mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-04 00:21:57 +00:00
Added AddrSignedLo and AddrSignedHi label functions.
This commit is contained in:
parent
c10b9b0b5f
commit
64c7d09b4b
@ -10,6 +10,7 @@ pub use line::{Line, LineArg, LineArgExpr, LineLabelFunc};
|
||||
|
||||
// Imports
|
||||
use crate::Pos;
|
||||
use int_conv::{Signed, Split};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
/// Instruction parsing
|
||||
@ -63,10 +64,22 @@ pub trait ParseCtx {
|
||||
// Converts a value into a position
|
||||
let to_pos = |value: i64| value.try_into().map(Pos).map_err(|_| ParseError::LiteralOutOfRange);
|
||||
|
||||
// Returns the signed lo-hi values of a position
|
||||
let signed_addr_lo_hi = |addr: Pos| -> (i16, u16) {
|
||||
let (lo, hi) = match addr.0.lo().as_signed() < 0 {
|
||||
true => (addr.0.lo(), addr.0.hi().wrapping_add(1)),
|
||||
false => addr.0.lo_hi(),
|
||||
};
|
||||
|
||||
(lo.as_signed(), hi)
|
||||
};
|
||||
|
||||
let value = match func {
|
||||
// For address, first get the value as a position to make sure it's within range
|
||||
LineLabelFunc::AddrLo => i64::from(to_pos(value)?.0 & 0xFFFF),
|
||||
LineLabelFunc::AddrHi => i64::from(to_pos(value)?.0 >> 16u32),
|
||||
LineLabelFunc::AddrSignedLo => i64::from(signed_addr_lo_hi(to_pos(value)?).0),
|
||||
LineLabelFunc::AddrSignedHi => i64::from(signed_addr_lo_hi(to_pos(value)?).1),
|
||||
};
|
||||
|
||||
Ok(value)
|
||||
|
||||
@ -165,13 +165,20 @@ pub enum LineArgExpr {
|
||||
}
|
||||
|
||||
/// Line label functions
|
||||
#[allow(clippy::pub_enum_variant_names)] // We'll have other functions eventually
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub enum LineLabelFunc {
|
||||
/// Lower 16 bits of address
|
||||
/// Address lower 16-bits
|
||||
AddrLo,
|
||||
|
||||
/// Higher 16 bits of address
|
||||
/// Address higher 16-bits
|
||||
AddrHi,
|
||||
|
||||
/// Address lower signed 16-bits
|
||||
AddrSignedLo,
|
||||
|
||||
/// Address higher signed 16-bits
|
||||
AddrSignedHi,
|
||||
}
|
||||
|
||||
/// Reads a name
|
||||
@ -306,9 +313,12 @@ fn read_reg(s: &str) -> Result<(Register, &str), ReadArgError> {
|
||||
}
|
||||
|
||||
/// Reads a func
|
||||
#[rustfmt::skip]
|
||||
fn read_func(s: &str) -> Result<(LineLabelFunc, &str), ReadFuncError> {
|
||||
None.or_else(|| s.strip_prefix("addr_hi").map(|rest| (LineLabelFunc::AddrHi, rest)))
|
||||
.or_else(|| s.strip_prefix("addr_lo").map(|rest| (LineLabelFunc::AddrLo, rest)))
|
||||
None.or_else(|| s.strip_prefix("addr_hi" ).map(|rest| (LineLabelFunc::AddrHi , rest)))
|
||||
.or_else(|| s.strip_prefix("addr_lo" ).map(|rest| (LineLabelFunc::AddrLo , rest)))
|
||||
.or_else(|| s.strip_prefix("signed_addr_hi").map(|rest| (LineLabelFunc::AddrSignedHi, rest)))
|
||||
.or_else(|| s.strip_prefix("signed_addr_lo").map(|rest| (LineLabelFunc::AddrSignedLo, rest)))
|
||||
.ok_or(ReadFuncError::Unknown)
|
||||
}
|
||||
|
||||
|
||||
@ -183,3 +183,7 @@
|
||||
pos: 0x80077adc
|
||||
ty: u32
|
||||
kind: Known
|
||||
- name: unknown6
|
||||
pos: 0x80077ad8
|
||||
ty: u32
|
||||
kind: Known
|
||||
|
||||
@ -274,6 +274,11 @@
|
||||
- name: something10
|
||||
start_pos: 0x800141b8
|
||||
end_pos: 0x800142d0
|
||||
labels:
|
||||
0x800141ec: "0"
|
||||
0x80014268: "1"
|
||||
0x800142a4: "2"
|
||||
0x800142c0: "3"
|
||||
|
||||
- name: something11
|
||||
start_pos: 0x800142d0
|
||||
@ -387,6 +392,10 @@
|
||||
start_pos: 0x8001f8b0
|
||||
end_pos: 0x8001f94c
|
||||
|
||||
- name: something39
|
||||
start_pos: 0x8005aa7c
|
||||
end_pos: 0x8005ab4c
|
||||
|
||||
# A functions
|
||||
- name: InitHeap
|
||||
signature: "fn(addr: *u32, size: u32)"
|
||||
|
||||
@ -118,3 +118,93 @@
|
||||
? pos: 0x80014080
|
||||
arg: 1
|
||||
: "unknown5@addr_lo"
|
||||
|
||||
? pos: 0x80014088
|
||||
arg: 1
|
||||
: "unknown2@addr_hi"
|
||||
? pos: 0x8001408c
|
||||
arg: 2
|
||||
: "unknown2@addr_lo"
|
||||
|
||||
? pos: 0x800140b0
|
||||
arg: 1
|
||||
: "unknown3@addr_hi"
|
||||
? pos: 0x800140b4
|
||||
arg: 2
|
||||
: "unknown3@addr_lo"
|
||||
? pos: 0x800140bc
|
||||
arg: 1
|
||||
: "unknown3@addr_lo"
|
||||
|
||||
? pos: 0x80014184
|
||||
arg: 1
|
||||
: "unknown6@addr_hi"
|
||||
? pos: 0x8001418c
|
||||
arg: 1
|
||||
: "unknown6@addr_lo"
|
||||
|
||||
? pos: 0x800141c4
|
||||
arg: 1
|
||||
: "something11_data5@addr_hi"
|
||||
? pos: 0x800141c8
|
||||
arg: 1
|
||||
: "something11_data5@addr_lo"
|
||||
|
||||
? pos: 0x80014218
|
||||
arg: 1
|
||||
: "something11_data1@addr_hi"
|
||||
? pos: 0x80014228
|
||||
arg: 1
|
||||
: "something11_data1@addr_lo"
|
||||
|
||||
? pos: 0x80014234
|
||||
arg: 1
|
||||
: "something11_data4@addr_hi"
|
||||
? pos: 0x80014268
|
||||
arg: 1
|
||||
: "something11_data4@addr_lo"
|
||||
|
||||
? pos: 0x8001424c
|
||||
arg: 1
|
||||
: "something11_data2@addr_hi"
|
||||
? pos: 0x80014258
|
||||
arg: 1
|
||||
: "something11_data2@addr_lo"
|
||||
|
||||
? pos: 0x8001425c
|
||||
arg: 1
|
||||
: "something11_data3@addr_hi"
|
||||
? pos: 0x80014264
|
||||
arg: 1
|
||||
: "something11_data3@addr_lo"
|
||||
|
||||
? pos: 0x8001426c
|
||||
arg: 1
|
||||
: "unknown3@addr_hi"
|
||||
? pos: 0x80014270
|
||||
arg: 2
|
||||
: "unknown3@addr_lo"
|
||||
? pos: 0x80014280
|
||||
arg: 1
|
||||
: "unknown3@addr_lo"
|
||||
|
||||
? pos: 0x80014274
|
||||
arg: 1
|
||||
: "something11_data5@addr_hi"
|
||||
? pos: 0x80014278
|
||||
arg: 1
|
||||
: "something11_data5@addr_lo"
|
||||
|
||||
? pos: 0x8001427c
|
||||
arg: 1
|
||||
: "something11_data6@addr_hi"
|
||||
? pos: 0x80014288
|
||||
arg: 1
|
||||
: "something11_data6@addr_lo"
|
||||
|
||||
? pos: 0x8005a88c
|
||||
arg: 1
|
||||
: "something39@signed_addr_hi"
|
||||
? pos: 0x8005a894
|
||||
arg: 1
|
||||
: "something39@signed_addr_lo"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user