From 44e57773a3378e290cc553d1a4f5eb07f581f4ab Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Wed, 7 Sep 2016 21:32:09 -0600
Subject: [PATCH] Debug reads writes better, set up stdio for BSP

---
 lib.rs        | 9 +++++++++
 syscall/fs.rs | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib.rs b/lib.rs
index d88d9263..bc93fc5d 100644
--- a/lib.rs
+++ b/lib.rs
@@ -133,6 +133,15 @@ pub extern fn kmain() {
     let pid = syscall::getpid();
     println!("BSP: {:?}", pid);
 
+    let stdin = syscall::open("debug:".as_bytes(), 0);
+    println!("STDIN: {:?}", stdin);
+    
+    let stdout = syscall::open("debug:".as_bytes(), 0);
+    println!("STDOUT: {:?}", stdout);
+
+    let stderr = syscall::open("debug:".as_bytes(), 0);
+    println!("STDERR: {:?}", stderr);
+
     let elf = elf::Elf::from(include_bytes!("../init/main")).expect("could not load elf");
     elf.run();
 
diff --git a/syscall/fs.rs b/syscall/fs.rs
index 87fe2dbd..3a23b6cd 100644
--- a/syscall/fs.rs
+++ b/syscall/fs.rs
@@ -7,7 +7,7 @@ use super::{Error, Result};
 
 /// Read syscall
 pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
-    println!("Read {}: {}", fd, buf.len());
+    println!("Read {}: {:X} {}", fd, buf.as_ptr() as usize, buf.len());
     if let Some(context_lock) = context::contexts().current() {
         let context = context_lock.read();
         if let Some(file) = context.files.get(fd) {
@@ -23,7 +23,7 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
 
 /// Write syscall
 pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
-    println!("Write {}: {}", fd, buf.len());
+    println!("Write {}: {:X} {}", fd, buf.as_ptr() as usize, buf.len());
     if let Some(context_lock) = context::contexts().current() {
         let context = context_lock.read();
         if let Some(file) = context.files.get(fd) {
-- 
GitLab