Add TTY and VGA interface
Line endings Removed redundant files Line ending
This commit is contained in:
parent
0196ef7824
commit
faeb433bb0
7 changed files with 3016 additions and 98 deletions
|
|
@ -1,3 +1,17 @@
|
|||
// Zig version: 0.4.0
|
||||
|
||||
const is_test = @import("builtin").is_test;
|
||||
|
||||
const ALIGN = 1 << 0;
|
||||
const MEMINFO = 1 << 1;
|
||||
const MAGIC = 0x1BADB002;
|
||||
const FLAGS = ALIGN | MEMINFO;
|
||||
|
||||
const KERNEL_ADDR_OFFSET = 0xC0000000;
|
||||
const KERNEL_PAGE_NUMBER = KERNEL_ADDR_OFFSET >> 22;
|
||||
// The number of pages occupied by the kernel, will need to be increased as we add a heap etc.
|
||||
const KERNEL_NUM_PAGES = 1;
|
||||
|
||||
extern fn kmain() void;
|
||||
|
||||
const MultiBoot = packed struct {
|
||||
|
|
@ -6,22 +20,12 @@ const MultiBoot = packed struct {
|
|||
checksum: i32,
|
||||
};
|
||||
|
||||
const ALIGN = 1 << 0;
|
||||
const MEMINFO = 1 << 1;
|
||||
const MAGIC = 0x1BADB002;
|
||||
const FLAGS = ALIGN | MEMINFO;
|
||||
|
||||
export var multiboot align(4) linksection(".rodata.boot") = MultiBoot{
|
||||
export var multiboot align(4) linksection(".rodata.boot") = MultiBoot {
|
||||
.magic = MAGIC,
|
||||
.flags = FLAGS,
|
||||
.checksum = -(MAGIC + FLAGS),
|
||||
};
|
||||
|
||||
const KERNEL_ADDR_OFFSET = 0xC0000000;
|
||||
const KERNEL_PAGE_NUMBER = KERNEL_ADDR_OFFSET >> 22;
|
||||
// The number of pages occupied by the kernel, will need to be increased as we add a heap etc.
|
||||
const KERNEL_NUM_PAGES = 1;
|
||||
|
||||
// The initial page directory used for booting into the higher half. Should be overwritten later
|
||||
export var boot_page_directory: [1024]u32 align(4096) linksection(".rodata.boot") = init: {
|
||||
// Increase max number of branches done by comptime evaluator
|
||||
|
|
@ -35,7 +39,7 @@ export var boot_page_directory: [1024]u32 align(4096) linksection(".rodata.boot"
|
|||
var i = 0;
|
||||
var idx = 1;
|
||||
|
||||
// Fill preceding pages with zeroes. May be unecessary but incurs no runtime cost
|
||||
// Fill preceding pages with zeroes. May be unnecessary but incurs no runtime cost
|
||||
while (i < KERNEL_PAGE_NUMBER - 1) : ({
|
||||
i += 1;
|
||||
idx += 1;
|
||||
|
|
@ -51,7 +55,7 @@ export var boot_page_directory: [1024]u32 align(4096) linksection(".rodata.boot"
|
|||
}) {
|
||||
dir[idx] = 0x00000083 | (i << 22);
|
||||
}
|
||||
// Fill suceeding pages with zeroes. May be unecessary but incurs no runtime cost
|
||||
// Fill succeeding pages with zeroes. May be unnecessary but incurs no runtime cost
|
||||
i = 0;
|
||||
while (i < 1024 - KERNEL_PAGE_NUMBER - KERNEL_NUM_PAGES) : ({
|
||||
i += 1;
|
||||
|
|
@ -107,4 +111,43 @@ export nakedcc fn start_higher_half() noreturn {
|
|||
while (true) {}
|
||||
}
|
||||
|
||||
///
|
||||
/// Initialise the architecture
|
||||
///
|
||||
export fn init() void {}
|
||||
|
||||
///
|
||||
/// Inline assembly to write to a given port with a byte of data.
|
||||
///
|
||||
/// Arguments:
|
||||
/// IN port: u16 - The port to write to.
|
||||
/// IN data: u8 - The byte of data that will be sent.
|
||||
///
|
||||
export fn outb(port: u16, data: u8) void {
|
||||
asm volatile ("outb %[data], %[port]"
|
||||
:
|
||||
: [port] "{dx}" (port), [data] "{al}" (data));
|
||||
}
|
||||
|
||||
///
|
||||
/// Inline assembly that reads data from a given port and returns its value.
|
||||
///
|
||||
/// Arguments:
|
||||
/// IN port: u16 - The port to read data from.
|
||||
///
|
||||
/// Return:
|
||||
/// The data that the port returns.
|
||||
///
|
||||
export fn inb(port: u16) u8 {
|
||||
return asm volatile ("inb %[port], %[result]"
|
||||
: [result] "={al}" (-> u8)
|
||||
: [port] "N{dx}" (port));
|
||||
}
|
||||
|
||||
///
|
||||
/// A simple way of waiting for I/O event to happen by doing an I/O event to flush the I/O
|
||||
/// event being waited.
|
||||
///
|
||||
export fn ioWait() void {
|
||||
outb(0x80, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue