updates and planning

master
able 2022-06-02 06:00:26 -05:00
parent 146082c668
commit 570525cbd7
11 changed files with 370 additions and 7 deletions

21
TODO.md Normal file
View File

@ -0,0 +1,21 @@
# AbleOS
## General
- [ ] Improve EXT2
## ARM
- [ ] Get arm-version booting on real hardware
# Drivers
- [ ] Slim down driver specific program code
- [ ] Remove entry/exit functions for drivers
# Tooling
## Repbuild
- [ ] make generation of the ext2 image possible

View File

@ -1,2 +0,0 @@
- [ ] Simple interactive "painting" "program"
- [ ] monotty like desktop environment

130
ableos/src/bogomips.rs Normal file
View File

@ -0,0 +1,130 @@
use crate::time::fetch_time;
fn delay(ms: u64) {
let mut i = 0;
while i < ms {
i += 1;
}
}
pub const CLOCKS_PER_SEC: u64 = 1000;
pub fn bogomips() -> u32 {
let mut loops_per_sec:u64 = 1;
let mut ticks: u64 = 0;
info!("bogomips: starting");
while (loops_per_sec << 1) != 0 {
ticks = fetch_time() as u64;
delay(loops_per_sec);
ticks = fetch_time() as u64 - ticks;
if ticks >= CLOCKS_PER_SEC {
loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
println!("ok - {}.{} BogoMips\n",
loops_per_sec/500000,
(loops_per_sec/5000) % 100
);
return 0;
}
}
println!("bogomips: failed to get a result");
return 61;
}
/*
asm!{
}
#ifdef CLASSIC_BOGOMIPS
/* the original code from the Linux kernel */
static __inline__ void delay(int loops)
{
__asm__(".align 2,0x90\n1:\tdecl %0\n\tjns 1b": :"a" (loops):"ax");
}
#endif
#ifdef QNX_BOGOMIPS
/* version for QNX C compiler */
void delay(int loops);
#pragma aux delay = \
"l1:" \
"dec eax" \
"jns l1" \
parm nomemory [eax] modify exact nomemory [eax];
#endif
#ifdef PORTABLE_BOGOMIPS
/* portable version */
static void delay(int loops)
{
long i;
for (i = loops; i >= 0 ; i--)
;
}
#endif
int
main(void)
{
unsigned long loops_per_sec = 1;
unsigned long ticks;
printf("Calibrating delay loop.. ");
fflush(stdout);
while ((loops_per_sec <<= 1)) {
ticks = clock();
delay(loops_per_sec);
ticks = clock() - ticks;
if (ticks >= CLOCKS_PER_SEC) {
loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
printf("ok - %lu.%02lu BogoMips\n",
loops_per_sec/500000,
(loops_per_sec/5000) % 100
);
return 0;
}
}
printf("failed\n");
return -1;
}
*/

View File

@ -1,6 +1,12 @@
use ab_glyph::{Font, FontRef, Glyph};
use shadeable::{evaluate_shader, pixel_format::Rgba64};
use shadeable::{
evaluate_shader,
pixel_format::{get_b, get_g, get_r, Rgba64},
};
use spin::Lazy;
use vga::{colors::Color16, writers::GraphicsWriter};
use crate::vga_e::VGAE;
pub static SCREEN_BUFFER: Lazy<spin::Mutex<ScreenBuffer>> =
Lazy::new(|| spin::Mutex::new(ScreenBuffer::new(640, 480)));
@ -123,7 +129,9 @@ impl ScreenBuffer {
// TODO force clear
pub fn force_redraw(&mut self) {
// VGAE.lock().clear_screen(vga::colors::Color16::Black);
let vga = VGAE.lock();
vga.set_mode();
vga.clear_screen(vga::colors::Color16::Black);
}
/// Draw a glyph on the screen at the given position
@ -240,3 +248,95 @@ pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)
coordinates
}
pub trait VgaBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn;
}
impl VgaBuffer for ScreenBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn {
let mode = VGAE.lock();
for y in 0..self.size.y {
for x in 0..self.size.x {
// use shadeable::pixel_format::into_vga_16;
let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
if into_vga_16(self.clear_color) != vga_color {
mode.set_pixel(x, y, vga_color);
}
}
}
GraphicsReturn::Ok
}
}
pub fn into_vga_16(rgba_64: Rgba64) -> Color16 {
use shadeable::pixel_format::ChannelValue::*;
use vga::colors::Color16::*;
match (
get_r(rgba_64).into(),
get_g(rgba_64).into(),
get_b(rgba_64).into(),
) {
(Dark, Dark, Dark) => Black,
(Dark, Dark, Low) => Black,
(Dark, Dark, Mid) => Blue,
(Dark, Dark, High) => Blue,
(Dark, Low, Dark) => Black,
(Dark, Low, Low) => Black,
(Dark, Low, Mid) => Blue,
(Dark, Low, High) => Blue,
(Dark, Mid, Dark) => Green,
(Dark, Mid, Low) => Green,
(Dark, Mid, Mid) => Cyan,
(Dark, Mid, High) => Cyan,
(Dark, High, Dark) => Green,
(Dark, High, Low) => Green,
(Dark, High, Mid) => Green,
(Dark, High, High) => Cyan,
(Low, Dark, Dark) => Black,
(Low, Dark, Low) => Black,
(Low, Dark, Mid) => Blue,
(Low, Dark, High) => Blue,
(Low, Low, Dark) => Black,
(Low, Low, Low) => DarkGrey,
(Low, Low, Mid) => LightGrey,
(Low, Low, High) => Blue,
(Low, Mid, Dark) => DarkGrey,
(Low, Mid, Low) => LightGrey,
(Low, Mid, Mid) => Cyan,
(Low, Mid, High) => Cyan,
(Low, High, Dark) => Green,
(Low, High, Low) => Green,
(Low, High, Mid) => Cyan,
(Low, High, High) => Cyan,
(Mid, Dark, Dark) => Red,
(Mid, Dark, Low) => Red,
(Mid, Dark, Mid) => Magenta,
(Mid, Dark, High) => Magenta,
(Mid, Low, Dark) => Brown,
(Mid, Low, Low) => Red,
(Mid, Low, Mid) => DarkGrey,
(Mid, Low, High) => LightBlue,
(Mid, Mid, Dark) => Brown,
(Mid, Mid, Low) => Brown,
(Mid, Mid, Mid) => LightGrey,
(Mid, Mid, High) => LightBlue,
(Mid, High, Dark) => Green,
(Mid, High, Low) => Green,
(Mid, High, Mid) => LightGreen,
(Mid, High, High) => LightCyan,
(High, Dark, Dark) => Red,
(High, Dark, _) => Magenta,
(High, Low, Dark) => Red,
(High, Low, Low) => LightRed,
(High, Low, Mid) => Pink,
(High, Low, High) => Magenta,
(High, Mid, Dark) => Yellow,
(High, Mid, Low) => Yellow,
(High, Mid, Mid) => LightRed,
(High, Mid, High) => Pink,
(High, High, Dark) => Yellow,
(High, High, Low) => White,
(High, High, Mid) => White,
(High, High, High) => White,
}
}

