Skip to content
Permalink
Browse files

Implemented some math ops

  • Loading branch information...
charlesbetros committed Apr 16, 2019
1 parent 26a7e2e commit bea0ab2d44a8dc5aebf430f0ff1a0bf306a090dc
@@ -87,6 +87,7 @@ DebugStub_SetINT1_TrapFLAG:
; - The interrupt frame - 8 for correct byte = ESP + 12 - 8 = ESP + 4
; - Therefore, ESP - 4 to get to the correct position
; EBP -= 4
Sub EBP, 0x4
; EAX = [EBP]
Mov EAX, DWORD [EBP]
; EAX | $0100
@@ -117,6 +118,7 @@ DebugStub_ResetINT1_TrapFLAG:
; Clear the Trap Flag (http://en.wikipedia.org/wiki/Trap_flag)
; See comment in SetINT1_TrapFlag
; EBP -= 4
Sub EBP, 0x4
; EAX = [EBP]
Mov EAX, DWORD [EBP]
; EAX & $FEFF
@@ -42,6 +42,7 @@ DebugStub_SendFrame:
Mov ESI, DWORD [DebugStub_CallerEBP]
; Dont transmit EIP or old EBP
; ESI += 8
Add ESI, 0x8
; ECX = 32
Mov ECX, 0x20
; ComWriteX()
@@ -103,6 +104,7 @@ DebugStub_SendStack:
; EAX = .CallerEBP
Mov EAX, DWORD [DebugStub_CallerEBP]
; EAX -= ESI
Sub EAX, ESI
; ComWriteAX()
Call DebugStub_ComWriteAX

@@ -138,6 +140,7 @@ DebugStub_SendMethodContext:
; ComReadEAX()
Call DebugStub_ComReadEAX
; ESI += EAX
Add ESI, EAX
; ComReadEAX()
Call DebugStub_ComReadEAX
; ECX = EAX
@@ -242,6 +245,7 @@ Mov EBP, ESP
; ESI = EBP
Mov ESI, EBP
; ESI += 12
Add ESI, 0xC
; ECX = [ESI]
Mov ECX, DWORD [ESI]
; ComWrite16()
@@ -542,6 +546,7 @@ DebugStub_SendMessageBox:
; ESI = EBP
Mov ESI, EBP
; ESI += 12
Add ESI, 0xC
; ECX = [ESI]
Mov ECX, DWORD [ESI]
; ComWrite16()
@@ -596,9 +601,11 @@ DebugStub_SendCoreDump:
Mov EAX, EBP
; while EAX != 0 {
; EAX -= 4
Sub EAX, 0x4
; +EAX
Push EAX
; ECX += 4
Add ECX, 0x4
; EAX = [EAX]
Mov EAX, DWORD [EAX]
; }
@@ -61,6 +61,7 @@ DebugStub_BreakOnAddress:
Mov EBX, DebugStub_DebugBPs
; EAX << 2
; EBX += EAX
Add EBX, EAX

; if ECX = 0 {
; This is a BP removal
@@ -112,6 +113,7 @@ DebugStub_FindBPLoop:
; 4 bytes per Id
; EAX << 2
; EBX += EAX
Add EBX, EAX

; Set EAX to be the value at the address stored by EAX
; I.e. the ASM address of the BP with BP Id of ECX (if there is one - it will be 0 if no BP at this BP Id)
@@ -39,6 +39,7 @@ DebugStub_DisplayWaitMsg:
Mov EDI, DebugStub_Const_VidBase
; 10 lines down, 20 cols in (10 * 80 + 20) * 2)
; EDI += 1640
Add EDI, 0x668

; Read and copy string till 0 terminator
; while byte [ESI] != 0 {
@@ -49,6 +50,7 @@ DebugStub_DisplayWaitMsg:
; ESI++
Inc ESI
; EDI += 2
Add EDI, 0x2
; }
; }

