-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9889e32
commit 6e72996
Showing
4 changed files
with
135 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module io; | ||
|
||
void outp(T)(ushort port, T d) { | ||
uint data = d; | ||
static if (T.sizeof == 1) | ||
{ | ||
asm { | ||
"outb %0, %1" | ||
: : "a"(data), | ||
"Nd"(port); | ||
}; | ||
} | ||
else static if (T.sizeof == 4) | ||
{ | ||
asm { | ||
"outw %0, %1" | ||
: : "a"(data), | ||
"Nd"(port); | ||
}; | ||
} | ||
else static if (T.sizeof == 4) | ||
{ | ||
asm { | ||
"outl %0, %1" | ||
: : "a"(data), | ||
"Nd"(port); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
module main; | ||
|
||
import terminal; | ||
import serial; | ||
|
||
extern(C) void main(uint magic, uint addr) { | ||
|
||
auto terminal = Terminal(80, 25); | ||
// Serial COM1 | ||
auto serial = SerialDevice(SerialDevice.COMPORT.COM1); | ||
serial.log("Kernel image loaded successfully"); | ||
serial.log("Welcome to BetterNamePendingOS!"); | ||
serial.log("Printing int '10': ", 10); | ||
|
||
terminal.color = terminal.COLOR.GREEN; | ||
terminal.writeln("Terminal initialized"); | ||
terminal.writeln("Kernel image loaded successfully"); | ||
|
||
terminal.color = terminal.COLOR.WHITE; | ||
terminal.writeln(); | ||
terminal.writeln("Welcome to BetterNamePendingOS!"); | ||
terminal.writeln(); | ||
terminal.writeln("Running tests on all availiable modules:"); | ||
terminal.writeln(); | ||
terminal.writeln("convert.d"); | ||
terminal.writeln(" ", "Printing int '10': ", 10); | ||
terminal.writeln(" ", "Printing ubyte '0xdd': ", cast(ubyte)0xdd); | ||
terminal.writeln(":/"); | ||
|
||
for (;;) { | ||
} | ||
// VGA terminal | ||
auto terminal = Terminal(80, 25); | ||
|
||
terminal.color = terminal.COLOR.GREEN; | ||
terminal.writeln("Terminal initialized"); | ||
terminal.writeln("Kernel image loaded successfully"); | ||
|
||
terminal.color = terminal.COLOR.WHITE; | ||
terminal.writeln(); | ||
terminal.writeln("Welcome to BetterNamePendingOS!"); | ||
terminal.writeln(); | ||
terminal.writeln("Running tests on all availiable modules:"); | ||
terminal.writeln(); | ||
terminal.writeln("convert.d"); | ||
terminal.writeln(" ", "Printing int '10': ", 10); | ||
terminal.writeln(" ", "Printing ubyte '0xdd': ", cast(ubyte)0xdd); | ||
terminal.writeln(":/"); | ||
|
||
for (;;) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module serial; | ||
|
||
import io : outp; | ||
import convert; | ||
|
||
struct SerialDevice | ||
{ | ||
public: | ||
enum COMPORT : ushort | ||
{ | ||
COM1 = 0x3f8, | ||
COM2 = 0x2F8, | ||
}; | ||
|
||
COMPORT port = COMPORT.COM1; | ||
|
||
private void init() { | ||
outp!ubyte(cast(ushort)(port + 1), cast(ubyte)0x00); // Disable all interrupts | ||
outp!ubyte(cast(ushort)(port + 3), cast(ubyte)0x80); // Enable DLAB (set baud rate divisor) | ||
outp!ubyte(cast(ushort)(port + 0), cast(ubyte)0x03); // Set divisor to 3 (lo byte) 38400 baud | ||
outp!ubyte(cast(ushort)(port + 1), cast(ubyte)0x00); // (hi byte) | ||
outp!ubyte(cast(ushort)(port + 3), cast(ubyte)0x03); // 8 bits, no parity, one stop bit | ||
outp!ubyte(cast(ushort)(port + 2), cast(ubyte)0xC7); // Enable FIFO, clear them, with 14-byte threshold | ||
outp!ubyte(cast(ushort)(port + 4), cast(ubyte)0x0B); // IRQs enabled, RTS/DSR set | ||
} | ||
|
||
this(COMPORT port) | ||
{ | ||
this.port = port; | ||
init(); | ||
} | ||
|
||
void log(Args...)(Args args) | ||
{ | ||
writeln("[LOG] ", args); | ||
} | ||
|
||
void writeln(Args...)(Args args) | ||
{ | ||
write(args, '\r', '\n'); | ||
} | ||
|
||
void write(Args...)(Args args) | ||
{ | ||
foreach (arg; args) { | ||
alias T = typeof(arg); | ||
static if (is(T : const char[])) | ||
{ | ||
putstr(arg); | ||
} | ||
else static if (is(T : char)) | ||
{ | ||
putchar(arg); | ||
} | ||
else static if (is(T : int)) | ||
{ | ||
putstr(convert.itoa(arg, 10)); | ||
} | ||
else static if (is(T : ubyte)) | ||
{ | ||
putstr(convert.itoa(arg, 16)); | ||
} | ||
} | ||
} | ||
|
||
private void putstr(string str) | ||
{ | ||
foreach(c; str) | ||
putchar(c); | ||
} | ||
|
||
void putchar(char c) | ||
{ | ||
outp(this.port, c); | ||
} | ||
} | ||
|