Skip to content

Commit fc29a87

Browse files
committed
Added prefixes
1 parent 5fea5f6 commit fc29a87

File tree

7 files changed

+4758
-4688
lines changed

7 files changed

+4758
-4688
lines changed

workspace/assembler/src/mk2/InstructionStream.rs

Lines changed: 4675 additions & 4675 deletions
Large diffs are not rendered by default.

workspace/assembler/src/mk2/OrdinaryInstructionStream.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ pub struct OrdinaryInstructionStream
99

1010
impl OrdinaryInstructionStream
1111
{
12+
#[inline(always)]
13+
fn prefix_fwait(&mut self, byte: u8)
14+
{
15+
self.byte_emitter.emit_u8(byte)
16+
}
17+
18+
#[inline(always)]
19+
fn prefix_group1(&mut self, byte: u8)
20+
{
21+
self.byte_emitter.emit_u8(byte)
22+
}
23+
24+
#[inline(always)]
25+
fn prefix_group2(&mut self, memory_operand_or_branch_hint: MemoryOperandOrBranchHint)
26+
{
27+
memory_operand_or_branch_hint.emit_prefix_group2(&mut self.byte_emitter)
28+
}
29+
30+
#[inline(always)]
31+
fn prefix_group3(&mut self)
32+
{
33+
self.byte_emitter.emit_u8(0x66)
34+
}
35+
36+
#[inline(always)]
37+
fn prefix_group4(&mut self, memory_operand: MemoryOperand)
38+
{
39+
memory_operand.emit_prefix_group4()
40+
}
41+
42+
1243
#[inline(always)]
1344
fn opcode_1(&mut self, opcode: u8)
1445
{
@@ -50,6 +81,9 @@ impl OrdinaryInstructionStream
5081
self.displacement_immediate_1(displacement1);
5182
}
5283

84+
/** A symbolic representation of a Rel32. No Rel8 equivalent is provided. */
85+
//Label
86+
5387
/// Records internal state for a label reference.
5488
/// Saves the current code position and reserves space for the resolved address by emitting zero bytes.
5589
#[inline(always)]
@@ -74,15 +108,11 @@ impl OrdinaryInstructionStream
74108
/*
75109
impl OrdinaryInstructionStream
76110
{
77-
self.pref_fwait(0x9B);
78-
79111
self.pref_group2(&mut self, arg0);
80112
81113
self.pref_group4(&mut self, arg0);
82114
83115
self.pref_group3();
84-
85-
self.pref_group1(0xF2);
86116
87117
rex!(self, arg1, arg0, 0x00);
88118
/*

workspace/assembler/src/mk2/Types.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55

66

77

8-
/** A symbolic representation of a Rel32. No Rel8 equivalent is provided. */
9-
Label
108

workspace/assembler/src/mk2/mnemonic_parameter_types/Hint.rs renamed to workspace/assembler/src/mk2/mnemonic_parameter_types/BranchHint.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
/// Represents a hint.
66
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
77
#[repr(u8)]
8-
pub enum Hint
8+
pub enum BranchHint
99
{
1010
/// Hint taken.
11-
Taken = 0,
11+
Taken = 0x3E,
1212

1313
/// Hint not taken.
14-
NotTaken = 1,
14+
NotTaken = 0x2E,
1515
}
1616

17-
impl Default for Hint
17+
impl MemoryOperandOrBranchHint for BranchHint
1818
{
1919
#[inline(always)]
20-
fn default() -> Self
20+
fn emit_prefix_group2(self, byte_emitter: &mut ByteEmitter)
2121
{
22-
X87Register::ST1
22+
byte_emitter.emit_u8(self as u8)
2323
}
2424
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is part of assembler. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/assembler/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2+
// Copyright © 2017 The developers of assembler. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/assembler/master/COPYRIGHT.
3+
4+
5+
/// Memory operand or branch hint.
6+
pub trait MemoryOperandOrBranchHint
7+
{
8+
#[inline(always)]
9+
fn emit_prefix_group2(self, byte_emitter: &mut ByteEmitter);
10+
}

workspace/assembler/src/mk2/mnemonic_parameter_types/memory_operands/MemoryOperand.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ impl MemoryOperand
6969
}
7070
}
7171

72+
impl MemoryOperandOrBranchHint for BranchHint
73+
{
74+
#[inline(always)]
75+
fn emit_prefix_group2(self, byte_emitter: &mut ByteEmitter)
76+
{
77+
if self.has_segment_register()
78+
{
79+
let segment_register_byte = match self.segment_register_index()
80+
{
81+
0 => 0x26,
82+
1 => 0x2E,
83+
2 => 0x36,
84+
3 => 0x3E,
85+
4 => 0x64,
86+
5 => 0x65,
87+
_ => unreachable!(),
88+
};
89+
byte_emitter.emit_u8(segment_register_byte)
90+
}
91+
}
92+
}
93+
7294
impl MemoryOrRegister for MemoryOperand
7395
{
7496
#[inline(always)]
@@ -203,6 +225,15 @@ impl MemoryOperand
203225

204226
const NullSegmentRegister: u64 = 0x07;
205227

228+
#[inline(always)]
229+
pub(crate) fn emit_prefix_group4(self, byte_emitter: &mut ByteEmitter)
230+
{
231+
if self.has_address_override_for_32_bit()
232+
{
233+
byte_emitter.emit_u8(0x67)
234+
}
235+
}
236+
206237
#[inline(always)]
207238
pub fn new(displacement: Immediate32Bit, base: Option<impl GeneralPurposeRegister>, index: Option<impl GeneralPurposeRegister>, scale: IndexScale, segment_register: Option<impl AnySegmentRegister>, address_override_for_32_bit: bool, relative_instruction_pointer_offset: bool) -> Self
208239
{

workspace/assembler/src/mk2/mnemonic_parameter_types/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod singletons;
3434

3535

3636
include!("AsDisplacement.rs");
37-
include!("Hint.rs");
37+
include!("BranchHint.rs");
38+
include!("MemoryOperandOrBranchHint.rs");
3839
include!("MemoryOrRegister.rs");
3940
include!("ToOpcode.rs");

0 commit comments

Comments
 (0)