@@ -22,6 +22,7 @@ DebugStub_ComRead8:
; [EDI] = AL
Mov BYTE [EDI], AL
; EDI += 1
Add EDI, 0x1
; }
; function ComRead16 {
DebugStub_ComRead16:
@@ -24,6 +24,7 @@ DebugStub_WriteRegister:
; +EDX
Push EDX
; DX += $03F8
Add DX, 0x3F8
; Port[DX] = AL
Out DX, AL
; -EDX
@@ -40,6 +41,7 @@ DebugStub_ReadRegister:
; +EDX
Push EDX
; DX += $03F8
Add DX, 0x3F8
; AL = Port[DX]
In AL, DX
; -EDX
@@ -38,12 +38,14 @@ Mov DWORD [DebugStub_CallerEBP], EBP
; EBP = ESP
Mov EBP, ESP
; EBP += 32
Add EBP, 0x20
; Caller EIP
; EAX = [EBP]
Mov EAX, DWORD [EBP]

; 12 bytes for EFLAGS, CS, EIP
; EBP += 12
Add EBP, 0xC
; .CallerESP = EBP
Mov DWORD [DebugStub_CallerESP], EBP

@@ -7,9 +7,11 @@ DebugStub_CheckStack:
; after a call, the stack gets pushed to, so add 4 to the expected difference
; eax += 4
Add EAX, 0x4
; EBX = EBP
Mov EBX, EBP
; EBX += EAX
Add EBX, EAX

; if EBX != ESP {
; stack corruption.
@@ -15,6 +15,13 @@ public NASM(TextWriter aOut)

// Add in alphabetical order from here

Add(OpCode.Add, "{0}, {1}", typeof(Reg08), typeof(Reg08));
Add(OpCode.Add, "{0}, {1}", typeof(Reg16), typeof(Reg16));
Add(OpCode.Add, "{0}, {1}", typeof(Reg32), typeof(Reg32));
Add(OpCode.Add, "{0}, 0x{1:X}", typeof(Reg08), typeof(i08u));
Add(OpCode.Add, "{0}, 0x{1:X}", typeof(Reg16), typeof(i16u));
Add(OpCode.Add, "{0}, 0x{1:X}", typeof(Reg32), typeof(i32u));

Add(OpCode.Dec, "{0}", typeof(Reg08));
Add(OpCode.Dec, "{0}", typeof(Reg16));
Add(OpCode.Dec, "{0}", typeof(Reg32));
@@ -56,6 +63,13 @@ public NASM(TextWriter aOut)
Add(OpCode.Mov, "{0}, {1}", typeof(Reg16), typeof(Identifier));
Add(OpCode.Mov, "{0}, {1}", typeof(Reg32), typeof(Identifier));

Add(OpCode.Mul, "{0}, {1}", typeof(Reg08), typeof(Reg08));
Add(OpCode.Mul, "{0}, {1}", typeof(Reg16), typeof(Reg16));
Add(OpCode.Mul, "{0}, {1}", typeof(Reg32), typeof(Reg32));
Add(OpCode.Mul, "{0}, 0x{1:X}", typeof(Reg08), typeof(i08u));
Add(OpCode.Mul, "{0}, 0x{1:X}", typeof(Reg16), typeof(i16u));
Add(OpCode.Mul, "{0}, 0x{1:X}", typeof(Reg32), typeof(i32u));

Add(OpCode.NOP);

Add(OpCode.Out, "{0}, {1}", typeof(Reg16), typeof(Reg08));
@@ -88,8 +102,23 @@ public NASM(TextWriter aOut)
Add(OpCode.Pop, "{0}", typeof(RegisterAddress));

Add(OpCode.PopAD);

Add(OpCode.Rem, "{0}, {1}", typeof(Reg08), typeof(Reg08));
Add(OpCode.Rem, "{0}, {1}", typeof(Reg16), typeof(Reg16));
Add(OpCode.Rem, "{0}, {1}", typeof(Reg32), typeof(Reg32));
Add(OpCode.Rem, "{0}, 0x{1:X}", typeof(Reg08), typeof(i08u));
Add(OpCode.Rem, "{0}, 0x{1:X}", typeof(Reg16), typeof(i16u));
Add(OpCode.Rem, "{0}, 0x{1:X}", typeof(Reg32), typeof(i32u));

Add(OpCode.Ret);

Add(OpCode.Sub, "{0}, {1}", typeof(Reg08), typeof(Reg08));
Add(OpCode.Sub, "{0}, {1}", typeof(Reg16), typeof(Reg16));
Add(OpCode.Sub, "{0}, {1}", typeof(Reg32), typeof(Reg32));
Add(OpCode.Sub, "{0}, 0x{1:X}", typeof(Reg08), typeof(i08u));
Add(OpCode.Sub, "{0}, 0x{1:X}", typeof(Reg16), typeof(i16u));
Add(OpCode.Sub, "{0}, 0x{1:X}", typeof(Reg32), typeof(i32u));

Add(OpCode.Test, "{0}, 0x{1:X}", typeof(Reg08), typeof(i08u));
Add(OpCode.Test, "{0}, 0x{1:X}", typeof(Reg16), typeof(i16u));
Add(OpCode.Test, "{0}, 0x{1:X}", typeof(Reg32), typeof(i32u));
@@ -23,17 +23,22 @@
// Please add ops in alphabetical order
public enum OpCode
{
Dec, // Decrement operator
Add, // Add
Dec, // Decrement
Div, // Divide
In, // In Oprator
Inc, // Increment operator
Mov, // Move operator
Inc, // Increment
Mov, // Move
Mul, // Multiply
NOP, // No op
Out, // Out
Pop, // Pop
PopAD, // Pop all
Push, // Push
PushAD, // Push all
Rem, // Remainder
Ret, // Return
Sub, // Subtract
Test, // Test - logical compare
}
}
@@ -50,6 +50,7 @@ public Compiler(TextWriter aOut)
mTokenMap.AddEmitter(new Emitters.PushPop(this, mNASM)); // This should be above + operator
mTokenMap.AddEmitter(new Emitters.Assignments(this, mNASM));
mTokenMap.AddEmitter(new Emitters.Test(this, mNASM));
mTokenMap.AddEmitter(new Emitters.Math(this, mNASM));
mTokenMap.AddEmitter(new Emitters.AllEmitters(this, mNASM));
}

@@ -119,20 +119,6 @@ protected void VariableArrayDefinition(string aVarKeyword, string aVariableName,
{
}

[Emitter(typeof(Reg), typeof(OpMath), typeof(Const))]
[Emitter(typeof(Reg), typeof(OpMath), typeof(Variable))]
[Emitter(typeof(Reg08), typeof(OpMath), typeof(Int08u))]
[Emitter(typeof(Reg16), typeof(OpMath), typeof(Int16u))]
[Emitter(typeof(Reg32), typeof(OpMath), typeof(Int32u))]
protected void Arithmetic(Register aRegister, string aOpArithmetic, object aValue)
{
}

[Emitter(typeof(Reg), typeof(OpMath), typeof(Reg))]
protected void ArithmeticRegReg(Register aRegister, string aOpArithmetic, object aValue)
{
}

[Emitter(typeof(Reg), typeof(OpBitwise), typeof(Const))]
[Emitter(typeof(Reg), typeof(OpBitwise), typeof(Variable))]
[Emitter(typeof(Reg08), typeof(OpBitwise), typeof(Reg08))]
Oops, something went wrong.

0 comments on commit bea0ab2

Please sign in to comment.
You can’t perform that action at this time.