use super::bytes_of as of;
use crate::{
error::Result,
reloc::{Arch, Check, Field, RelExpr, Spec, Write, WriteKind},
};
pub const IMAGE_REL_I386_ABSOLUTE: u32 = 0x0000;
pub const IMAGE_REL_I386_DIR16: u32 = 0x0001;
pub const IMAGE_REL_I386_REL16: u32 = 0x0002;
pub const IMAGE_REL_I386_DIR32: u32 = 0x0006;
pub const IMAGE_REL_I386_DIR32NB: u32 = 0x0007;
pub const IMAGE_REL_I386_SECTION: u32 = 0x000A;
pub const IMAGE_REL_I386_SECREL: u32 = 0x000B;
pub const IMAGE_REL_I386_TOKEN: u32 = 0x000C;
pub const IMAGE_REL_I386_SECREL7: u32 = 0x000D;
pub const IMAGE_REL_I386_REL32: u32 = 0x0014;
pub struct CoffI386;
impl Arch for CoffI386 {
fn spec(r_type: u32) -> Result<Spec> {
Ok(match r_type {
IMAGE_REL_I386_ABSOLUTE => of(RelExpr::None, WriteKind::W32),
IMAGE_REL_I386_DIR16 => of(RelExpr::Abs, WriteKind::W16),
IMAGE_REL_I386_REL16 => of(RelExpr::Pc, WriteKind::W16),
IMAGE_REL_I386_DIR32 => of(RelExpr::Abs, WriteKind::W32),
IMAGE_REL_I386_REL32 => of(RelExpr::Pc, WriteKind::W32S),
IMAGE_REL_I386_DIR32NB
| IMAGE_REL_I386_SECREL
| IMAGE_REL_I386_TOKEN => of(RelExpr::Escape, WriteKind::W32),
IMAGE_REL_I386_SECTION => of(RelExpr::Escape, WriteKind::W16),
IMAGE_REL_I386_SECREL7 => Spec {
expr: RelExpr::Escape,
write: Write::Field(Field::new(1, 0, 0, 7, Check::None)),
},
other => return Err(crate::error::Error::UnsupportedReloc(other)),
})
}
}