-
Notifications
You must be signed in to change notification settings - Fork 25
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
af7c1f3
commit 55a2dd1
Showing
7 changed files
with
205 additions
and
7 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,43 @@ | ||
/* | ||
* Rust BareBones OS | ||
* - By John Hodge (Mutabah/thePowersGang) | ||
* | ||
* arch/x86/debug.rs | ||
* - Debug output channel | ||
* | ||
* Writes debug to the standard PC serial port (0x3F8 .. 0x3FF) | ||
* | ||
* == LICENCE == | ||
* This code has been put into the public domain, there are no restrictions on | ||
* its use, and the author takes no liability. | ||
*/ | ||
use prelude::*; | ||
|
||
/// Write a string to the output channel | ||
/// | ||
/// This method is unsafe because it does port accesses without synchronisation | ||
pub unsafe fn puts(s: &str) | ||
{ | ||
for b in s.bytes() | ||
{ | ||
putb(b); | ||
} | ||
} | ||
|
||
/// Write a single byte to the output channel | ||
/// | ||
/// This method is unsafe because it does port accesses without synchronisation | ||
pub unsafe fn putb(b: u8) | ||
{ | ||
// Wait for the serial port's fifo to not be empty | ||
while (::arch::x86_io::inb(0x3F8+5) & 0x20) == 0 | ||
{ | ||
// Do nothing | ||
} | ||
// Send the byte out the serial port | ||
::arch::x86_io::outb(0x3F8, b); | ||
|
||
// Also send to the bochs 0xe9 hack | ||
::arch::x86_io::outb(0xe9, b); | ||
} | ||
|
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,28 @@ | ||
/* | ||
* Rust BareBones OS | ||
* - By John Hodge (Mutabah/thePowersGang) | ||
* | ||
* arch/x86/mod.rs | ||
* - Top-level file for x86 architecture | ||
* | ||
* == LICENCE == | ||
* This code has been put into the public domain, there are no restrictions on | ||
* its use, and the author takes no liability. | ||
*/ | ||
|
||
// x86 port IO | ||
mod x86_io; | ||
|
||
// Debug output channel (uses serial) | ||
pub mod debug; | ||
|
||
#[no_mangle] | ||
pub fn x86_prep_page_table(buf: &mut [u32; 1024]) | ||
{ | ||
for i in 0u32 .. 1024 | ||
{ | ||
buf[i as usize] = i * 0x1000 + 3; | ||
} | ||
} | ||
|
||
|
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,54 @@ | ||
/* | ||
* Rust BareBones OS | ||
* - By John Hodge (Mutabah/thePowersGang) | ||
* | ||
* arch/x86/x86_io.rs | ||
* - Support for the x86 IO bus | ||
* | ||
* == LICENCE == | ||
* This code has been put into the public domain, there are no restrictions on | ||
* its use, and the author takes no liability. | ||
*/ | ||
|
||
/// Write a byte to the specified port | ||
pub unsafe fn outb(port: u16, val: u8) | ||
{ | ||
asm!("outb %al, %dx" : : "{dx}"(port), "{al}"(val)); | ||
} | ||
|
||
/// Read a single byte from the specified port | ||
pub unsafe fn inb(port: u16) -> u8 | ||
{ | ||
let ret : u8; | ||
asm!("inb %dx, %al" : "={ax}"(ret) : "{dx}"(port)); | ||
return ret; | ||
} | ||
|
||
/// Write a word (16-bits) to the specified port | ||
pub unsafe fn outw(port: u16, val: u16) | ||
{ | ||
asm!("outb %ax, %dx" : : "{dx}"(port), "{al}"(val)); | ||
} | ||
|
||
/// Read a word (16-bits) from the specified port | ||
pub unsafe fn inw(port: u16) -> u16 | ||
{ | ||
let ret : u16; | ||
asm!("inb %dx, %ax" : "={ax}"(ret) : "{dx}"(port)); | ||
return ret; | ||
} | ||
|
||
/// Write a long/double-word (32-bits) to the specified port | ||
pub unsafe fn outl(port: u16, val: u32) | ||
{ | ||
asm!("outb %eax, %dx" : : "{dx}"(port), "{al}"(val)); | ||
} | ||
|
||
/// Read a long/double-word (32-bits) from the specified port | ||
pub unsafe fn inl(port: u16) -> u32 | ||
{ | ||
let ret : u32; | ||
asm!("inb %dx, %eax" : "={ax}"(ret) : "{dx}"(port)); | ||
return ret; | ||
} | ||
|
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