View File

@ -60,9 +60,11 @@ pub mod time;
pub mod utils;
pub mod virtio;
pub mod wasm;
pub mod bogomips;
pub mod wasm_jumploader;
mod unicode_utils;
pub mod vga_e;
#[prelude_import]
pub use prelude::rust_2021::*;

View File

@ -5,11 +5,13 @@ use crate::filesystem::FILE_SYSTEM;
use crate::rhai_shell::shell;
use crate::rhai_shell::KEYBUFF;
use crate::wasm_jumploader::run_program;
use crate::{SCREEN_BUFFER, bogomips};
use acpi::{AcpiTables, PlatformInfo};
use cpuio::inb;
use cpuio::outb;
use genfs::Fs;
use genfs::OpenOptions;
use vga::writers::GraphicsWriter;
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -93,8 +95,29 @@ pub fn scratchpad() {
debug!("{}", generate_process_pass());
}
debug!("start the graphics");
let mut abcde = SCREEN_BUFFER.lock();
abcde.force_redraw();
abcde.draw_filled_circle(100, 100, 300, 0x0000ff00);
abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000);
abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000);
abcde.draw_line(100, 100, 400, 200, 0xff000000);
abcde.copy_to_buffer();
debug!("end the graphics");
// */
use crate::bogomips::bogomips;
// bogomips();
real_shell();
}
use crate::graphics::VgaBuffer;
pub fn acpi() {
let acpi_handler = AcpiStruct {};

View File

@ -7,14 +7,14 @@ pub static VGAE_BUFF_OFFSET_X: spin::Mutex<u8> = spin::Mutex::new(0);
pub static VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
pub static VGAE: spin::Mutex<Graphics640x480x16> = {
let xyz = Graphics640x480x16::new();
xyz.set_mode();
// xyz.set_mode();
spin::Mutex::new(xyz)
};
/// Converts a number to ... i forgor 💀
pub const fn num_to_vga16(num: u8) -> Color16 {
use Color16::*;
match num {
0 => Black,
1 => Blue,

12
api/file.axel Normal file
View File

@ -0,0 +1,12 @@
file {
val=
name: "Hi"
extension: "txt"
size: 123
fn|
open: (None)->()
read: (Num)->(String)
write: (Num, String)->(Bool)
close: (None)->(Bool)
}

View File

@ -2,7 +2,7 @@ use core::ops::{BitAnd, BitOr, Shr};
pub type Rgba64 = u64;
enum ChannelValue {
pub enum ChannelValue {
Dark,
Low,
Mid,

77
userland/bogomips.c Normal file
View File

@ -0,0 +1,77 @@
// Utterly stolen from stack overflow
/*
* Standalone BogoMips program
*
* Based on code Linux kernel code in init/main.c and
* include/linux/delay.h
*
* For more information on interpreting the results, see the BogoMIPS
* Mini-HOWTO document.
*
* version: 1.3
* author: Jeff Tranter (Jeff_Tranter@Mitel.COM)
*/
#include <stdio.h>
#include <time.h>
#ifdef CLASSIC_BOGOMIPS
/* the original code from the Linux kernel */
static __inline__ void delay(int loops)
{
__asm__(".align 2,0x90\n1:\tdecl %0\n\tjns 1b": :"a" (loops):"ax");
}
#endif
#ifdef QNX_BOGOMIPS
/* version for QNX C compiler */
void delay(int loops);
#pragma aux delay = \
"l1:" \
"dec eax" \
"jns l1" \
parm nomemory [eax] modify exact nomemory [eax];
#endif
#ifdef PORTABLE_BOGOMIPS
/* portable version */
static void delay(int loops)
{
long i;
for (i = loops; i >= 0 ; i--)
;
}
#endif
int
main(void)
{
unsigned long loops_per_sec = 1;
unsigned long ticks;
printf("Calibrating delay loop.. ");
fflush(stdout);
while ((loops_per_sec <<= 1)) {
ticks = clock();
delay(loops_per_sec);
ticks = clock() - ticks;
if (ticks >= CLOCKS_PER_SEC) {
loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
printf("ok - %lu.%02lu BogoMips\n",
loops_per_sec/500000,
(loops_per_sec/5000) % 100
);
return 0;
}
}
printf("failed\n");
return -1;
}

Binary file not shown.