2020-03-12 13:34:48 -05:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(custom_test_frameworks)]
|
|
|
|
#![reexport_test_harness_main = "test_main"]
|
|
|
|
#![test_runner(testing::test_runner)]
|
|
|
|
|
|
|
|
use core::panic::PanicInfo;
|
2020-03-12 23:41:00 -05:00
|
|
|
use testing::{gdt, interrupts, serial_print, serial_println};
|
2020-03-14 22:55:48 -05:00
|
|
|
use vga::{
|
2020-03-15 17:30:28 -05:00
|
|
|
Vga, VgaConfiguration, VideoMode, DEFAULT_PALETTE, MODE_40X25_CONFIGURATION,
|
|
|
|
MODE_40X50_CONFIGURATION, MODE_640X480X16_CONFIGURATION, MODE_80X25_CONFIGURATION,
|
|
|
|
PALETTE_SIZE, VGA,
|
2020-03-14 22:55:48 -05:00
|
|
|
};
|
2020-03-12 13:34:48 -05:00
|
|
|
|
|
|
|
#[no_mangle] // don't mangle the name of this function
|
|
|
|
pub extern "C" fn _start() -> ! {
|
2020-03-12 23:41:00 -05:00
|
|
|
init();
|
2020-03-12 13:34:48 -05:00
|
|
|
test_main();
|
|
|
|
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
2020-03-12 23:41:00 -05:00
|
|
|
fn init() {
|
|
|
|
gdt::init();
|
|
|
|
interrupts::init_idt();
|
|
|
|
unsafe { interrupts::PICS.lock().initialize() };
|
|
|
|
x86_64::instructions::interrupts::enable();
|
|
|
|
}
|
|
|
|
|
2020-03-12 13:34:48 -05:00
|
|
|
#[panic_handler]
|
|
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
|
|
testing::test_panic_handler(info)
|
|
|
|
}
|
|
|
|
|
2020-03-14 22:55:48 -05:00
|
|
|
#[test_case]
|
|
|
|
fn set_mode_40x25() {
|
|
|
|
serial_print!("mode 40x25... ");
|
|
|
|
|
|
|
|
let mut vga = VGA.lock();
|
|
|
|
vga.set_video_mode(VideoMode::Mode40x25);
|
|
|
|
check_registers(&mut vga, &MODE_40X25_CONFIGURATION);
|
|
|
|
|
|
|
|
serial_println!("[ok]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test_case]
|
|
|
|
fn set_mode_40x50() {
|
|
|
|
serial_print!("mode 40x50... ");
|
|
|
|
|
|
|
|
let mut vga = VGA.lock();
|
|
|
|
vga.set_video_mode(VideoMode::Mode40x50);
|
|
|
|
check_registers(&mut vga, &MODE_40X50_CONFIGURATION);
|
|
|
|
|
|
|
|
serial_println!("[ok]");
|
|
|
|
}
|
|
|
|
|
2020-03-12 13:34:48 -05:00
|
|
|
#[test_case]
|
2020-03-12 23:41:00 -05:00
|
|
|
fn set_mode_80x25() {
|
|
|
|
serial_print!("mode 80x25... ");
|
|
|
|
|
|
|
|
let mut vga = VGA.lock();
|
|
|
|
vga.set_video_mode(VideoMode::Mode80x25);
|
2020-03-14 22:55:48 -05:00
|
|
|
check_registers(&mut vga, &MODE_80X25_CONFIGURATION);
|
2020-03-12 23:41:00 -05:00
|
|
|
|
2020-03-12 13:34:48 -05:00
|
|
|
serial_println!("[ok]");
|
|
|
|
}
|
2020-03-14 22:55:48 -05:00
|
|
|
|
|
|
|
#[test_case]
|
|
|
|
fn set_mode_640x480x16() {
|
|
|
|
serial_print!("mode 640x480x16... ");
|
|
|
|
|
|
|
|
let mut vga = VGA.lock();
|
|
|
|
vga.set_video_mode(VideoMode::Mode640x480x16);
|
|
|
|
check_registers(&mut vga, &MODE_640X480X16_CONFIGURATION);
|
|
|
|
|
|
|
|
serial_println!("[ok]");
|
|
|
|
}
|
|
|
|
|
2020-03-15 17:30:28 -05:00
|
|
|
#[test_case]
|
|
|
|
fn load_palette() {
|
|
|
|
serial_print!("load palette... ");
|
|
|
|
|
|
|
|
let mut palette = [0u8; PALETTE_SIZE];
|
|
|
|
let mut vga = VGA.lock();
|
|
|
|
vga.load_palette(&DEFAULT_PALETTE);
|
|
|
|
vga.read_palette(&mut palette);
|
|
|
|
|
|
|
|
for i in 0..PALETTE_SIZE {
|
|
|
|
assert_eq!(palette[i], DEFAULT_PALETTE[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
serial_println!("[ok]");
|
|
|
|
}
|
|
|
|
|
2020-03-14 22:55:48 -05:00
|
|
|
fn check_registers(vga: &mut Vga, configuration: &VgaConfiguration) {
|
|
|
|
let emulation_mode = vga.get_emulation_mode();
|
|
|
|
assert_eq!(vga.read_msr(), configuration.miscellaneous_output);
|
|
|
|
|
|
|
|
for (index, value) in configuration.sequencer_registers {
|
|
|
|
assert_eq!(vga.read_sequencer(*index), *value);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index, value) in configuration.crtc_controller_registers {
|
|
|
|
assert_eq!(vga.read_crtc_controller(emulation_mode, *index), *value);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index, value) in configuration.graphics_controller_registers {
|
|
|
|
assert_eq!(vga.read_graphics_controller(*index), *value);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index, value) in configuration.attribute_controller_registers {
|
|
|
|
assert_eq!(
|
|
|
|
vga.read_attribute_controller(emulation_mode, *index),
|
|
|
|
*value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|