From ce879e11b2bcd863317d664255be4d1cab264e0a Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 May 2019 21:09:57 +0200 Subject: [PATCH] compiler problems... --- build.zig | 3 +- src/arch/x86/_start.s | 15 +++++++ src/arch/x86/gdt.s | 26 +++++------ src/arch/x86/isr.zig | 100 ++++++++++++++++++++--------------------- src/arch/x86/linker.ld | 3 +- src/arch/x86/main.zig | 7 ++- src/index.zig | 1 + src/main.zig | 4 +- 8 files changed, 91 insertions(+), 68 deletions(-) create mode 100644 src/arch/x86/_start.s diff --git a/build.zig b/build.zig index 20d0a33..7dd0371 100644 --- a/build.zig +++ b/build.zig @@ -7,8 +7,9 @@ pub fn build(b: *Builder) void { kernel.addPackagePath("arch", "src/arch/x86/lib/index.zig"); kernel.setOutputDir("build"); + // kernel.addAssemblyFile("src/arch/x86/_start.s"); kernel.addAssemblyFile("src/arch/x86/gdt.s"); - kernel.addAssemblyFile("src/arch/x86/isr.s"); + // kernel.addAssemblyFile("src/arch/x86/isr.s"); kernel.setBuildMode(b.standardReleaseOptions()); kernel.setTarget(builtin.Arch.i386, builtin.Os.freestanding, builtin.Abi.none); diff --git a/src/arch/x86/_start.s b/src/arch/x86/_start.s new file mode 100644 index 0000000..1fe5466 --- /dev/null +++ b/src/arch/x86/_start.s @@ -0,0 +1,15 @@ +.global _start +.type _start, @function + +// Entry point. It puts the machine into a consistent state, +// starts the kernel and then waits forever. +_start: + mov $0x80000, %esp // Setup the stack. + + push %ebx // Pass multiboot info structure. + push %eax // Pass multiboot magic code. + call x86_main // Call the kernel. + + // Halt the CPU. + cli + hlt diff --git a/src/arch/x86/gdt.s b/src/arch/x86/gdt.s index c51fc73..75aac48 100644 --- a/src/arch/x86/gdt.s +++ b/src/arch/x86/gdt.s @@ -1,23 +1,23 @@ .type loadGDT, @function -// +//// // Load the GDT into the system registers. // // Arguments: // gdtr: Pointer to the GDTR. // loadGDT: - mov +4(%esp), %eax // Fetch the gdtr parameter. - lgdt (%eax) // Load the new GDT. + mov +4(%esp), %eax // Fetch the gdtr parameter. + lgdt (%eax) // Load the new GDT. - // Reload data segments (GDT entry 2: kernel data). - mov $0x10, %ax - mov %ax, %ds - mov %ax, %es - mov %ax, %fs - mov %ax, %gs - mov %ax, %ss + // Reload data segments (GDT entry 2: kernel data). + mov $0x10, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs + mov %ax, %ss - // Reload code segment (GDT entry 1: kernel code). - ljmp $0x08, $1f -1: ret + // Reload code segment (GDT entry 1: kernel code). + ljmp $0x08, $1f + 1: ret diff --git a/src/arch/x86/isr.zig b/src/arch/x86/isr.zig index 90abf13..f2673a5 100644 --- a/src/arch/x86/isr.zig +++ b/src/arch/x86/isr.zig @@ -103,56 +103,56 @@ pub export var context: *volatile Context = undefined; pub fn install() void { // Exceptions. idt.setGate(0, idt.INTERRUPT_GATE, isr0); - idt.setGate(1, idt.INTERRUPT_GATE, isr1); - idt.setGate(2, idt.INTERRUPT_GATE, isr2); - idt.setGate(3, idt.INTERRUPT_GATE, isr3); - idt.setGate(4, idt.INTERRUPT_GATE, isr4); - idt.setGate(5, idt.INTERRUPT_GATE, isr5); - idt.setGate(6, idt.INTERRUPT_GATE, isr6); - idt.setGate(7, idt.INTERRUPT_GATE, isr7); - idt.setGate(8, idt.INTERRUPT_GATE, isr8); - idt.setGate(9, idt.INTERRUPT_GATE, isr9); - idt.setGate(10, idt.INTERRUPT_GATE, isr10); - idt.setGate(11, idt.INTERRUPT_GATE, isr11); - idt.setGate(12, idt.INTERRUPT_GATE, isr12); - idt.setGate(13, idt.INTERRUPT_GATE, isr13); - idt.setGate(14, idt.INTERRUPT_GATE, isr14); - idt.setGate(15, idt.INTERRUPT_GATE, isr15); - idt.setGate(16, idt.INTERRUPT_GATE, isr16); - idt.setGate(17, idt.INTERRUPT_GATE, isr17); - idt.setGate(18, idt.INTERRUPT_GATE, isr18); - idt.setGate(19, idt.INTERRUPT_GATE, isr19); - idt.setGate(20, idt.INTERRUPT_GATE, isr20); - idt.setGate(21, idt.INTERRUPT_GATE, isr21); - idt.setGate(22, idt.INTERRUPT_GATE, isr22); - idt.setGate(23, idt.INTERRUPT_GATE, isr23); - idt.setGate(24, idt.INTERRUPT_GATE, isr24); - idt.setGate(25, idt.INTERRUPT_GATE, isr25); - idt.setGate(26, idt.INTERRUPT_GATE, isr26); - idt.setGate(27, idt.INTERRUPT_GATE, isr27); - idt.setGate(28, idt.INTERRUPT_GATE, isr28); - idt.setGate(29, idt.INTERRUPT_GATE, isr29); - idt.setGate(30, idt.INTERRUPT_GATE, isr30); - idt.setGate(31, idt.INTERRUPT_GATE, isr31); + // idt.setGate(1, idt.INTERRUPT_GATE, isr1); + // idt.setGate(2, idt.INTERRUPT_GATE, isr2); + // idt.setGate(3, idt.INTERRUPT_GATE, isr3); + // idt.setGate(4, idt.INTERRUPT_GATE, isr4); + // idt.setGate(5, idt.INTERRUPT_GATE, isr5); + // idt.setGate(6, idt.INTERRUPT_GATE, isr6); + // idt.setGate(7, idt.INTERRUPT_GATE, isr7); + // idt.setGate(8, idt.INTERRUPT_GATE, isr8); + // idt.setGate(9, idt.INTERRUPT_GATE, isr9); + // idt.setGate(10, idt.INTERRUPT_GATE, isr10); + // idt.setGate(11, idt.INTERRUPT_GATE, isr11); + // idt.setGate(12, idt.INTERRUPT_GATE, isr12); + // idt.setGate(13, idt.INTERRUPT_GATE, isr13); + // idt.setGate(14, idt.INTERRUPT_GATE, isr14); + // idt.setGate(15, idt.INTERRUPT_GATE, isr15); + // idt.setGate(16, idt.INTERRUPT_GATE, isr16); + // idt.setGate(17, idt.INTERRUPT_GATE, isr17); + // idt.setGate(18, idt.INTERRUPT_GATE, isr18); + // idt.setGate(19, idt.INTERRUPT_GATE, isr19); + // idt.setGate(20, idt.INTERRUPT_GATE, isr20); + // idt.setGate(21, idt.INTERRUPT_GATE, isr21); + // idt.setGate(22, idt.INTERRUPT_GATE, isr22); + // idt.setGate(23, idt.INTERRUPT_GATE, isr23); + // idt.setGate(24, idt.INTERRUPT_GATE, isr24); + // idt.setGate(25, idt.INTERRUPT_GATE, isr25); + // idt.setGate(26, idt.INTERRUPT_GATE, isr26); + // idt.setGate(27, idt.INTERRUPT_GATE, isr27); + // idt.setGate(28, idt.INTERRUPT_GATE, isr28); + // idt.setGate(29, idt.INTERRUPT_GATE, isr29); + // idt.setGate(30, idt.INTERRUPT_GATE, isr30); + // idt.setGate(31, idt.INTERRUPT_GATE, isr31); - // IRQs. - idt.setGate(32, idt.INTERRUPT_GATE, isr32); - idt.setGate(33, idt.INTERRUPT_GATE, isr33); - idt.setGate(34, idt.INTERRUPT_GATE, isr34); - idt.setGate(35, idt.INTERRUPT_GATE, isr35); - idt.setGate(36, idt.INTERRUPT_GATE, isr36); - idt.setGate(37, idt.INTERRUPT_GATE, isr37); - idt.setGate(38, idt.INTERRUPT_GATE, isr38); - idt.setGate(39, idt.INTERRUPT_GATE, isr39); - idt.setGate(40, idt.INTERRUPT_GATE, isr40); - idt.setGate(41, idt.INTERRUPT_GATE, isr41); - idt.setGate(42, idt.INTERRUPT_GATE, isr42); - idt.setGate(43, idt.INTERRUPT_GATE, isr43); - idt.setGate(44, idt.INTERRUPT_GATE, isr44); - idt.setGate(45, idt.INTERRUPT_GATE, isr45); - idt.setGate(46, idt.INTERRUPT_GATE, isr46); - idt.setGate(47, idt.INTERRUPT_GATE, isr47); + // // IRQs. + // idt.setGate(32, idt.INTERRUPT_GATE, isr32); + // idt.setGate(33, idt.INTERRUPT_GATE, isr33); + // idt.setGate(34, idt.INTERRUPT_GATE, isr34); + // idt.setGate(35, idt.INTERRUPT_GATE, isr35); + // idt.setGate(36, idt.INTERRUPT_GATE, isr36); + // idt.setGate(37, idt.INTERRUPT_GATE, isr37); + // idt.setGate(38, idt.INTERRUPT_GATE, isr38); + // idt.setGate(39, idt.INTERRUPT_GATE, isr39); + // idt.setGate(40, idt.INTERRUPT_GATE, isr40); + // idt.setGate(41, idt.INTERRUPT_GATE, isr41); + // idt.setGate(42, idt.INTERRUPT_GATE, isr42); + // idt.setGate(43, idt.INTERRUPT_GATE, isr43); + // idt.setGate(44, idt.INTERRUPT_GATE, isr44); + // idt.setGate(45, idt.INTERRUPT_GATE, isr45); + // idt.setGate(46, idt.INTERRUPT_GATE, isr46); + // idt.setGate(47, idt.INTERRUPT_GATE, isr47); - // Syscalls. - idt.setGate(128, idt.SYSCALL_GATE, isr128); + // // Syscalls. + // idt.setGate(128, idt.SYSCALL_GATE, isr128); } diff --git a/src/arch/x86/linker.ld b/src/arch/x86/linker.ld index c19f381..4cf7efe 100644 --- a/src/arch/x86/linker.ld +++ b/src/arch/x86/linker.ld @@ -1,4 +1,5 @@ -ENTRY(_start) +/* ENTRY(_start) */ +ENTRY(x86_main) /* OUTPUT_FORMAT(elf32-i386) */ SECTIONS { diff --git a/src/arch/x86/main.zig b/src/arch/x86/main.zig index 74548d4..689aa5c 100644 --- a/src/arch/x86/main.zig +++ b/src/arch/x86/main.zig @@ -1,13 +1,16 @@ use @import("kernel").main; +use @import("kernel").multiboot; const idt = @import("idt.zig"); const gdt = @import("gdt.zig"); const x86 = @import("lib/index.zig"); +const assert = @import("std").debug.assert; /// x86 specific intialization /// first entry point (see linker.ld) -export nakedcc fn _start() noreturn { +export nakedcc fn x86_main(magic: u32, info: *const MultibootInfo) noreturn { + // assert(magic == MULTIBOOT_BOOTLOADER_MAGIC); gdt.initialize(); idt.initialize(); x86.sti(); - kmain(); + kmain(magic, info); } diff --git a/src/index.zig b/src/index.zig index cbc573a..90dc75f 100644 --- a/src/index.zig +++ b/src/index.zig @@ -1,2 +1,3 @@ pub const vga = @import("vga.zig"); pub const main = @import("main.zig"); +pub const multiboot = @import("multiboot.zig"); diff --git a/src/main.zig b/src/main.zig index c45afbc..c2b2771 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,9 +2,11 @@ use @import("multiboot.zig"); const pci = @import("pci.zig"); const arch = @import("arch/x86/lib/index.zig"); const console = @import("console.zig"); +const vga = @import("vga.zig"); // platform independant initialization -pub fn kmain() noreturn { +pub fn kmain(magic: u32, info: *const MultibootInfo) noreturn { console.initialize(); + vga.printf("magic 0x{x}\n", magic); while (true) {} }