<commit_before>// "Tifflin" Kernel
// - By <NAME> (thePowersGang)
//
// arch/amd64/crate.rs
// - AMD64/x86_64 architecture support
use core::option::Option;

pub use self::log::{puts, puth};

module_define!{arch, [APIC, HPET], init}

pub mod interrupts;
#[doc(hidden)]
pub mod cpu_faults;
pub mod memory;
pub mod threads;
pub mod boot;
pub mod sync;

mod tss;

mod log;
pub mod x86_io;
pub mod hw;
pub mod acpi;
pub mod pci;

extern "C"
{
	static v_kernel_end : ::Void;
}

fn init()
{
	// None needed, just dependencies
}

#[inline(always)]
pub fn checkmark() {
	// SAFE: nop ASM
	unsafe { asm!("xchg %bx, %bx" : : : "memory" : "volatile"); }
}
#[inline(always)]
pub fn checkmark_val<T>(v: *const T) {
	// SAFE: nop ASM (TODO: Ensure)
	unsafe { asm!("xchg %bx, %bx; mov $0,$0" : : "r"(v) : "memory" : "volatile"); }
}

#[allow(improper_ctypes)]
extern "C" {
	pub fn drop_to_user(entry: usize, stack: usize, cmdline_len: usize) -> !;
}

/// Return the system timestamp (miliseconds since an arbitary point)
pub fn cur_timestamp() -> u64
{
	hw::hpet::get_timestamp()
}

/// Print a backtrace, starting at the current location.
pub fn print_backtrace()
{
	let cur_bp: u64;
	// SAFE: Reads from bp
	unsafe{ asm!("mov %rbp, $0" : "=r" (cur_bp)); }
	puts("Backtrace: ");
	puth(cur_bp);
	
	let mut bp = cur_bp;
	while let Option::Some((newbp, ip)) = cpu_faults::backtrace(bp)
	{
		puts(" > ");
		puth(ip);
		if let Some( (name, ofs) ) = ::symbols::get_symbol_for_addr(ip as usize - 1) {
			puts("(");
			puts(name);
			puts("+");
			puth(ofs as u64 + 1);
			puts(")");
		}
		bp = newbp;
	}
	puts("\n");
}

// vim: ft=rust
<commit_msg>Kernel/AMD64 - Demangled and symbol-annoated backtrace<commit_after>// "Tifflin" Kernel
// - By <NAME> (thePowersGang)
//
// arch/amd64/crate.rs
// - AMD64/x86_64 architecture support
use core::option::Option;

pub use self::log::{puts, puth};

module_define!{arch, [APIC, HPET], init}

pub mod interrupts;
#[doc(hidden)]
pub mod cpu_faults;
pub mod memory;
pub mod threads;
pub mod boot;
pub mod sync;

mod tss;

mod log;
pub mod x86_io;
pub mod hw;
pub mod acpi;
pub mod pci;

extern "C"
{
	static v_kernel_end : ::Void;
}

fn init()
{
	// None needed, just dependencies
}

#[inline(always)]
pub fn checkmark() {
	// SAFE: nop ASM
	unsafe { asm!("xchg %bx, %bx" : : : "memory" : "volatile"); }
}
#[inline(always)]
pub fn checkmark_val<T>(v: *const T) {
	// SAFE: nop ASM (TODO: Ensure)
	unsafe { asm!("xchg %bx, %bx; mov $0,$0" : : "r"(v) : "memory" : "volatile"); }
}

#[allow(improper_ctypes)]
extern "C" {
	pub fn drop_to_user(entry: usize, stack: usize, cmdline_len: usize) -> !;
}

/// Return the system timestamp (miliseconds since an arbitary point)
pub fn cur_timestamp() -> u64
{
	hw::hpet::get_timestamp()
}

/// Print a backtrace, starting at the current location.
pub fn print_backtrace()
{
	let cur_bp: u64;
	// SAFE: Reads from bp
	unsafe{ asm!("mov %rbp, $0" : "=r" (cur_bp)); }
	log_notice!("Backtrace: {}", Backtrace(cur_bp as usize));
}
pub struct Backtrace(usize);
impl ::core::fmt::Display for Backtrace {
	fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
		let mut bp = self.0 as u64;
		while let Option::Some((newbp, ip)) = cpu_faults::backtrace(bp)
		{
			try!(write!(f, " > {:#x}", ip));
			if let Some( (name, ofs) ) = ::symbols::get_symbol_for_addr(ip as usize - 1) {
				try!(write!(f, "({}+{:#x})", ::symbols::Demangle(name), ofs + 1));
			}
			bp = newbp;
		}
		Ok( () )
	}
}

// vim: ft=rust

{'fraction_non_alphanumeric': 0.19176504463000288, 'fraction_numerical': 0.01295709761013533, 'mean_word_length': 3.9699570815450644, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2825591', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1451, 'n_words': 385}