Commit work

This commit is contained in:
pjht 2023-09-29 15:45:38 -05:00
parent a4609d7f53
commit b5a694a126
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
6 changed files with 23 additions and 95 deletions

View File

@ -1,9 +1,5 @@
[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins", "alloc"]
[build] [build]
target = "x86_64-unknown-none.json" target = "x86_64-unknown-none"
[install] [install]
root = "../kernel/sysroot" root = "../kernel/sysroot"

61
2
View File

@ -1,61 +0,0 @@
#![no_std]
#![no_main]
#![feature(int_roundings)]
#![deny(unsafe_op_in_unsafe_fn)]
use ext2::Ext2;
use std::fmt::Debug;
use std::loader::{Binary, Loader};
use std::path::Path;
use std::syscalls::{get_initrd, new_process};
use std::{ipc, prelude::*, str};
use tar_no_std::TarArchiveRef;
use ata::PRIMARY_SLAVE;
mod ata;
mod ext2;
main!({
let primary_slave = PRIMARY_SLAVE.unwrap();
let fs = Ext2::new(primary_slave).unwrap();
print_all_files("/", &fs);
println!("Hello, syscall format world!");
let initrd = TarArchiveRef::new(get_initrd());
let test_proc = Binary::new(
initrd
.entries()
.find(|entry| entry.filename() == *"bin/test_proc")
.expect("test_proc not found")
.data(),
)
.expect("test_proc not an ELF binary");
let space = Loader::load(&test_proc);
let pid = new_process(test_proc.entry_point(), space).expect("Failed to create process");
ipc::base::allow_protocol(0);
let id = ipc::rpc::send_call(pid, 0, 0, "Hello, RPC call world".as_bytes());
let ret = loop {
ipc::rpc::process_messages();
if let Some(ret) = ipc::rpc::get_return(id) {
dbg!();
break ret;
}
};
dbg!(&ret.retval);
println!("{}", str::from_utf8(&ret.retval).unwrap());
loop {}
});
fn print_all_files<P: AsRef<Path> + Debug>(path: P, fs: &Ext2) {
for entry in fs.read_dir(path).unwrap() {
let entry = entry.unwrap();
if entry.metadata().file_type().is_dir() {
print_all_files(entry.path(), fs);
} else {
let mut file = fs.open(entry.path()).unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf).unwrap();
print!("{:?}:\n{}", entry.path(), buf);
}
}
}

View File

@ -11,7 +11,7 @@ std = { path = "../std" }
bitflags = "1.3.2" bitflags = "1.3.2"
spin = "0.9.4" spin = "0.9.4"
tap = "1.0.1" tap = "1.0.1"
x86_64 = { git = "https://github.com/pjht/x86_64", features = ["experimental"] } x86_64 = { git = "https://gitea.pterpstra.com/mikros/x86_64", features = ["experimental"] }
binread = { version = "2.2.0", path = "../binread/binread", default-features = false } binread = { version = "2.2.0", path = "../binread/binread", default-features = false }
itertools = { version = "0.10.3", default-features = false, features = ["use_alloc"] } itertools = { version = "0.10.3", default-features = false, features = ["use_alloc"] }
serde = { version = "1.0.144", default-features = false, features = ["alloc", "derive"] } serde = { version = "1.0.144", default-features = false, features = ["alloc", "derive"] }

View File

@ -7,6 +7,7 @@ mod structs;
use block_group_table::BlockGroupDescriptorTable; use block_group_table::BlockGroupDescriptorTable;
use block_reader::BlockReader; use block_reader::BlockReader;
use std::dbg;
use std::io::{self, Read}; use std::io::{self, Read};
use std::path::{Component, Path}; use std::path::{Component, Path};
use std::string::{String, ToString}; use std::string::{String, ToString};
@ -29,7 +30,7 @@ impl Ext2 {
let superblock = Superblock::read_from_disk(&mut disk)?; let superblock = Superblock::read_from_disk(&mut disk)?;
let reader = BlockReader::new(disk, &superblock); let reader = BlockReader::new(disk, &superblock);
Ok(Self { Ok(Self {
descriptor_table: BlockGroupDescriptorTable::new(&superblock, &reader)?, descriptor_table: dbg!(BlockGroupDescriptorTable::new(&superblock, &reader)?),
reader, reader,
}) })
} }

View File

@ -16,8 +16,10 @@ mod ata;
mod ext2; mod ext2;
main!({ main!({
dbg!();
// let primary_slave = PRIMARY_SLAVE.unwrap(); // let primary_slave = PRIMARY_SLAVE.unwrap();
let initrd = TarArchiveRef::new(get_initrd()); let initrd = TarArchiveRef::new(get_initrd());
dbg!();
let test_proc = Binary::new( let test_proc = Binary::new(
initrd initrd
.entries() .entries()
@ -26,30 +28,34 @@ main!({
.data(), .data(),
) )
.expect("test_proc not an ELF binary"); .expect("test_proc not an ELF binary");
dbg!();
let space = Loader::load(&test_proc); let space = Loader::load(&test_proc);
dbg!();
let pid = new_process(test_proc.entry_point(), space).expect("Failed to create process"); let pid = new_process(test_proc.entry_point(), space).expect("Failed to create process");
dbg!();
let client = dev_driver_rpc::Client::new(pid); let client = dev_driver_rpc::Client::new(pid);
dbg!();
let fd = client.open("sdb").unwrap(); let fd = client.open("sdb").unwrap();
dbg!();
let sdb = File::from_pid_fd(pid, fd); let sdb = File::from_pid_fd(pid, fd);
dbg!();
let fs = Ext2::new(sdb).unwrap(); let fs = Ext2::new(sdb).unwrap();
// dbg!(); dbg!();
print_all_files("/", &fs); print_all_files("/", &fs);
dbg!();
}); });
fn print_all_files<P: AsRef<Path> + Debug>(path: P, fs: &Ext2) { fn print_all_files<P: AsRef<Path> + Debug>(path: P, fs: &Ext2) {
// dbg!();
for entry in fs.read_dir(path).unwrap() { for entry in fs.read_dir(path).unwrap() {
// dbg!();
let entry = entry.unwrap(); let entry = entry.unwrap();
if entry.metadata().file_type().is_dir() { println!("{:?}", entry.path());
print_all_files(entry.path(), fs); // if entry.metadata().file_type().is_dir() {
} else { // // print_all_files(entry.path(), fs);
// dbg!(); // } else {
let mut file = fs.open(entry.path()).unwrap(); // // let mut file = fs.open(entry.path()).unwrap();
// dbg!(); // // let mut buf = String::new();
let mut buf = String::new(); // // file.read_to_string(&mut buf).unwrap();
file.read_to_string(&mut buf).unwrap(); // // print!("{:?}:\n{}", entry.path(), buf);
print!("{:?}:\n{}", entry.path(), buf); // }
}
} }
} }

View File

@ -1,14 +0,0 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"features": "-mmx,-sse,+soft-float"
}