Skip to content

Commit

Permalink
Usermode - Work on shell
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Oct 15, 2015
1 parent 71ab013 commit c334171
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 61 deletions.
25 changes: 19 additions & 6 deletions Graphics/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@

.PHONY: all

SHARED_DIR := .output/shared/

all: $(addprefix $(SHARED_DIR),power.r8 options.r8 background.r24)


# NOTE: This is actually done in Kernel/Makefile
logo.rs: TifflinLogoV1-128.png Makefile ConvertTo32bppRS
$(SHARED_DIR)logo.rs: TifflinLogoV1-128.png Makefile ConvertTo32bppRS
./ConvertTo32bppRS $< $@ S_LOGO

power.r8: open-iconic_moon-2x.png Makefile
%.r8:
mkdir -p $(dir $@)
convert $< -depth 8 -channel A -separate gray:.tmp.$(notdir $@)
/bin/echo -ne "\x10\x00\x10\x00" | cat - .tmp.$(notdir $@) > $@
/bin/echo -ne "\x7FR8M\x10\x00\x10\x00" | cat - .tmp.$(notdir $@) > $@

options.r8: open-iconic_cog-2x.png Makefile
convert $< -depth 8 -channel A -separate gray:.tmp.$(notdir $@)
/bin/echo -ne "\x10\x00\x10\x00" | cat - .tmp.$(notdir $@) > $@
%.r24:
mkdir -p $(dir $@)
convert $< -depth 8 rgb:.tmp.$(notdir $@)
/bin/echo -ne "\x7FR24\x10\x00\x10\x00" | cat - .tmp.$(notdir $@) > $@

$(SHARED_DIR)background.r24: rustacean-orig.png Makefile
$(SHARED_DIR)power.r8: open-iconic_moon-2x.png Makefile
$(SHARED_DIR)options.r8: open-iconic_cog-2x.png Makefile

Binary file added Graphics/rustacean-orig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Kernel/rundir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $(IMGDIR)hda_0.img:
@echo "[MkDisk] ZERO 1MB $@"
@# - 1MB of blank space
@dd if=/dev/zero of=$@ bs=1M count=1 status=noxfer
$(IMGDIR)hda_1.img: $(wildcard ../../Usermode/.output/$(ARCH)/bin/*) Makefile $(wildcard ../../Graphics/*.r8)
$(IMGDIR)hda_1.img: $(wildcard ../../Usermode/.output/$(ARCH)/bin/*) Makefile $(wildcard ../../Graphics/.output/shared/*)
@mkdir -p $(dir $@)
@echo "[MkDisk] FAT 32MB $@"
@# - 32MB FAT? partition on disk 0
Expand All @@ -71,7 +71,7 @@ $(IMGDIR)hda_1.img: $(wildcard ../../Usermode/.output/$(ARCH)/bin/*) Makefile $(
@mmd -i $@ ::/Tifflin/shared
@mmd -i $@ ::/Tifflin/shared/images
@mcopy -s -D o -i $@ ../../Usermode/.output/$(ARCH)/bin ::/Tifflin/bin
@mcopy -s -D o -i $@ ../../Graphics/*.r8 ::/Tifflin/shared/images/
@mcopy -s -D o -i $@ ../../Graphics/.output/shared/* ::/Tifflin/shared/images/
@echo "Test content" | mcopy -i $@ - ::/1.txt
$(IMGDIR)hda_2.img:
@mkdir -p $(dir $@)
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ run: all
all:
@echo ">>> $@: libcore source"
@+make -C Kernel/ ../libcore/lib.rs --no-print-directory
@echo ">>> $@: Graphics"
@make -C Graphics/ all
@echo ">>> $@: Usermode"
@+make -C Usermode/ all --no-print-directory
@echo ">>> $@: Kernel"
Expand Down
2 changes: 1 addition & 1 deletion Usermode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ V ?= @

# List of root-level applications to build
APPS := loader init login
APPS += simple_console
APPS += simple_console shell

# Build directories
# - Distribution output root
Expand Down
55 changes: 53 additions & 2 deletions Usermode/libstd_io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,36 @@
#![no_std]
use core::fmt;

#[macro_use]
extern crate macros;
extern crate syscalls;

pub mod prelude {
pub use super::{Read, Write, BufRead, Seek};
}
mod std {
pub use core::{fmt, convert};
}

/// Shorthand result type
pub type Result<T> = ::core::result::Result<T,Error>;

/// IO Error type
#[derive(Debug)]
pub struct Error;
pub struct Error(ErrorInner);
#[derive(Debug)]
enum ErrorInner
{
Misc,
Interrupted,
VFS(::syscalls::vfs::Error),
}

impl_conv! {
From<::syscalls::vfs::Error>(v) for Error {
Error( ErrorInner::VFS(v) )
}
}

pub trait Read
{
Expand All @@ -33,7 +53,7 @@ pub trait Write
fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
while !buf.is_empty() {
match self.write(buf) {
Ok(0) => return Err(Error/*::new(ErrorKind::WriteZero, "failed to write whole buffer")*/),
Ok(0) => return Err(Error(ErrorInner::Misc)/*::new(ErrorKind::WriteZero, "failed to write whole buffer")*/),
Ok(n) => buf = &buf[n..],
//Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(e) => return Err(e),
Expand Down Expand Up @@ -97,3 +117,34 @@ impl<'a> Read for &'a [u8]
}
}


