refactor namespacing for readability
This commit is contained in:
parent
d051e1b0c8
commit
28175d9336
17 changed files with 77 additions and 99 deletions
|
|
@ -4,7 +4,7 @@ const builtin = @import("builtin");
|
||||||
pub fn build(b: *Builder) void {
|
pub fn build(b: *Builder) void {
|
||||||
const kernel = b.addExecutable("kernel", "src/arch/x86/main.zig");
|
const kernel = b.addExecutable("kernel", "src/arch/x86/main.zig");
|
||||||
kernel.addPackagePath("kernel", "src/index.zig");
|
kernel.addPackagePath("kernel", "src/index.zig");
|
||||||
// kernel.addPackagePath("arch", "src/arch/x86/lib/index.zig");
|
kernel.addPackagePath("x86", "src/arch/x86/index.zig");
|
||||||
kernel.setOutputDir("build");
|
kernel.setOutputDir("build");
|
||||||
|
|
||||||
// kernel.addAssemblyFile("src/arch/x86/_start.s");
|
// kernel.addAssemblyFile("src/arch/x86/_start.s");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// const tty = @import("tty.zig");
|
// const tty = @import("tty.zig");
|
||||||
const x86 = @import("lib/index.zig");
|
const x86 = @import("x86");
|
||||||
|
|
||||||
// GDT segment selectors.
|
// GDT segment selectors.
|
||||||
pub const KERNEL_CODE = 0x08;
|
pub const KERNEL_CODE = 0x08;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
// https://wiki.osdev.org/IDT
|
// https://wiki.osdev.org/IDT
|
||||||
usingnamespace @import("../../vga.zig");
|
usingnamespace @import("kernel");
|
||||||
const x86 = @import("lib/index.zig");
|
usingnamespace @import("x86");
|
||||||
const interrupt = @import("interrupt.zig");
|
|
||||||
const gdt = @import("gdt.zig");
|
|
||||||
|
|
||||||
// Types of gates.
|
// Types of gates.
|
||||||
pub const INTERRUPT_GATE = 0x8E;
|
pub const INTERRUPT_GATE = 0x8E;
|
||||||
|
|
@ -55,5 +53,5 @@ pub fn initialize() void {
|
||||||
interrupt.initialize();
|
interrupt.initialize();
|
||||||
|
|
||||||
// load IDT
|
// load IDT
|
||||||
x86.lidt(@ptrToInt(&idtr));
|
lidt(@ptrToInt(&idtr));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
src/arch/x86/index.zig
Normal file
8
src/arch/x86/index.zig
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
usingnamespace @import("lib/io.zig");
|
||||||
|
usingnamespace @import("lib/instructions.zig");
|
||||||
|
|
||||||
|
const memory = @import("memory.zig");
|
||||||
|
const paging = @import("paging.zig");
|
||||||
|
const idt = @import("idt.zig");
|
||||||
|
const gdt = @import("gdt.zig");
|
||||||
|
const interrupt = @import("interrupt.zig");
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const x86 = @import("lib/index.zig");
|
usingnamespace @import("kernel");
|
||||||
|
const x86 = @import("x86");
|
||||||
const isr = @import("isr.zig");
|
const isr = @import("isr.zig");
|
||||||
const println = @import("../../vga.zig").println;
|
|
||||||
|
|
||||||
// PIC ports.
|
// PIC ports.
|
||||||
const PIC1_CMD = 0x20;
|
const PIC1_CMD = 0x20;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const idt = @import("idt.zig");
|
usingnamespace @import("x86");
|
||||||
|
|
||||||
// Interrupt Service Routines defined externally in assembly.
|
// Interrupt Service Routines defined externally in assembly.
|
||||||
extern fn isr0() void;
|
extern fn isr0() void;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
usingnamespace @import("io.zig");
|
|
||||||
usingnamespace @import("instructions.zig");
|
|
||||||
|
|
@ -1,13 +1,5 @@
|
||||||
usingnamespace @import("kernel").main;
|
usingnamespace @import("kernel");
|
||||||
usingnamespace @import("kernel").multiboot;
|
usingnamespace @import("x86");
|
||||||
const console = @import("../console.zig");
|
|
||||||
const println = @import("../../vga.zig").println;
|
|
||||||
|
|
||||||
const idt = @import("idt.zig");
|
|
||||||
const memory = @import("memory.zig");
|
|
||||||
const paging = @import("paging.zig");
|
|
||||||
const gdt = @import("gdt.zig");
|
|
||||||
const x86 = @import("lib/index.zig");
|
|
||||||
|
|
||||||
/// x86 specific intialization
|
/// x86 specific intialization
|
||||||
pub fn x86_main(info: *const MultibootInfo) void {
|
pub fn x86_main(info: *const MultibootInfo) void {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
usingnamespace @import("kernel").multiboot;
|
usingnamespace @import("kernel");
|
||||||
usingnamespace @import("kernel").vga;
|
|
||||||
const assert = @import("std").debug.assert;
|
|
||||||
|
|
||||||
var stack: [*]usize = undefined; // Stack of free physical page.
|
var stack: [*]usize = undefined; // Stack of free physical page.
|
||||||
var stack_index: usize = 0; // Index into the stack.
|
var stack_index: usize = 0; // Index into the stack.
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
const x86 = @import("lib/index.zig");
|
usingnamespace @import("kernel");
|
||||||
const memory = @import("memory.zig");
|
usingnamespace @import("x86");
|
||||||
const interrupt = @import("interrupt.zig");
|
|
||||||
const assert = @import("std").debug.assert;
|
|
||||||
const println = @import("../../vga.zig").println;
|
|
||||||
|
|
||||||
extern fn setupPaging(phys_pd: usize) void;
|
extern fn setupPaging(phys_pd: usize) void;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
const interrupt = @import("arch/x86/interrupt.zig");
|
usingnamespace @import("kernel");
|
||||||
const paging = @import("arch/x86/paging.zig");
|
|
||||||
const ps2 = @import("ps2.zig");
|
|
||||||
const pci = @import("pci.zig");
|
|
||||||
const mem = @import("std").mem;
|
|
||||||
usingnamespace @import("vga.zig");
|
|
||||||
|
|
||||||
var command: [10]u8 = undefined;
|
var command: [10]u8 = undefined;
|
||||||
var command_len: usize = 0;
|
var command_len: usize = 0;
|
||||||
|
|
||||||
fn execute(com: []u8) void {
|
fn execute(com: []u8) void {
|
||||||
if (mem.eql(u8, com, "lspci")) pci.lspci();
|
if (@import("std").mem.eql(u8, com, "lspci")) pci.lspci();
|
||||||
if (mem.eql(u8, com, "paging")) paging.addrspace();
|
if (@import("std").mem.eql(u8, com, "paging")) x86.paging.addrspace();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keypress(char: u8) void {
|
pub fn keypress(char: u8) void {
|
||||||
|
|
@ -35,6 +30,6 @@ pub fn keypress(char: u8) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize() void {
|
pub fn initialize() void {
|
||||||
interrupt.registerIRQ(1, ps2.keyboard_handler);
|
@import("x86").interrupt.registerIRQ(1, ps2.keyboard_handler);
|
||||||
print("> ");
|
print("> ");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
pub const vga = @import("vga.zig");
|
usingnamespace @import("vga.zig");
|
||||||
pub const main = @import("main.zig");
|
const main = @import("main.zig");
|
||||||
pub const multiboot = @import("multiboot.zig");
|
const multiboot = @import("multiboot.zig");
|
||||||
|
const console = @import("console.zig");
|
||||||
|
const pci = @import("pci.zig");
|
||||||
|
const ps2 = @import("ps2.zig");
|
||||||
|
|
||||||
|
const assert = @import("std").debug.assert;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
usingnamespace @import("multiboot.zig");
|
usingnamespace @import("kernel");
|
||||||
usingnamespace @import("vga.zig");
|
const x86 = @import("x86");
|
||||||
const pci = @import("pci.zig");
|
|
||||||
const arch = @import("arch/x86/lib/index.zig");
|
|
||||||
const console = @import("console.zig");
|
|
||||||
const x86 = @import("arch/x86/main.zig");
|
|
||||||
const assert = @import("std").debug.assert;
|
|
||||||
|
|
||||||
// arch independant initialization
|
// arch independant initialization
|
||||||
export fn kmain(magic: u32, info: *const MultibootInfo) noreturn {
|
export fn kmain(magic: u32, info: *const MultibootInfo) noreturn {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
// MULTIBOOT1
|
// MULTIBOOT1
|
||||||
// https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
|
// https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
|
||||||
|
|
||||||
// zig fmt: off
|
|
||||||
const tty = @import("tty.zig");
|
|
||||||
const cstr = @import("std").cstr;
|
|
||||||
const Process = @import("process.zig").Process;
|
|
||||||
|
|
||||||
// This should be in EAX.
|
// This should be in EAX.
|
||||||
pub const MULTIBOOT_BOOTLOADER_MAGIC = 0x2BADB002;
|
pub const MULTIBOOT_BOOTLOADER_MAGIC = 0x2BADB002;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
const arch = @import("arch/x86/lib/index.zig");
|
usingnamespace @import("kernel");
|
||||||
|
const arch = @import("x86");
|
||||||
|
const std = @import("std");
|
||||||
|
const virtio = @import("virtio.zig");
|
||||||
|
|
||||||
const PCI_CONFIG_ADDRESS = 0xCF8;
|
const PCI_CONFIG_ADDRESS = 0xCF8;
|
||||||
const PCI_CONFIG_DATA = 0xCFC;
|
const PCI_CONFIG_DATA = 0xCFC;
|
||||||
usingnamespace @import("vga.zig");
|
|
||||||
const virtio = @import("virtio.zig");
|
|
||||||
const std = @import("std");
|
|
||||||
|
|
||||||
// https://wiki.osdev.org/Pci
|
// https://wiki.osdev.org/Pci
|
||||||
pub const PciAddress = packed struct {
|
pub const PciAddress = packed struct {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
usingnamespace @import("vga.zig");
|
usingnamespace @import("kernel");
|
||||||
const x86 = @import("arch/x86/lib/index.zig");
|
const x86 = @import("x86");
|
||||||
const console = @import("console.zig");
|
|
||||||
|
|
||||||
const PS2_DATA = 0x60;
|
const PS2_DATA = 0x60;
|
||||||
const PS2_STATUS = 0x64;
|
const PS2_STATUS = 0x64;
|
||||||
|
|
|
||||||
10
src/vga.zig
10
src/vga.zig
|
|
@ -1,6 +1,4 @@
|
||||||
const builtin = @import("builtin");
|
const arch = @import("x86");
|
||||||
const mem = @import("std").mem;
|
|
||||||
const arch = @import("arch/x86/lib/index.zig");
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
// Screen size.
|
// Screen size.
|
||||||
|
|
@ -79,7 +77,7 @@ const VGA = struct {
|
||||||
////
|
////
|
||||||
// Clear the screen.
|
// Clear the screen.
|
||||||
pub fn clear(self: *VGA) void {
|
pub fn clear(self: *VGA) void {
|
||||||
mem.set(VGAEntry, self.vram[0..VGA_SIZE], self.entry(' '));
|
std.mem.set(VGAEntry, self.vram[0..VGA_SIZE], self.entry(' '));
|
||||||
|
|
||||||
self.cursor = 0;
|
self.cursor = 0;
|
||||||
self.updateCursor();
|
self.updateCursor();
|
||||||
|
|
@ -145,9 +143,9 @@ const VGA = struct {
|
||||||
const last = VGA_SIZE - VGA_WIDTH; // Index of last line.
|
const last = VGA_SIZE - VGA_WIDTH; // Index of last line.
|
||||||
|
|
||||||
// Copy all the screen (apart from the first line) up one line.
|
// Copy all the screen (apart from the first line) up one line.
|
||||||
mem.copy(VGAEntry, self.vram[0..last], self.vram[first..VGA_SIZE]);
|
std.mem.copy(VGAEntry, self.vram[0..last], self.vram[first..VGA_SIZE]);
|
||||||
// Clean the last line.
|
// Clean the last line.
|
||||||
mem.set(VGAEntry, self.vram[last..VGA_SIZE], self.entry(' '));
|
std.mem.set(VGAEntry, self.vram[last..VGA_SIZE], self.entry(' '));
|
||||||
|
|
||||||
// Bring the cursor back to the beginning of the last line.
|
// Bring the cursor back to the beginning of the last line.
|
||||||
self.cursor -= VGA_WIDTH;
|
self.cursor -= VGA_WIDTH;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue