2021-09-28 23:09:38 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod error;
|
|
|
|
mod memory;
|
2021-10-04 03:45:50 +00:00
|
|
|
mod timers;
|
2021-10-09 06:11:52 +00:00
|
|
|
mod devices;
|
|
|
|
mod interrupts;
|
2021-09-30 00:11:48 +00:00
|
|
|
mod cpus;
|
2021-10-06 23:14:56 +00:00
|
|
|
mod peripherals;
|
|
|
|
mod system;
|
2021-09-28 23:09:38 +00:00
|
|
|
|
2021-10-09 06:11:52 +00:00
|
|
|
use crate::system::System;
|
2021-10-06 23:14:56 +00:00
|
|
|
use crate::memory::MemoryBlock;
|
2021-09-30 00:11:48 +00:00
|
|
|
use crate::cpus::m68k::MC68010;
|
2021-10-06 23:14:56 +00:00
|
|
|
use crate::peripherals::ata::AtaDevice;
|
|
|
|
use crate::peripherals::mc68681::MC68681;
|
2021-10-09 06:11:52 +00:00
|
|
|
use crate::devices::{wrap_addressable, wrap_interruptable};
|
2021-09-28 23:09:38 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-10-06 23:14:56 +00:00
|
|
|
let mut system = System::new();
|
|
|
|
|
2021-10-03 16:55:20 +00:00
|
|
|
let monitor = MemoryBlock::load("binaries/monitor.bin").unwrap();
|
2021-09-28 23:09:38 +00:00
|
|
|
for byte in monitor.contents.iter() {
|
|
|
|
print!("{:02x} ", byte);
|
|
|
|
}
|
2021-10-07 16:41:01 +00:00
|
|
|
system.add_addressable_device(0x00000000, wrap_addressable(monitor)).unwrap();
|
2021-09-28 23:09:38 +00:00
|
|
|
|
2021-10-03 16:55:20 +00:00
|
|
|
let mut ram = MemoryBlock::new(vec![0; 0x00100000]);
|
|
|
|
ram.load_at(0, "binaries/kernel.bin").unwrap();
|
2021-10-07 16:41:01 +00:00
|
|
|
system.add_addressable_device(0x00100000, wrap_addressable(ram)).unwrap();
|
2021-09-28 23:09:38 +00:00
|
|
|
|
2021-10-04 20:02:58 +00:00
|
|
|
let mut ata = AtaDevice::new();
|
2021-10-05 23:22:21 +00:00
|
|
|
ata.load("binaries/disk-with-partition-table.img").unwrap();
|
2021-10-07 16:41:01 +00:00
|
|
|
system.add_addressable_device(0x00600000, wrap_addressable(ata)).unwrap();
|
2021-10-04 20:02:58 +00:00
|
|
|
|
2021-10-01 03:27:01 +00:00
|
|
|
let mut serial = MC68681::new();
|
2021-10-10 00:35:23 +00:00
|
|
|
launch_terminal_emulator(serial.port_a.open().unwrap());
|
|
|
|
launch_slip_connection(serial.port_b.open().unwrap());
|
2021-10-07 16:41:01 +00:00
|
|
|
system.add_addressable_device(0x00700000, wrap_addressable(serial)).unwrap();
|
2021-10-06 23:14:56 +00:00
|
|
|
|
2021-09-30 04:52:38 +00:00
|
|
|
|
2021-09-28 23:09:38 +00:00
|
|
|
let mut cpu = MC68010::new();
|
Added MUL, DIV, NEG, DBcc, and Scc instructions, and fixed issue with ADD/SUB flags
With ADDA, SUBA, and ADDQ/SUBQ when the target is an address register, the condition
flags should not be changed, but the code was changing them, which caused problems.
I've fixed it by making the ADD/SUB executions check for an address target and
will not update flags in that case. This should only occur when the actual instruction
was an ADDA or ADDQ with an address register target
2021-10-03 04:59:28 +00:00
|
|
|
|
2021-10-06 02:58:22 +00:00
|
|
|
//cpu.enable_tracing();
|
2021-10-08 17:52:15 +00:00
|
|
|
//cpu.add_breakpoint(0x10781a);
|
|
|
|
//cpu.add_breakpoint(0x10bc9c);
|
|
|
|
//cpu.add_breakpoint(0x106a94);
|
2021-10-10 00:35:23 +00:00
|
|
|
//cpu.add_breakpoint(0x10d0c6);
|
2021-10-02 05:06:53 +00:00
|
|
|
|
2021-10-07 18:35:15 +00:00
|
|
|
system.add_interruptable_device(wrap_interruptable(cpu)).unwrap();
|
|
|
|
loop {
|
|
|
|
match system.step() {
|
2021-09-30 04:52:38 +00:00
|
|
|
Ok(()) => { },
|
|
|
|
Err(err) => {
|
2021-10-07 18:35:15 +00:00
|
|
|
system.exit_error();
|
2021-10-10 03:35:52 +00:00
|
|
|
println!("{:?}", err);
|
|
|
|
break;
|
2021-09-30 04:52:38 +00:00
|
|
|
},
|
|
|
|
}
|
2021-09-28 23:09:38 +00:00
|
|
|
}
|
2021-10-02 05:06:53 +00:00
|
|
|
|
|
|
|
/*
|
Added MUL, DIV, NEG, DBcc, and Scc instructions, and fixed issue with ADD/SUB flags
With ADDA, SUBA, and ADDQ/SUBQ when the target is an address register, the condition
flags should not be changed, but the code was changing them, which caused problems.
I've fixed it by making the ADD/SUB executions check for an address target and
will not update flags in that case. This should only occur when the actual instruction
was an ADDA or ADDQ with an address register target
2021-10-03 04:59:28 +00:00
|
|
|
// TODO I need to add a way to decode and dump the assembly for a section of code, in debugger
|
2021-10-08 17:52:15 +00:00
|
|
|
cpu.enable_tracing();
|
|
|
|
cpu.state.pc = 0x0010781a;
|
2021-10-02 05:06:53 +00:00
|
|
|
while cpu.is_running() {
|
2021-10-08 17:52:15 +00:00
|
|
|
match cpu.decode_next(&system) {
|
2021-10-03 16:55:20 +00:00
|
|
|
Ok(()) => { },
|
|
|
|
Err(err) => {
|
2021-10-08 17:52:15 +00:00
|
|
|
cpu.dump_state(&system);
|
2021-10-03 16:55:20 +00:00
|
|
|
panic!("{:?}", err);
|
|
|
|
},
|
|
|
|
}
|
2021-10-02 05:06:53 +00:00
|
|
|
}
|
|
|
|
*/
|
2021-09-28 23:09:38 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 00:35:23 +00:00
|
|
|
pub fn launch_terminal_emulator(name: String) {
|
|
|
|
use nix::unistd::sleep;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
Command::new("x-terminal-emulator").arg("-e").arg(&format!("pyserial-miniterm {}", name)).spawn().unwrap();
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn launch_slip_connection(name: String) {
|
|
|
|
use nix::unistd::sleep;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
//Command::new("x-terminal-emulator").arg("-e").arg(&format!("pyserial-miniterm {}", name)).spawn().unwrap();
|
|
|
|
|
|
|
|
Command::new("sudo").args(["slattach", "-s", "38400", "-p", "slip", &name]).spawn().unwrap();
|
|
|
|
Command::new("sudo").args(["ifconfig", "sl0", "192.168.1.2", "pointopoint", "192.168.1.200", "up"]).status().unwrap();
|
|
|
|
Command::new("sudo").args(["arp", "-Ds", "192.168.1.200", "enp4s0", "pub"]).status().unwrap();
|
|
|
|
Command::new("sudo").args(["iptables", "-A", "FORWARD", "-i", "sl0", "-j", "ACCEPT"]).status().unwrap();
|
|
|
|
Command::new("sudo").args(["iptables", "-A", "FORWARD", "-o", "sl0", "-j", "ACCEPT"]).status().unwrap();
|
|
|
|
Command::new("sudo").args(["sh", "-c", "echo 1 > /proc/sys/net/ipv4/ip_forward"]).status().unwrap();
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
sudo slattach -s 38400 -p slip /dev/ttyUSB1
|
|
|
|
sudo ifconfig sl0 192.168.1.2 pointopoint 192.168.1.200 up
|
|
|
|
// (this is automatically added on my machine) >> sudo route add -host 192.168.1.200 sl0
|
|
|
|
sudo arp -Ds 192.168.1.200 enp3s0 pub
|
|
|
|
sudo iptables -A FORWARD -i sl0 -j ACCEPT
|
|
|
|
sudo iptables -A FORWARD -o sl0 -j ACCEPT
|
|
|
|
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
|
|
|
|
*/
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|