Change target arch to RISCV32IMA. Recover some dependencies.

master
WangRunji 6 years ago
parent 37564cb9fd
commit bf2ad7c6a5

@ -19,26 +19,30 @@ opt-level = 1
[profile.release]
debug = true
[target.x86_64-blog_os.dependencies]
bit_field = "0.9.0"
[dependencies]
rlibc = "1.0"
volatile = "0.1.0"
spin = "0.4.8"
multiboot2 = "0.6"
once = "0.3.3"
xmas-elf = "0.6"
bitflags = "1.0"
bit_field = "0.9.0"
volatile = "0.1.0"
lazy_static = { version = "1.0.0", features = ["spin_no_std"] }
bit-allocator = { path = "crate/bit-allocator" }
[target.x86_64-blog_os.dependencies]
multiboot2 = "0.6"
x86_64 = "0.2.6"
once = "0.3.3"
linked_list_allocator = "0.6"
redox_syscall = "0.1"
xmas-elf = "0.6"
log = "0.4"
uart_16550 = "0.1"
lazy_static = { version = "1.0.0", features = ["spin_no_std"] }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }
bit-allocator = { path = "crate/bit-allocator" }
ucore-memory = { path = "crate/memory" }
[target.riscv32-blog_os.dependencies]
linked_list_allocator = { version = "0.5", default-features = false } # due to rust version
riscv = { path = "crate/riscv" }
bbl = { path = "crate/bbl" }