impl Read for ::syscalls::vfs::File {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
Ok(try!( self.read(buf) ))
}
}
impl Seek for ::syscalls::vfs::File {
fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
match pos
{
SeekFrom::Start(pos) => self.set_cursor(pos),
SeekFrom::End(ofs) => {
let pos = if ofs < 0 {
self.get_size() - (-ofs) as u64
} else {
self.get_size() + ofs as u64
};
self.set_cursor(pos);
},
SeekFrom::Current(ofs) => {
let pos = if ofs < 0 {
self.get_cursor() - (-ofs) as u64
} else {
self.get_cursor() + ofs as u64
};
self.set_cursor(pos);
},
}
Ok(self.get_cursor())
}
}
14 changes: 14 additions & 0 deletions Usermode/libsyscalls/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,20 @@ impl Window
let v = unsafe { self.0.call_0(::values::GUI_WIN_GETDIMS) };
Dims { w: (v >> 32) as u32, h: v as u32 }
}
pub fn set_dims(&self, dims: Dims) {
// SAFE: Syscall
unsafe { self.0.call_2(::values::GUI_WIN_SETDIMS, dims.w as usize, dims.h as usize); }
}

pub fn get_pos(&self) -> (u32, u32) {
// SAFE: No side-effect syscall
let v = unsafe { self.0.call_0(::values::GUI_WIN_GETPOS) };
( (v >> 32) as u32, v as u32 )
}
pub fn set_pos(&self, x: u32, y: u32) {
// SAFE: Syscall
unsafe { self.0.call_2(::values::GUI_WIN_SETPOS, x as usize, y as usize); }
}
// TODO: Should this be controllable by the application?
pub fn maximise(&self) {
// SAFE: Syscall
Expand All @@ -131,6 +144,7 @@ impl Window
assert!( data.len() >= rgn_size );
let data = &data[..rgn_size];

// Assert that data length and h*stride agree
{
assert!(data.len() > 0);
let h_calc = if data.len() >= w as usize {
Expand Down
2 changes: 0 additions & 2 deletions Usermode/libsyscalls/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#![feature(associated_consts)]
#![no_std]

extern crate std_io;

mod std {
pub use core::convert;
pub use core::fmt;
Expand Down
44 changes: 0 additions & 44 deletions Usermode/libsyscalls/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ pub use ::values::VFSFileOpenMode as FileOpenMode;
pub use ::values::VFSMemoryMapMode as MemoryMapMode;


impl From<Error> for ::std_io::Error {
fn from(v: Error) -> ::std_io::Error {
::std_io::Error
}
}

fn to_obj(val: usize) -> Result<super::ObjectHandle, Error> {
super::ObjectHandle::new(val).map_err(|code| Error::from(code))
}
Expand Down Expand Up @@ -141,44 +135,6 @@ impl ::Object for File {
}


impl ::std_io::Read for File {
fn read(&mut self, buf: &mut [u8]) -> ::std_io::Result<usize> {
match self.read(buf)
{
Ok(v) => Ok(v),
Err(e) => {
panic!("TODO: Convert VFS error to io error: {:?}", e);
},
}
}
}
impl ::std_io::Seek for File {
fn seek(&mut self, pos: ::std_io::SeekFrom) -> ::std_io::Result<u64> {
use std_io::SeekFrom;
match pos
{
SeekFrom::Start(pos) => self.set_cursor(pos),
SeekFrom::End(ofs) => {
let pos = if ofs < 0 {
self.get_size() - (-ofs) as u64
} else {
self.get_size() + ofs as u64
};
self.set_cursor(pos);
},
SeekFrom::Current(ofs) => {
let pos = if ofs < 0 {
self.get_cursor() - (-ofs) as u64
} else {
self.get_cursor() + ofs as u64
};
self.set_cursor(pos);
},
}
Ok(self.get_cursor())
}
}

impl Dir
{
/// Open a directory for iteration
Expand Down
82 changes: 80 additions & 2 deletions Usermode/libwtk/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,69 @@ impl_conv! {
}}
}

fn get_4_bytes<F: ::std::io::Read>(f: &mut F) -> Result<[u8; 4], ::std::io::Error> {
let mut rv = [0; 4];
if try!(f.read(&mut rv)) != 4 {
todo!("Handle unexpected EOF in get_4_bytes");
}
Ok( rv )
}

/// Full-colour raster image
pub struct RasterRGB
{
width: usize,
data: Vec<u32>,
}
impl RasterRGB
{
pub fn new_img<P: AsRef<::std::fs::Path>>(path: P) -> Result<Image<Self>,LoadError> {
Self::new(path).map(|b| Image::new(b))
}
pub fn new<P: AsRef<::std::fs::Path>>(path: P) -> Result<RasterRGB,LoadError> {
use ::byteorder::{LittleEndian,ReadBytesExt};
use std::io::Read;
let path = path.as_ref();
let mut file = try!( ::std::fs::File::open(path) );
// - Check magic
if &try!(get_4_bytes(&mut file)) != b"\x7FR24" {
return Err(LoadError::Malformed);
}
// - Read dimensions
let w = try!( file.read_u16::<LittleEndian>() ) as usize;
let h = try!( file.read_u16::<LittleEndian>() ) as usize;
// - Read data
let mut data = Vec::with_capacity(w*h);
for _ in 0 .. w * h
{
let mut px = [0; 3];
if try!(file.read(&mut px)) != 3 { return Err(LoadError::Malformed); }
let v = (px[0] as u32) << 16 | (px[1] as u32) << 8 | (px[2] as u32) << 0;
data.push(v);
}

Ok(RasterRGB {
width: w,
data: data,
})
}
}
impl Buffer for RasterRGB {
fn dims_px(&self) -> Rect<Px> {
Rect::new(0,0, self.width as u32, (self.data.len() / self.width) as u32)
}
fn render(&self, buf: ::surface::SurfaceView) {
let mut buf_rows = self.data.chunks(self.width);
buf.foreach_scanlines(self.dims_px(), |_row, line| {
let val = buf_rows.next().unwrap();
for (d, v) in Iterator::zip( line.iter_mut(), val.iter().cloned() )
{
*d = v;
}
});
}
}

/// Raster single-colour image with alpha
pub struct RasterMonoA
{
Expand All @@ -91,14 +154,22 @@ pub struct RasterMonoA
}
impl RasterMonoA
{
pub fn new_img<P: AsRef<::std::fs::Path>>(path: P, fg: ::surface::Colour) -> Result<Image<Self>,LoadError> {
Self::new(path, fg).map(|b| Image::new(b))
}
pub fn new<P: AsRef<::std::fs::Path>>(path: P, fg: ::surface::Colour) -> Result<RasterMonoA,LoadError> {
use ::byteorder::{LittleEndian,ReadBytesExt};
use std::io::Read;
let path = path.as_ref();
let mut file = try!( ::std::fs::File::open(path) );
// - Check magic
if &try!(get_4_bytes(&mut file)) != b"\x7FR8M" {
return Err(LoadError::Malformed);
}
// - Read dimensions
let w = try!( file.read_u16::<LittleEndian>() ) as usize;
let h = try!( file.read_u16::<LittleEndian>() ) as usize;
kernel_log!("(w,h) = ({},{})", w, h);
// - Read data (directly)
let mut alpha: Vec<u8> = (0 .. w*h).map(|_| 0u8).collect();
try!(file.read(&mut alpha));
Ok(RasterMonoA {
Expand All @@ -113,7 +184,6 @@ impl Buffer for RasterMonoA {
Rect::new(0,0, self.width as u32, (self.alpha.len() / self.width) as u32)
}
fn render(&self, buf: ::surface::SurfaceView) {
// - Alpha defaults to zero if the alpha vec is empty
let mut buf_rows = self.alpha.chunks(self.width);
buf.foreach_scanlines(self.dims_px(), |_row, line| {
let alpha = buf_rows.next().unwrap();
Expand All @@ -136,10 +206,18 @@ pub struct RasterBiA
}
impl RasterBiA
{
pub fn new_img<P: AsRef<::std::fs::Path>>(path: P, fg: ::surface::Colour, bg: ::surface::Colour) -> Result<Image<Self>,LoadError> {
Self::new(path, fg, bg).map(|b| Image::new(b))
}
pub fn new<P: AsRef<::std::fs::Path>>(path: P, fg: ::surface::Colour, bg: ::surface::Colour) -> Result<RasterBiA,LoadError> {
use ::byteorder::{LittleEndian,ReadBytesExt};
let path = path.as_ref();
let mut file = try!( ::std::fs::File::open(path) );
// - Check magic
if &try!(get_4_bytes(&mut file)) != b"\x7FR8B" {
return Err(LoadError::Malformed);
}
// - Read dimensions
let w = try!( file.read_u16::<LittleEndian>() ) as usize;
let h = try!( file.read_u16::<LittleEndian>() ) as usize;

Expand Down
10 changes: 10 additions & 0 deletions Usermode/libwtk/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod window;
mod layout;
mod static_layout;
mod input;
mod text;

pub mod image;

Expand Down Expand Up @@ -67,3 +68,12 @@ pub use image::Image;
pub use static_layout::Box as StaticBox;
pub use static_layout::BoxEle;

pub use text::Label;

pub fn initialise()
{
use syscalls::Object;
use syscalls::threads::{S_THIS_PROCESS,ThisProcessWaits};
::syscalls::threads::wait(&mut [S_THIS_PROCESS.get_wait(ThisProcessWaits::new().recv_obj())], !0);
::syscalls::gui::set_group( S_THIS_PROCESS.receive_object::<::syscalls::gui::Group>(0).unwrap() );
}
Loading

0 comments on commit c334171

Please sign in to comment.