This will be the end of me

This commit is contained in:
Gvidas Juknevičius 2024-09-02 20:55:25 +03:00
parent 12e9a068e9
commit 08b2d22662
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
4 changed files with 52 additions and 7 deletions

View File

@ -6,6 +6,8 @@
#![feature(ptr_internals)]
#![feature(allocator_api)]
use std::vga::video::Color;
use mem::paging::ActivePageTable;
use multiboot2::{BootInformation, BootInformationHeader};
use pc_keyboard::KeyCode;
@ -37,11 +39,11 @@ fn init(mb2p: *const BootInformationHeader) -> ActivePageTable {
#[no_mangle]
extern "C" fn kmain(mb2p: *const BootInformationHeader) -> ! {
let _ = init(mb2p); // active table
let vc = std::vga::video::VideoControler::new(mb2p);
// vc.set_px(0, 0, Color::new(0xFF, 0xFF, 0x0));
// vc.fill_screen(Color::new(0xFF, 0x0, 0x0));
let boot_info = unsafe { BootInformation::load(mb2p).unwrap() };
let fb = boot_info.framebuffer_tag().unwrap().unwrap();
log::debug!("{fb:?}");
log::debug!("{}", std::vga::video::is_video_mode_enabled());
log::info!("end of work");
loop {
if std::input::is_key_down(KeyCode::A) {

View File

@ -124,6 +124,8 @@ pub struct MemInfo<'a>{
pub kernel_end: usize,
pub mb_start: usize,
pub mb_end: usize,
pub vga_vide_start: usize,
pub vga_vide_size: usize,
}
impl MemInfo<'_> {
@ -148,6 +150,9 @@ impl MemInfo<'_> {
let kernel_end = elf_secs.clone().filter(|s| s.is_allocated()).map(|s| s.end_address()).min().unwrap() as usize;
let mb_start = boot_info.start_address();
let mb_end = boot_info.end_address();
let vv_info = boot_info.framebuffer_tag().unwrap().unwrap();
let vv_start = vv_info.address();
let vv_size = vv_info.width() * vv_info.height();
//log::debug!("Kernel: start: 0x{:x} sz: 0x{:x}", mi.kernel_start, mi.kernel_end - mi.kernel_start);
//log::debug!("Multiboot: start: 0x{:x} sz: 0x{:x}", mi.mb_start, mi.mb_end - mi.mb_start);
@ -159,6 +164,8 @@ impl MemInfo<'_> {
kernel_end,
mb_start,
mb_end,
vga_vide_start: vv_start as usize,
vga_vide_size: vv_size as usize
}
}
}

View File

@ -205,8 +205,13 @@ pub fn remap_the_kernel<A>(allocator: &mut A, mem_info: &MemInfo) -> ActivePageT
mapper.identity_map(frame, flags, allocator);
}
}
let vga_buffer_frame = Frame::containing_address(0xb8000);
mapper.identity_map(vga_buffer_frame, EntryFlags::WRITABLE, allocator);
let vga_text_buffer_frame = Frame::containing_address(0xb8000);
let vga_video_buffer_frame_start = Frame::containing_address(mem_info.vga_vide_start);
let vga_video_buffer_frame_end = Frame::containing_address((mem_info.vga_vide_start + mem_info.vga_vide_size*3));
for frame in Frame::range_inclusive(vga_video_buffer_frame_start, vga_video_buffer_frame_end) {
mapper.identity_map(frame, EntryFlags::PRESENT | EntryFlags::WRITABLE, allocator);
}
mapper.identity_map(vga_text_buffer_frame, EntryFlags::WRITABLE, allocator);
let multiboot_start = Frame::containing_address(mem_info.boot_info.start_address());
let multiboot_end = Frame::containing_address(mem_info.boot_info.end_address() - 1);
for frame in Frame::range_inclusive(multiboot_start, multiboot_end) {

View File

@ -9,6 +9,18 @@ use spin::{Mutex, MutexGuard};
pub use util::is_video_mode_enabled;
#[derive(Clone, Copy)]
pub struct Color {
r: u8,
g: u8,
b: u8,
}
impl Color {
pub fn new(r: u8, g: u8, b: u8) -> Self {
Self {r, g, b}
}
}
pub struct VideoControler{
component_size: u8,
@ -27,7 +39,8 @@ impl VideoControler {
panic!();
};
assert!(red.size == green.size && green.size == blue.size);
log::info!("VGA VIDEO adddr: {:x}", fbt.address());
log::info!("VGA VIDEO FB TYPE: {:?}", fbt.buffer_type());
Self {
component_size: red.size,
r_ofs: red.position,
@ -37,5 +50,23 @@ impl VideoControler {
size: Vector2::new(fbt.width() as usize, fbt.height() as usize)
}
}
pub fn set_px(&self, x: usize, y: usize, c: Color) {
let ptr = self.buf_addr as *mut () as *mut u8;
let px = ptr.wrapping_add(x * self.size.x + y);
unsafe {
*px.wrapping_add((self.r_ofs % 8) as usize) = c.r;
*px.wrapping_add((self.g_ofs % 8) as usize) = c.g;
*px.wrapping_add((self.b_ofs % 8) as usize) = c.b;
}
}
pub fn fill_screen(&self, c: Color) {
for x in 0..100 {
for y in 0..100 {
self.set_px(x, y, c);
}
}
}
}