@ -1,5 +1,6 @@
#![no_std]
#![feature(asm)]
#![feature(universal_impl_trait)]
extern crate bit_field;
@ -108,6 +109,7 @@ impl BitAlloc for BitAlloc16 {
}
#[inline(always)]
#[cfg(target_arch = "x86_64")]
fn log2(x: u16) -> usize {
assert_ne!(x, 0);
let pos: u16;
@ -115,21 +117,27 @@ fn log2(x: u16) -> usize {
pos as usize
}
#[inline(always)]
#[cfg(not(target_arch = "x86_64"))]
fn log2(x: u16) -> usize {
log2_naive(x)
}
#[inline(always)]
fn log2_naive(mut x: u16) -> usize {
assert_ne!(x, 0);
let mut pos = -1;
while x != 0 {
pos += 1;
x >>= 1;
}
pos as usize
}
#[cfg(test)]
mod tests {
use super::*;
#[inline(always)]
fn log2_naive(mut x: u16) -> usize {
assert_ne!(x, 0);
let mut pos = -1;
while x != 0 {
pos += 1;
x >>= 1;
}
pos as usize
}
#[test]
fn log2_() {
for x in 1..=0xffff {

@ -1,5 +1,7 @@
#![no_std]
#![feature(alloc)]
#![feature(universal_impl_trait)]
#![feature(match_default_bindings)]
extern crate alloc;

@ -1,6 +1,8 @@
extern crate riscv;
extern crate bbl;
pub mod serial;
pub fn test() {
bbl::sbi::console_putchar(b'g' as u8 as u32);
println!("Hello RISCV! {}", 123);
}

@ -0,0 +1,13 @@
use super::bbl::sbi;
use core::fmt;
pub struct SerialPort;
impl fmt::Write for SerialPort {
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.bytes() {
sbi::console_putchar(c as u32);
}
Ok(())
}
}

@ -1,35 +1,15 @@
use consts::KERNEL_OFFSET;
use core::ptr::Unique;
use core::fmt;
use spin::Mutex;
use volatile::Volatile;
use x86_64::instructions::port::Port;
use io::Color;
pub const VGA_BUFFER: Unique<VgaBuffer> = unsafe {
Unique::new_unchecked((KERNEL_OFFSET + 0xb8000) as *mut _)
};
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum Color {
Black = 0,
Blue = 1,
Green = 2,
Cyan = 3,
Red = 4,
Magenta = 5,
Brown = 6,
LightGray = 7,
DarkGray = 8,
LightBlue = 9,
LightGreen = 10,
LightCyan = 11,
LightRed = 12,
Pink = 13,
Yellow = 14,
White = 15,
}
#[derive(Debug, Clone, Copy)]
struct ColorCode(u8);
@ -90,12 +70,72 @@ impl VgaBuffer {
}
}
#[cfg(test)]
mod test {
#[test]
fn print_something() {
let vga = unsafe {&mut *VGA_BUFFER};
vga.clear();
vga.write(0, 0, ScreenChar::new('h', Color::LightGray, Color::Black));
lazy_static! {
pub static ref VGA_WRITER: Mutex<VgaWriter> = Mutex::new(
// It is the only user of VGA_BUFFER. So it's safe.
VgaWriter::new(unsafe{ &mut *VGA_BUFFER.as_ptr() })
);
}
pub struct VgaWriter {
column_position: usize,
color: Color,
buffer: &'static mut VgaBuffer,
}
impl VgaWriter {
fn new(buffer: &'static mut VgaBuffer) -> Self {
buffer.clear();
VgaWriter {
column_position: 0,
color: Color::LightGray,
buffer,
}
}
pub fn set_color(&mut self, color: Color) {
self.color = color;
}
pub fn write_byte(&mut self, byte: u8) {
match byte {
b'\n' => self.new_line(),
byte => {
if self.column_position >= BUFFER_WIDTH {
self.new_line();
}
let row = BUFFER_HEIGHT - 1;
let col = self.column_position;
self.buffer.write(row, col, ScreenChar::new(byte, self.color, Color::Black));
self.column_position += 1;
self.buffer.set_cursor_at(row, col);
}
}
}
fn new_line(&mut self) {
for row in 1..BUFFER_HEIGHT {
for col in 0..BUFFER_WIDTH {
let screen_char = self.buffer.read(row, col);
self.buffer.write(row - 1, col, screen_char);
}
}
let blank = ScreenChar::new(b' ', self.color, Color::Black);
for col in 0..BUFFER_WIDTH {
self.buffer.write(BUFFER_HEIGHT - 1, col, blank);
}
self.column_position = 0;
self.buffer.set_cursor_at(BUFFER_HEIGHT - 1, 0);
}
}
impl fmt::Write for VgaWriter {
fn write_str(&mut self, s: &str) -> fmt::Result {
for byte in s.bytes() {
self.write_byte(byte)
}
Ok(())
}
}

@ -1,11 +1,8 @@
use arch::driver::serial::COM1;
use arch::driver::vga::Color;
use core::fmt;
use log;
use log::{Level, LevelFilter, Log, Metadata, Record};
mod vga_writer;
pub fn init() {
static LOGGER: SimpleLogger = SimpleLogger;
log::set_logger(&LOGGER).unwrap();
@ -107,4 +104,26 @@ fn color_to_console_code(color: Color) -> (u8, u8) {
Color::Yellow => (1, 3),
Color::White => (1, 0),
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum Color {
Black = 0,
Blue = 1,
Green = 2,
Cyan = 3,
Red = 4,
Magenta = 5,
Brown = 6,
LightGray = 7,
DarkGray = 8,
LightBlue = 9,
LightGreen = 10,
LightCyan = 11,
LightRed = 12,
Pink = 13,
Yellow = 14,
White = 15,
}

@ -1,73 +0,0 @@
use spin::Mutex;
use core::fmt;
use arch::driver::vga::*;
lazy_static! {
pub static ref VGA_WRITER: Mutex<VgaWriter> = Mutex::new(
// It is the only user of VGA_BUFFER. So it's safe.
VgaWriter::new(unsafe{ &mut *VGA_BUFFER.as_ptr() })
);
}
pub struct VgaWriter {
column_position: usize,
color: Color,
buffer: &'static mut VgaBuffer
}
impl VgaWriter {
fn new(buffer: &'static mut VgaBuffer) -> Self {
buffer.clear();
VgaWriter {
column_position: 0,
color: Color::LightGray,
buffer,
}
}
pub fn set_color(&mut self, color: Color) {
self.color = color;
}
pub fn write_byte(&mut self, byte: u8) {
match byte {
b'\n' => self.new_line(),
byte => {
if self.column_position >= BUFFER_WIDTH {
self.new_line();
}
let row = BUFFER_HEIGHT - 1;
let col = self.column_position;
self.buffer.write(row, col, ScreenChar::new(byte, self.color, Color::Black));
self.column_position += 1;
self.buffer.set_cursor_at(row, col);
}
}
}
fn new_line(&mut self) {
for row in 1..BUFFER_HEIGHT {
for col in 0..BUFFER_WIDTH {
let screen_char = self.buffer.read(row, col);
self.buffer.write(row-1, col, screen_char);
}
}
let blank = ScreenChar::new(b' ', self.color, Color::Black);
for col in 0..BUFFER_WIDTH {
self.buffer.write(BUFFER_HEIGHT-1, col, blank);
}
self.column_position = 0;
self.buffer.set_cursor_at(BUFFER_HEIGHT-1, 0);
}
}
impl fmt::Write for VgaWriter {
fn write_str(&mut self, s: &str) -> fmt::Result {
for byte in s.bytes() {
self.write_byte(byte)
}
Ok(())
}
}

@ -42,11 +42,9 @@ extern crate multiboot2;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate once;
#[cfg(target_arch = "x86_64")]
extern crate rlibc;
#[cfg(target_arch = "x86_64")]
extern crate simple_filesystem;
#[cfg(target_arch = "x86_64")]
extern crate spin;
#[cfg(target_arch = "x86_64")]
extern crate syscall as redox_syscall;
@ -70,6 +68,12 @@ use linked_list_allocator::LockedHeap;
#[macro_use] // print!
#[cfg(target_arch = "x86_64")]
mod io;
#[macro_use] // print!
#[cfg(target_arch = "riscv")]
#[path = "io/riscv_io.rs"]
mod io;
#[cfg(target_arch = "x86_64")]
mod memory;
mod lang;

Loading…
Cancel
Save