upload koldbg by CandyMan

git-svn-id: svn://kolibrios.org@9353 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2021-12-02 17:13:25 +00:00
parent 542bdad9e0
commit b34f9856cb
44 changed files with 55650 additions and 0 deletions

View File

@ -0,0 +1,2 @@
if tup.getconfig("NO_FASM") ~= "" then return end
tup.rule({"koldbg.asm"}, "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "koldbg")

View File

@ -0,0 +1,50 @@
;-----------------------------------------------------------------------------
; Assemble instruction event
OnAsm: mov esi,[CurArg]
mov edi,esi
mov ecx,255
xor eax,eax
repnz scasb
stc
sbb edi,esi
jz .Exit
;
mov eax,[CPUYPos]
mov rax,[AddrBuffer+(rax-1)*sizeof.dq]
mov [OriginPtr],rax
mov al,[CodeType]
mov [code_type],al
;
call Assemble
or esi,esi
jz .Move
;
if 1
mov ecx,MSG_WIDTH-1
mov edi,ErrorLine
push rdi
.Loop: lodsb
stosb
or al,al
loopnz .Loop
mov [rdi-1],word 10
pop rsi
and byte [rsi],0xDF
end if
;
call PutMessageNoDraw
jmp .Exit
.Move: mov eax,[CPUYPos]
mov rsi,[AddrBuffer+(rax-1)*sizeof.dq]
lea edi,[output_data]
mcall 69,7,[DebuggeePID],[output_size]
.Exit: call PrintCmdLine
mov [AfterKey],1
call ShowImage
ret
;-----------------------------------------------------------------------------
uglobal
if used ErrorLine
ErrorLine rb MSG_WIDTH
end if
endg

View File

@ -0,0 +1,564 @@
InitCmdHistBuffer:
;-------------------------------------------------------------------------------
push eax ebx ecx
mcall 68,12,4096 ;allocate 4KB block
mov [CmdHistBuffer.Ptr],eax
mov [CmdHistBuffer.Size],ecx
mov edi,eax
xor eax,eax
stosd
stosd
mov [CmdHistBuffer.NewNodeOffset],eax
mov [CmdHistBuffer.LastNodeOffset],eax
mov [CmdHistBuffer.CurNodeOffset],eax
mov [CmdHistBuffer.TmpLineFlag],al
mov [CmdHistBuffer.NFlag],al
pop ecx ebx eax
ret
;-------------------------------------------------------------------------------
EnlargeCmdHistBuffer:
;-------------------------------------------------------------------------------
pusha
mov ecx,[CmdHistBuffer.Size]
add ecx,4096
mov edx,[CmdHistBuffer.Ptr]
mcall 68,20 ;reallocate the buffer (prev. size + 4KB)
test eax,eax
jz .Err
mov [CmdHistBuffer.Ptr],eax
mov [CmdHistBuffer.Size],ecx
.OK:
clc
popa
ret
.Err:
stc
popa
ret
;-------------------------------------------------------------------------------
AddCmdHistLine:
;-------------------------------------------------------------------------------
;in:
;eax = ptr to ASCIIZ string of line
;-------------------------------------------------------------------------------
pusha
mov esi,eax
mov edx,eax
xor ecx,ecx
@@:
inc ecx
lodsb
test al,al
jz @F
jmp @B
@@:
dec ecx
jz .OK
inc ecx
mov eax,[CmdHistBuffer.NewNodeOffset]
lea eax,[eax+ecx+2*4]
cmp [CmdHistBuffer.Size],eax
jae @F
call EnlargeCmdHistBuffer
jc .Err
@@:
mov edi,[CmdHistBuffer.NewNodeOffset]
mov eax,[CmdHistBuffer.Ptr]
add edi,eax
cmp eax,edi ;if eax = edi, then it's the first node
jne @F
xor eax,eax
dec eax
stosd ;save previous node link = -1 for the first node
stosd ;save next node link = -1 for the first node
jmp .CPStr
@@:
mov ebx,[CmdHistBuffer.LastNodeOffset]
mov [edi],ebx ;save previous node link for a new node
add ebx,eax
mov eax,[CmdHistBuffer.NewNodeOffset]
mov [ebx+4],eax ;update next node link for a last node
mov [CmdHistBuffer.LastNodeOffset],eax
mov [CmdHistBuffer.CurNodeOffset],eax
add edi,4
xor eax,eax
dec eax
stosd
.CPStr:
mov esi,edx
push ecx
rep movsb
pop ecx
add ecx,2*4
add [CmdHistBuffer.NewNodeOffset],ecx
.OK:
clc
.Err:
mov [CmdHistBuffer.TmpLineFlag],0
popa
ret
;-------------------------------------------------------------------------------
AddCmdHistTmpLine:
;-------------------------------------------------------------------------------
;in:
;eax = ptr to ASCIIZ string of line
;-------------------------------------------------------------------------------
pusha
mov esi,eax
mov edx,eax
xor ecx,ecx
@@:
inc ecx
lodsb
test al,al
jz @F
jmp @b
@@:
mov eax,[CmdHistBuffer.NewNodeOffset]
lea eax,[eax+ecx+2*4]
cmp [CmdHistBuffer.Size],eax
jae @F
call EnlargeCmdHistBuffer
jc .Err
@@:
mov edi,[CmdHistBuffer.NewNodeOffset]
mov [CmdHistBuffer.TmpLineFlag],1
mov eax,[CmdHistBuffer.Ptr]
add edi,eax
xor eax,eax
stosd
stosd ;two zeroes - marker (prefix) of tmp line
.CPStr:
mov esi,edx
rep movsb
.OK:
clc
.Err:
popa
ret
;-------------------------------------------------------------------------------
GetCmdHistLine:
;-------------------------------------------------------------------------------
;out:
;eax = ptr to ASCIIZ string of current line
;-------------------------------------------------------------------------------
push ebx
mov eax,[CmdHistBuffer.Ptr]
mov ebx,[CmdHistBuffer.CurNodeOffset]
lea eax,[eax+ebx+2*4]
pop ebx
ret
;-------------------------------------------------------------------------------
GetCmdHistTmpLine:
;-------------------------------------------------------------------------------
;out:
;eax = ptr to ASCIIZ string of current line or 0 (no tmp line)
;-------------------------------------------------------------------------------
cmp [CmdHistBuffer.TmpLineFlag],0
je @F
mov eax,[CmdHistBuffer.NewNodeOffset]
add eax,[CmdHistBuffer.Ptr]
add eax,2*4
@@:
ret
;-------------------------------------------------------------------------------
PrevCmdHistLine:
;-------------------------------------------------------------------------------
;out:
;CF = 0 - OK, CF = 1 (no previous lines)
;-------------------------------------------------------------------------------
push eax ebx
mov eax,[CmdHistBuffer.Ptr]
mov ebx,[CmdHistBuffer.CurNodeOffset]
lea eax,[eax+ebx]
mov eax,[eax]
inc eax
jz .RetCF
dec eax
mov [CmdHistBuffer.CurNodeOffset],eax
clc
pop ebx eax
ret
.RetCF:
stc
pop ebx eax
ret
;-------------------------------------------------------------------------------
NextCmdHistLine:
;-------------------------------------------------------------------------------
;out:
;CF = 0 - OK, CF = 1 (no next lines)
;-------------------------------------------------------------------------------
push eax ebx
mov eax,[CmdHistBuffer.Ptr]
mov ebx,[CmdHistBuffer.CurNodeOffset]
lea eax,[eax+ebx]
mov eax,[eax+4]
inc eax
jz .RetCF
dec eax
mov [CmdHistBuffer.CurNodeOffset],eax
clc
pop ebx eax
ret
.RetCF:
stc
pop ebx eax
ClearCmdLineEnd:
ret
;-------------------------------------------------------------------------------
DrawCmdLine:
pushad
xor ebx,ebx
jmp @F
DrawCmdLineEnd:
pushad
mov ebx,[CmdLinePos]
@@:
call ClearCmdLine
mov [XPos],1
mov [YPos],MinHeight-1
mov [Color],15
mov al,'>'
call PrintC
mov ecx,[CmdLineLen]
sub ecx,ebx
jbe .Skip
lea esi,[CmdLine+ebx]
.Loop:
lodsb
call PrintC
loop .Loop
.Skip:
popad
ret
DrawCursor:
pushad
mov eax,[CmdLinePos]
times 2 inc eax
mov [CursorX],eax
mov [CursorY],MinHeight-1
mov [AfterKey],1
call ShowImage
popad
ret
HideCursor:
pushad
or [CursorX],-1
or [CursorY],-1
mov [AfterKey],1
call ShowImage
popad
ret
;-----------------------------------------------------------------------------
; Find command in list
FindCmd:
; all commands are case-insensitive
push edi
.X4:
mov al,[edi]
cmp al,0
jz .X5
cmp al,'A'
jb @F
cmp al,'Z'
ja @F
or al,20h
@@:
stosb
jmp .X4
; find command
.X5:
pop edi
.X6:
cmp dword [esi],0
jz .X7
push esi
mov esi,[esi]
lodsb
movzx ecx,al
push edi
repz cmpsb
pop edi
pop esi
jz .X8
add esi,17
jmp .X6
.X7:
stc
.X8:
ret
HelpGroups:
dd aControl,0,0,HelpControlMsg
db 0
dd aData,0,0,HelpDataMsg
db 0
dd aBreakpoints,0,0,HelpBreaksMsg
db 0
; flags field:
; &1: command may be called without parameters
; &2: command may be called with parameters
; &4: command may be called without loaded program
; &8: command may be called with loaded program
Commands:
dd aHlp,OnHelp,HelpSyntax,HelpHelp
db 0Fh
dd aHelp,OnHelp,HelpSyntax,HelpHelp
db 0Fh
dd aQuit,OnQuit,QuitSyntax,QuitHelp
db 0Dh
dd aExit,OnQuit,ExitSyntax,ExitHelp
db 0Dh
dd aLoad,OnLoad,LoadSyntax,LoadHelp
db 6
dd aReload,OnReLoad,ReloadSyntax,ReloadHelp
db 0Dh
dd aTerminate,OnTerminate,TerminateSyntax,TerminateHelp
db 9
dd aDetach,OnDetach,DetachSyntax,DetachHelp
db 9
dd aSuspend,OnSuspend,SuspendSyntax,SuspendHelp
db 9
dd aResume,OnResume,ResumeSyntax,ResumeHelp
db 0Bh
dd aStep,OnStepMultiple,StepSyntax,StepHelp
db 0Bh
dd aProceed,OnProceedMultiple,ProceedSyntax,ProceedHelp
db 0Bh
dd aCalc,OnCalc,CalcSyntax,CalcHelp
db 0Eh
dd aDump,OnDump,DumpSyntax,DumpHelp
db 0Bh
;dd aUnassemble,OnUnassemble,UnassembleSyntax,UnassembleHelp
;db 0Bh
dd aBp,OnBp,BpSyntax,BpHelp
db 0Ah
dd aBpm,OnBpmb,BpmSyntax,BpmHelp
db 0Ah
dd aBpmb,OnBpmb,BpmSyntax,BpmHelp
db 0Ah
dd aBpmw,OnBpmw,BpmSyntax,BpmHelp
db 0Ah
dd aBpmd,OnBpmd,BpmSyntax,BpmHelp
db 0Ah
dd aBl,OnBl,BlSyntax,BlHelp
db 0Bh
dd aBc,OnBc,BcSyntax,BcHelp
db 0Ah
dd aBd,OnBd,BdSyntax,BdHelp
db 0Ah
dd aBe,OnBe,BeSyntax,BeHelp
db 0Ah
dd aReg,OnReg,RSyntax,RHelp
db 0Ah
dd aUnpack,OnUnpack,UnpackSyntax,UnpackHelp
db 9
dd aLoadSymbols,OnLoadSymbols,LoadSymbolsSyntax,LoadSymbolsHelp
db 0Ah
;
dd aAsm,OnAsm,AsmSyntax,AsmHelp
db 2+8
dd aJump,OnJump,JumpSyntax,JumpHelp
db 2+8
dd aDoLoad,DoLoad,DoLoadSyntax,DoLoadHelp
db 1+4
;
dd 0
aHelp db 5,'help',0
aHlp db 2,'h',0
HelpHelp db 'Help on specified function',10
HelpSyntax db 'Usage: h or help [group | command]',10,0
HelpMsg db 'List of known command groups:',10
db '"help control" - display list of control commands',10
db '"help data" - display list of commands concerning data',10
db '"help breakpoints" - display list of commands concerning breakpoints',10,0
aAsm db 2,'a',0
AsmHelp db 'Assemble instruction at current position',10
AsmSyntax db 'Usage: a instruction (',8,8Ah,'mov al,[ebx+12h]',8,8Fh,')',10,0
aJump db 2,'j',0
JumpHelp db 'Sets current window or current register new address',10
JumpSyntax db 'Usage: Jump <expression>',10,0
aDetach db 7,'detach',0
DetachHelp db 'Detach from debugged program',10
DetachSyntax db 'Usage: detach',10,0
aSuspend db 5,'stop',0
SuspendHelp db 'Suspend execution of debugged program',10
SuspendSyntax db 'Usage: stop',10,0
aQuit db 5,'quit',0
QuitHelp db 'Quit from debugger',10
QuitSyntax db 'Usage: quit',10,0
aExit db 5,'exit',0
ExitHelp db 'Exit from debugger',10
ExitSyntax db 'Usage: exit',10,0
aLoad db 5,'load',0
LoadHelp db 'Load program for debugging',10
LoadSyntax db 'Usage: load <program-name> [parameters]',10,0
aDoLoad db 7,'doload',0
DoLoadHelp db 'Load test program for debugging',10
DoLoadSyntax db 'Usage: doload',10,0
aReload db 7,'reload',0
ReloadHelp db 'Reload debugging program (restart debug session)',10
ReloadSyntax db 'Usage: reload',10,0
aTerminate db 10,'terminate',0
TerminateHelp db 'Terminate debugged program',10
TerminateSyntax db 'Usage: terminate',10,0
aResume db 2,'g',0
ResumeHelp db 'Go (resume execution of debugged program)',10
ResumeSyntax db 'Usage: g',10
db ' or: g <expression> - wait until specified address is reached',10,0
aStep db 2,'s',0
StepHelp db 'Make step in debugged program',10
StepSyntax db 'Usage: s [<number>]',10,0
aProceed db 2,'p',0
ProceedHelp db 'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
ProceedSyntax db 'Usage: p [<number>]',10,0
aDump db 2,'d',0
DumpHelp db 'Dump data of debugged program',10
DumpSyntax db 'Usage: d <expression> - dump data at specified address',10
db ' or: d - continue current dump',10,0
aCalc db 2,'?',0
CalcHelp db 'Calculate value of expression',10
CalcSyntax db 'Usage: ? <expression>',10,0
aReg db 2,'r',0
RHelp db 'Set register value',10
RSyntax db 'Usage: r <register> <expression>',10
db ' or: r <register>=<expression> - set value of <register> to <expression>',10,0
aBp db 3,'bp',0
BpHelp db 'set BreakPoint on execution',10
BpSyntax db 'Usage: bp <expression>',10,0
aBpm db 4,'bpm',0
aBpmb db 5,'bpmb',0
aBpmw db 5,'bpmw',0
aBpmd db 5,'bpmd',0
BpmHelp db 'set BreakPoint on Memory access',10
db 'Maximum 4 breakpoints of this type are allowed',10
db 'Note that for this breaks debugger is activated after access',10
BpmSyntax db 'Usage: bpmb [w] <expression>',10
db ' bpmw [w] <expression>',10
db ' bpmd [w] <expression>',10
db ' bpm is synonym for bpmd',10
db '"w" means break only on writes (default is on read/write)',10,0
aBl db 3,'bl',0
BlHelp db 'Breakpoint List',10
BlSyntax db 'Usage: bl - list all breakpoints',10
db ' bl <number> - display info on particular breakpoint',10,0
aBc db 3,'bc',0
BcHelp db 'Breakpoint Clear',10
BcSyntax db 'Usage: bc <number-list>',10
db 'Examples: bc 2',10
db ' bc 1 3 4 A',10,0
aBd db 3,'bd',0
BdHelp db 'Breakpoint Disable',10
BdSyntax db 'Usage: bd <number-list>',10
db 'Examples: bd 2',10
db ' bd 1 3 4 A',10,0
aBe db 3,'be',0
BeHelp db 'Breakpoint Enable',10
BeSyntax db 'Usage: be <number-list>',10
db 'Examples: be 2',10
db ' be 1 3 4 A',10,0
aUnpack db 7,'unpack',0
UnpackHelp db 'Try to bypass unpacker code',10
UnpackSyntax db 'Usage: unpack',10,0
aLoadSymbols db 13,'load-symbols',0
LoadSymbolsHelp db 'Load symbolic information for executable',10
LoadSymbolsSyntax db 'Usage: load-symbols <symbols-file-name>',10,0
; Control commands group
aControl db 8,'control',0
HelpControlMsg db 'List of control commands:',10
db 'h = help - help',10
db 'exit/quit - exit from debugger',10
db 'load <name> [params] - load program for debugging',10
db 'reload - reload debugging program',10
db 'load-symbols <name> - load information on symbols for program',10
db 'terminate - terminate loaded program',10
db 'detach - detach from debugging program',10
db 'stop - suspend execution of debugging program',10
db 'a <instruction> - assemble instruction at current position',10
db 'g [<expression>] - go on (resume execution of debugging program)',10
db 's [<num>] - program step, also <F7>',10
db 'p [<num>] - program wide step, also <F8>',10
db 'unpack - try to bypass unpacker code (heuristic)',10,0
; Data commands group
aData db 5,'data',0
HelpDataMsg db 'List of data commands:',10
db '? <expression> - calculate value of expression',10
db 'd [<expression>] - dump data at given address',10
db 'j <expression> - jump, current window or current register new address',10
;db 'u [<expression>] - unassemble instructions at given address',10
db 'r <register> <expression> or',10
db 'r <register>=<expression> - set register value',10,0
; Breakpoints commands group
aBreakpoints db 12,'breakpoints',0
HelpBreaksMsg db 'List of breakpoints commands:',10
db 'bp <expression> - set breakpoint on execution',10
db 'bpm[b|w|d] <type> <expression> - set breakpoint on memory access',10
db 'bl [<number>] - breakpoint(s) info',10
db 'bc <number>... - clear breakpoint',10
db 'bd <number>... - disable breakpoint',10
db 'be <number>... - enable breakpoint',10,0
;

View File

@ -0,0 +1 @@
uharc a -m3 -mx -md32768 -r koldbg !old\*.* !*.dbg

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,187 @@
BufferSizeI = 1*1024
BufferSizeO = 1*1024
use32
rax equ eax
rbx equ ebx
rcx equ ecx
rdx equ edx
rsi equ esi
rdi equ edi
rbp equ ebp
rsp equ esp
dq equ dd
macro dv A,B
{
db A
dw B
}
macro dy A,B,C
{
db A,B
dw C
}
macro cmova Dst,Src
{
local ..L
jna ..L
mov Dst,Src
..L:
}
macro cmovae Dst,Src
{
local ..L
jnae ..L
mov Dst,Src
..L:
}
macro cmovb Dst,Src
{
local ..L
jnb ..L
mov Dst,Src
..L:
}
macro cmovbe Dst,Src
{
local ..L
jnbe ..L
mov Dst,Src
..L:
}
macro cmovg Dst,Src
{
local ..L
jng ..L
mov Dst,Src
..L:
}
macro cmovge Dst,Src
{
local ..L
jnge ..L
mov Dst,Src
..L:
}
macro cmovl Dst,Src
{
local ..L
jnl ..L
mov Dst,Src
..L:
}
macro cmovle Dst,Src
{
local ..L
jnle ..L
mov Dst,Src
..L:
}
macro cmovno Dst,Src
{
local ..L
jo ..L
mov Dst,Src
..L:
}
macro cmovnp Dst,Src
{
local ..L
jp ..L
mov Dst,Src
..L:
}
macro cmovns Dst,Src
{
local ..L
js ..L
mov Dst,Src
..L:
}
macro cmovnz Dst,Src
{
local ..L
jz ..L
mov Dst,Src
..L:
}
macro cmovo Dst,Src
{
local ..L
jno ..L
mov Dst,Src
..L:
}
macro cmovp Dst,Src
{
local ..L
jnp ..L
mov Dst,Src
..L:
}
macro cmovs Dst,Src
{
local ..L
jns ..L
mov Dst,Src
..L:
}
macro cmovz Dst,Src
{
local ..L
jnz ..L
mov Dst,Src
..L:
}
macro jrcxz Dst
{
jecxz Dst
}
use32
InitDefault:
mov [DefInst.Arch],CPUX32
mov [DefInst.Size],15
mov [DefInst.Negate],True
mov [DefInst.Base],-1
mov [DefInst.Indx],-1
mov [DefInst.Scale],-1
ret
include "disasm.asm"
CrLf db 0
TheL db 0
LastByte db 0
IgnoreInvalid db 0 ;Ignore invalid VEX/XOP
SpaceSize dd 8
Origin dd 0
TheBufferO dd 0
_r8_ dd ?
_r9_ dd ?
_r10_ dq ?
_r15_ dq ?

View File

@ -0,0 +1,26 @@
BufferSizeI = 1k
BufferSizeO = 1k
use64
InitDefault:
mov [DefInst.Arch],CPUX64
mov [DefInst.Size],15
mov [DefInst.Negate],True
mov [DefInst.HideRIP],True
mov [DefInst.Base],-1
mov [DefInst.Indx],-1
mov [DefInst.Scale],-1
ret
include "disasm.asm"
CrLf db 0
TheL db 0
LastByte db 0
IgnoreInvalid db 0 ;Ignore invalid VEX/XOP
SpaceSize dd 8
Origin dq 0
TheBufferO dq 0

View File

@ -0,0 +1,693 @@
ClrMagicBytes:
xor al,al
SetMagicBytes:
test al,4
setnz dl
shl dl,3
mov [I.R],dl
mov bl,-1
cmovnz ebx,[NotP4X]
mov [I.NotR],bl
test al,2
setnz dl
shl dl,3
mov [I.X],dl
mov bl,-1
cmovnz ebx,[NotP4X]
mov [I.NotX],bl
test al,1
setnz dl
shl dl,3
mov [I.B],dl
mov bl,-1
cmovnz ebx,[NotP4X]
mov [I.NotB],bl
test al,8
setnz [I.W]
mov bl,-1
cmovnz ebx,[NotP4X]
mov [I.NotW],bl
test al,40h
setnz [I.P]
mov bl,-1
cmovnz ebx,[NotP4X]
mov [I.NotP],bl
ret
FetchModRM:
FetchB
mov [I.ModRM],al
mov cl,al
mov bl,al
mov dl,al
shr cl,6 ;cl = mod
and bl,7 ;bl = r/m
shr dl,3
and dl,7 ;dl = reg
mov [I.Mod],cl
mov [I.Reg],dl
mov [I.RM],bl
call ModRM2EA
mov al,[I.ModRM]
ret
TWorFW: cmp [I.Syntax],0
jnz .Exit
mov [I.RandSize],VTWORD
cmp [I.Arch],CPUX64
jz .Exit
mov [I.RandSize],VFWORD
.Exit:
ret
SetArg2W:
cmp [I.Fasm],0
jz .Exit
mov [I.Arg2.Type],GPR16
.Exit: ret
SetArg12X:
mov [I.Arg1.Type],XMMRG
mov [I.Arg2.Type],XMMRG
ret
RM32R32C:
call RM32R32M
mov [I.Arg1.Type],GPR64
mov [I.Arg2.Type],CTRRG
cmp [I.Arch],CPUX64
je .L1
mov [I.Arg1.Type],GPR32
;lock mov reg,cr0 = mov reg,cr8
;lock mov cr0,reg = mov cr8,reg
cmp [I.Reg],0
jne .L1
BitTR I.Prefixes,PF0
jnc .L1
mov [I.Reg],8
.L1: ret
;-----------------------------------------------------------------------------
CheckPrevSSE4:
mov ecx,(EndSSE4-TabSSE4)/3
mov edx,TabSSE4
.L1: cmp al,[rdx]
je .L2
add edx,3
loop .L1
stc
ret
.L2: mov edx,[rdx+1]
mov [I.Name],dx
call rbx
mov [I.RandSize],VQWORD+80h
clc
ret
;-----------------------------------------------------------------------------
CheckNextSSE4:
mov ecx,(EndNxtSSE4-NxtSSE4)/4
mov edx,NxtSSE4
.L1: cmp al,[rdx]
je .L2
add edx,4
loop .L1
stc
ret
.L2: mov ecx,[rdx+1]
mov [I.RandSize],cl
shr ecx,8
mov [I.Name],cx
cmp al,2Ah
jne .2A
cmp byte [rsi],0xC0
jae ErrorDec
.2A:
cmp al,15h
ja .L3
mov [I.Arg3.Type],XMMRG
.L3: call R32RM32X
clc
ret
;-----------------------------------------------------------------------------
R32RM32C:
call R32RM32M
mov [I.Arg2.Type],GPR64
mov [I.Arg1.Type],CTRRG
cmp [I.Arch],CPUX64
je .L1
mov [I.Arg2.Type],GPR32
;lock mov reg,cr0 = mov reg,cr8
;lock mov cr0,reg = mov cr8,reg
cmp [I.Reg],0
jne .L1
BitTR I.Prefixes,PF0
jnc .L1
mov [I.Reg],8
.L1: ret
RM32R32D:
call RM32R32M
mov [I.Arg1.Type],GPR64
mov [I.Arg2.Type],DBGRG
cmp [I.Arch],CPUX64
je .L1
mov [I.Arg1.Type],GPR32
.L1: ret
R32RM32D:
call R32RM32M
mov [I.Arg2.Type],GPR64
mov [I.Arg1.Type],DBGRG
cmp [I.Arch],CPUX64
je .L1
mov [I.Arg2.Type],GPR32
.L1: ret
RM32R32T:
call RM32R32M
mov [I.Arg1.Type],GPR64
mov [I.Arg2.Type],TRXRG
cmp [I.Arch],CPUX64
je .L1
mov [I.Arg1.Type],GPR32
.L1: ret
R32RM32T:
call R32RM32M
mov [I.Arg2.Type],GPR64
mov [I.Arg1.Type],TRXRG
cmp [I.Arch],CPUX64
je .L1
mov [I.Arg2.Type],GPR32
.L1: ret
;-----------------------------------------------------------------------------
BNDX4: mov [I.Arg2.Type],GPR64
mov [I.RandSize],VQWORD+80h
cmp [I.Arch],CPUX64
jz .Next
mov [I.RandSize],VDWORD+80h
mov [I.Arg2.Type],GPR32
.Next: ;jmp BNDX1
;-----------------------------------------------------------------------------
BNDX1: mov [I.Arg1.Type],BNDRG
ret
;-----------------------------------------------------------------------------
BNDX3: mov [I.Arg1.Type],BNDRG
BNDX2: mov [I.Arg2.Type],BNDRG
ret
;-----------------------------------------------------------------------------
Rtn0F3A14:
mov [I.RandSize],VBYTE+80h
mov dx,TPEXTRB
.L0: BitTR I.Prefixes,P66
jnc ErrorDec
mov [I.Name],dx
call RM32R32X
mov [I.Arg1.Type],GPR32
cmp [I.W],0
jz .L1
mov [I.Arg1.Type],GPR64
.L1: call ClearW
FetchB
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
Rtn0F3A15:
mov [I.RandSize],VWORD+80h
mov dx,TPEXTRW
jmp Rtn0F3A14.L0
Rtn0F3A16:
mov [I.RandSize],VDWORD+80h
mov dx,TPEXTRD
test [I.W],0
jz .L1
mov [I.RandSize],VQWORD+80h
mov dx,TPEXTRQ
.L1: jmp Rtn0F3A14.L0
Rtn0F3A17:
mov [I.RandSize],VDWORD+80h
mov dx,TEXTRACTPS
jmp Rtn0F3A14.L0
Rtn0F3A20:
mov [I.RandSize],VBYTE+80h
BitTR I.Prefixes,P66
jnc ErrorDec
mov [I.Name],TPINSRB
call R32RM32X
FetchB
mov [I.Arg2.Type],GPR32
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
Rtn0F3A21:
mov [I.RandSize],VDWORD+80h
BitTR I.Prefixes,P66
jnc ErrorDec
mov [I.Name],TINSERTPS
call R32RM32X
FetchB
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
Rtn0F3A22:
call R32RM32X
mov [I.RandSize],VDWORD+80h
BitTR I.Prefixes,P66
jnc ErrorDec
mov dx,TPINSRD
mov [I.Arg2.Type],GPR32
cmp [I.W],0
jz .L1
mov dx,TPINSRQ
mov [I.Arg2.Type],GPR64
.L1: mov [I.Name],dx
call ClearW
FetchB
.L2: mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
Rtn0F3A44:
mov [I.RandSize],VXWORD+80h
mov [I.Name],TPCLMULQDQ
BitTR I.Prefixes,P66
jnc ErrorDec
call R32RM32X
xor eax,eax
FetchB
cmp al,18
ja Rtn0F3A22.L2
mov edx,[rax*2+TabCLMUL]
or dx,dx
jz Rtn0F3A22.L2
mov [I.Name],dx
ret
SetArg3Imm:
FetchB
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
SetArg3CL:
mov [I.Arg3.Type],GPR08
mov [I.Arg3.Reg],RRCX
ret
RtnXOP: mov ebx,R32RM32X
test [I.FlagsXOP],XOPO
jnz .Z1
mov ebx,RM32R32X
.Z1: call rbx
cmp [I.MMMMM],8
jnz .Z2
test [I.FlagsXOP],XOPI
jz .Z2
FetchB
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
.Z2: ret
;-----------------------------------------------------------------------------
SetVT3: push CheckVT3
SetVT: mov [I.Base],-1
mov [I.Indx],-1
mov [I.Scale],-1
mov [I.DispSize],0
cmp [I.Arch],CPUX64
jz .L1
mov [I.Address],AD32
.L1:
mov rsi,[I.SaveRSI]
push rax
sub al,XMMRG-ADXX
mov [I.VT],al
call FetchModRM
pop rax
cmp [I.Arch],CPUX64
jz .L2
BitT I.PrefixesCpy,P67
jnc .L2
BitTS I.Prefixes,P67
.L2:
cmp [I.Relative],0
jnz ErrorDec
ret
;-----------------------------------------------------------------------------
CheckVT3:
cmp [I.Mod],3
jz ErrorDec
ret
;-----------------------------------------------------------------------------
RtnPINSR?:
test [I.VEX],VEXW
jz .L1
cmp [I.Arch],CPUX64
jnz ErrorDec
mov [I.RandSize],VQWORD+80h
mov [I.LastByte],'q'
mov [I.Arg3.Type],GPR64
.L1: ret
;-----------------------------------------------------------------------------
MoveKandZ:
test byte [I.FlagsEVEX],EVEXS
jnz .L1
mov al,[I.AAAA]
or al,al
jz .L1
mov al,'{'
stosb
cmp [I.Syntax],0
jz .L0
mov al,'%'
stosb
.L0:
mov al,'k'
stosb
mov al,[I.AAAA]
add al,'0'
stosb
mov al,'}'
stosb
.L1:
mov al,[I.Z]
or al,al
jz .L2
mov al,'{'
stosb
mov al,'z'
stosb
mov al,'}'
stosb
.L2:
ret
;-----------------------------------------------------------------------------
GetP0P1P2:
;P0
lodsb
cmp rsi,r9
ja .Error
test al,1100b
jnz .Error
mov ah,al
and al,11b
mov [I.MMMMM],al
mov al,ah
test al,10000000b
setz [I.R]
test al,00010000b
setz dl
shl dl,1
or [I.R],dl
shl [I.R],3
test al,01000000b
setz [I.X]
shl [I.X],3
test al,00100000b
setz [I.B]
shl [I.B],3
mov al,[I.X]
shl al,1
mov [I.XX],al
mov [I.P],1
;P1
lodsb
cmp rsi,r9
ja .Error
test al,100b
jz .Error
mov ah,al
and al,11b
mov [I.PP],al
mov al,ah
shr al,3
and al,1111b
xor al,1111b
mov [I.VVVV],al
mov al,ah
rol al,1
and al,1b
mov [I.W],al
;P2
lodsb
cmp rsi,r9
ja .Error
mov ah,al
and al,111b
mov [I.AAAA],al
mov al,ah
xor dl,dl
shl al,1
rcl dl,1
mov [I.Z],dl
mov al,ah
and al,1000b
xor al,1000b
jz .L1
add [I.V],16
.L1:
shl al,1
or [I.VVVV],al
mov al,ah
and al,1100000b
cmp al,1100000b
shr al,5
mov [I.LL],al
test ah,10000b
setnz [I.BB]
;
movzx eax,[I.PP]
mov edx,[rax*4+T6200Tab]
mov ebx,[rax*4+T6238Tab]
mov ecx,[rax*4+T623ATab]
;
mov al,[I.MMMMM]
or al,al
jz .Error
cmp al,00011b
jne .L2
mov edx,ecx
.L2:
cmp al,00010b
jne .L3
mov edx,ebx
.L3:
lodsb
cmp rsi,r9
ja .Error
mov ebx,edx
;
mov [I.SaveRSI],rsi
ret
;
.Error: pop rax
jmp BNDEVEX62.Error
;-----------------------------------------------------------------------------
DetectMULT:
cmp [I.Is62],0
jz .L2
mov al,[I.RandSize]
mov ah,1
cmp al,xW
jz .L1
mov ah,2
cmp al,xD
jz .L1
mov ah,3
cmp al,xQ
jz .L1
mov ah,4
cmp al,xO
jz .L1
mov ah,5
cmp al,xY
jz .L1
mov ah,6
cmp al,xZ
jz .L1
xor ah,ah
.L1:
mov [I.MULT],ah
.L2:
ret
;-----------------------------------------------------------------------------
MoveXtoX:
cmp [I.Mod],3
jz .V1
cmp [I.BB],0
jz .V1
movzx eax,[I.LL]
test byte [I.FlagsEVEX+2],EVEXAA shr 16
jnz .V0
cmp [I.RandSize],xQ
jz .V0
inc eax
.V0: mov esi,dword [rax*2+T1TO]
call MoveStringData
.V1: ret
;-----------------------------------------------------------------------------
MoveSAE1:
cmp [I.Mod],3
jnz .E1
test byte [I.FlagsEVEX],EVEXO
jz .L1
cmp [I.W],0
jz .E1
.L1:
test byte [I.FlagsEVEX],EVEXR
jz .E2
cmp [I.BB],0
jz .E1
mov al,','
stosb
movzx eax,[I.LL]
mov esi,dword [rax*2+TSAE]
call MoveStringData
.E1: ret
.E2: cmp [I.BB],0
jz .E3
cmp [I.LL],00b
jnz .E3
if %B=64
mov rax,',{sae}'
stosq
sub rdi,2
else
mov ax,',{'
stosw
mov eax,'sae}'
stosd
end if
.E3: ret
;-----------------------------------------------------------------------------
MoveSAE2:
cmp [I.Mod],3
jnz .E1
test byte [I.FlagsEVEX],EVEXO
jz .L1
cmp [I.W],0
jz .E1
.L1:
test byte [I.FlagsEVEX],EVEXR
jz .E2
cmp [I.BB],0
jz .E1
movzx eax,[I.LL]
mov esi,dword [rax*2+TSAE]
call MoveStringData
mov al,','
stosb
.E1: ret
.E2: cmp [I.BB],0
jz .E3
cmp [I.LL],00b
jnz .E3
if %B=64
mov rax,'{sae},'
stosq
sub rdi,2
else
mov eax,'{sae'
stosd
mov ax,'},'
stosw
end if
.E3: ret
;-----------------------------------------------------------------------------
GetVectorAL:
test byte [I.FlagsEVEX],EVEXX
jnz .L1
mov al,ZMMRG
cmp [I.BB],0
jnz .L0
test [I.LL],10b
jnz .L0
mov al,YMMRG
test [I.LL],01b
jnz .L0
.L1: mov al,XMMRG
.L0: ret
;-----------------------------------------------------------------------------
GetVectorAndMUL:
test byte [I.FlagsEVEX],EVEXX
jnz .L4
;
mov ah,[I.LL]
mov al,ZMMRG
;
cmp [I.Mod],3
jnz .LX
cmp [I.BB],0
jnz .L0
.LX: ;
test ah,10b
jnz .L0
mov al,YMMRG
test ah,01b
jnz .L0
mov al,XMMRG
;
.L0: mov ah,al
;
cmp [I.BB],0
jnz .L3
cmp al,YMMRG
jz .L2
ja .L1
ret
;
.L1: call .L2
.L2: inc [I.RandSize]
.L3: ret
.L4: mov al,XMMRG
mov ah,al
ret
;-----------------------------------------------------------------------------
GetRDRQAH:
mov ah,GPR32
cmp [I.W],1
jnz .L1
mov ah,GPR64
.L1: ret
;-----------------------------------------------------------------------------
GetRDRQAL:
mov al,GPR32
cmp [I.W],1
jnz .L1
mov al,GPR64
.L1: ret

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,556 @@
;-----------------------------------------------------------------------------
BNDEVEX62:
cmp byte [rsi],0xC0
jae EVEX62
;
call GetP0P1P2
jmp EVEX62.Loop
;
.Error: cmp [I.Arch],CPUX64
jz ErrorDec
;
xor al,al
;
mov [I.R],al
mov [I.X],al
mov [I.B],al
mov [I.W],al
mov [I.V],al
mov [I.Z],al
mov [I.BB],al
mov [I.XX],al
mov [I.VVVV],al
mov [I.AAAA],al
;
mov rsi,[I.SaveRSI]
;
BitTR I.Prefixes,P66
cmp [I.Operand],0
mov [I.RandSize],VQWORD+80h ;32:32
jnz R32RM32
mov [I.RandSize],VDWORD+80h ;16:16
jmp R16RM16
;-----------------------------------------------------------------------------
EVEX62: cmp [I.PreREX],0
jnz ErrorDec
call GetP0P1P2
.Loop:
mov [I.Is62],1
cmp dword [rbx],-1
jz ErrorDec
cmp al,[rbx+X62.Imm]
je .Found
add ebx,X62.Size
jmp .Loop
.Found:
mov al,[rbx+X62.MOS]
cmp [I.BB],0
jnz .L1
shr al,4
.L1:
and al,0Fh
mov [I.RandSize],al
;
mov eax,dword [rbx+X62.Flags]
mov word [I.FlagsEVEX],ax
;
and ah,EVEXLX shr 8
cmp ah,EVEXLX shr 8
jnz .L2
cmp [I.LL],00b
jnz ErrorDec
jmp .SkipLX
.L2: ;
test ah,EVEXL0 shr 8
jz .L3
cmp [I.LL],00b
jz ErrorDec
.L3: ;
test ah,EVEXLL shr 8
jz .L4
cmp [I.LL],10b
jb ErrorDec
.L4:
;
.SkipLX:
;
mov ah,al
and ah,EVEXW0
cmp ah,EVEXW0
jnz .L5
cmp [I.Arch],CPUX64
jz .SkipWNW
mov [I.W],0
jmp .SkipWNW
.L5: ;
test al,EVEXYW
jz .L6
cmp [I.W],1
jz ErrorDec
.L6: ;
test al,EVEXNW
jz .L7
cmp [I.W],0
jz ErrorDec
.L7:
;
.SkipWNW:
;
test al,EVEXV
jz .L8
mov al,[I.VVVV]
and al,1111b
or al,al
jnz ErrorDec
.L8: ;
mov edx,dword [rbx+X62.Name]
mov al,byte [rbx+X62.Flags+1]
and al,EVEXE shr 8
cmp al,EVEXE shr 8
jnz .L9
movzx eax,[I.W]
movzx edx,dx
add edx,T62Names
mov edx,[rdx+rax*2]
.L9:
mov [I.Prefix],'v'
mov [I.Name],dx
cmp [I.W],1
jnz .LA
mov al,byte [rbx+X62.Flags+1]
and al,EVEXE shr 8
cmp al,EVEXE shr 8
jz .LA
test al,EVEXD1 shr 8
ifnz mov [I.LastByte],'d'
test al,EVEXQ1 shr 8
ifnz mov [I.LastByte],'q'
.LA: ;
movzx r8d,word [rbx+X62.Rtn]
add r8d,RtnXX
test [rbx+X62.Flags],EVEX2
jz .LB
movzx eax,[I.W]
movzx r8d,word [r8+rax*2]
add r8d,RtnXX
.LB: ;
call FetchModRM
test byte [I.FlagsEVEX+1],EVEXM shr 8
jz .LC
call GetVectorAndMUL
.LC:
test byte [I.FlagsEVEX+1],EVEXU shr 8
jnz .SkipBB
test byte [I.FlagsEVEX+1],EVEXB shr 8
jz .LD
;
cmp [I.BB],0
jz .LD
.SkipBB:
cmp [I.W],1
jnz .LD
;inc [I.MULT]
inc [I.RandSize]
.LD:
call r8
;
test byte [I.FlagsEVEX+1],EVEXI shr 8
jz .LG
lea r8,[I.Arg1]
mov ecx,5
.LE:
cmp [r8+TArg.Type],0
jz .LF
add r8,sizeof.TArg
loop .LE
ret
.LF:
FetchB
mov [r8+TArg.Type],80h+1
mov [r8+TArg.ImmB],al
.LG: ret
;-----------------------------------------------------------------------------
T6244:
cmp [I.ModRM],3
jz ErrorDec
cmp [I.BB],1
jz ErrorDec
mov [I.RandSize],VOWORD
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type2nd],InRM or 80h
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
mov [I.Arg3.Type],ah
ret
;-----------------------------------------------------------------------------
T6214:
call GetRDRQAH
;jmp T6201
;-----------------------------------------------------------------------------
T6201:
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type2nd],InRM
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
mov [I.Arg3.Type],ah
ret
;-----------------------------------------------------------------------------
T6215:
mov [I.RandSize],xO
mov ah,XMMRG
jmp T6201
;-----------------------------------------------------------------------------
T6200:
mov [I.RandSize],xD
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],ah
mov [I.Arg2.Type2nd],InRM
cmp [I.W],0
jz .L1
inc [I.RandSize]
dec al
cmp al,XMMRG
jae .L1
mov al,XMMRG
.L1: jmp SetVT3
;-----------------------------------------------------------------------------
T621B:
mov [I.RandSize],xQ
;
cmp [I.W],0
jnz .L1
;
dec [I.RandSize]
;
dec al
cmp al,XMMRG
jae .L1
mov al,XMMRG
;
.L1:
;
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],ah
mov [I.Arg2.Type2nd],InRM
;
mov al,ah
jmp SetVT3
;-----------------------------------------------------------------------------
T6202:
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type2nd],InRM
mov [I.Arg1.Type],KXXRG
mov [I.Arg2.Type],al
mov [I.Arg3.Type],ah
ret
;-----------------------------------------------------------------------------
T6219:
cmp [I.Mod],3
jz ErrorDec
;jmp T6203
;-----------------------------------------------------------------------------
T6203:
mov ah,XMMRG
call GetVectorAL
T6204:
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],al
mov [I.Arg2.Type],ah
ret
;-----------------------------------------------------------------------------
T621A:
cmp [I.Mod],3
jz ErrorDec
mov al,ZMMRG
mov ah,XMMRG
jmp T6204
;-----------------------------------------------------------------------------
T6208:
cmp [I.BB],0
jz .L1
dec [I.RandSize]
.L1:
jmp T6204
;-----------------------------------------------------------------------------
T6209:
or byte [I.FlagsEVEX+2],EVEXAA shr 16
;
cmp [I.BB],0
jnz .L1
dec [I.RandSize]
.L1:
T6207:
dec ah
cmp ah,XMMRG
jae .L1
mov ah,XMMRG
.L1: jmp T6204
;-----------------------------------------------------------------------------
T6205:
dec al
cmp al,XMMRG
jae .L1
mov al,XMMRG
.L1:
jmp T6204
;-----------------------------------------------------------------------------
T6206:
cmp [I.W],0
jnz T6204
;
dec [I.RandSize]
;
or byte [I.FlagsEVEX+2],EVEXAA shr 16
;
jmp T6207
;-----------------------------------------------------------------------------
T620A:
dec ah
cmp ah,XMMRG
jae .L1
mov ah,XMMRG
.L1:
T620B:
mov [I.Arg2.Type2nd],InReg
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type],al
mov [I.Arg1.Type],ah
ret
;-----------------------------------------------------------------------------
T6223:
mov al,XMMRG
mov ah,GPR32
jmp T620B
;-----------------------------------------------------------------------------
T6221: mov [I.RandSize],xO
;call DetectMULT
;jmp T6220
;-----------------------------------------------------------------------------
T6220:
mov ah,XMMRG
jmp T620B
;-----------------------------------------------------------------------------
T6222:
mov [I.RandSize],xY
;call DetectMULT
mov ah,YMMRG
jmp T620B
;-----------------------------------------------------------------------------
T620C:
cmp [I.Mod],3
jnz T6201
mov [I.Name],TMOVHLPS
jmp T6201
;-----------------------------------------------------------------------------
T620D:
cmp [I.Mod],3
jz ErrorDec
jmp T6201
;-----------------------------------------------------------------------------
T620E:
cmp [I.Mod],3
jnz .L1
mov [I.Name],TMOVLHPS
.L1: jmp T6201
;-----------------------------------------------------------------------------
T620F:
cmp [I.Mod],3
jz ErrorDec
jmp T620B
;-----------------------------------------------------------------------------
T6210:
cmp [I.Mod],3
jz ErrorDec
jmp T620B
;-----------------------------------------------------------------------------
T621C:
cmp [I.Mod],3
jz ErrorDec
jmp T6204
;-----------------------------------------------------------------------------
T6211:
call GetRDRQAH
jmp T6204
;-----------------------------------------------------------------------------
T6212:
call GetRDRQAH
jmp T620B
;-----------------------------------------------------------------------------
T6213:
call GetRDRQAL
jmp T6204
;-----------------------------------------------------------------------------
T6271:
mov ebx,T0F71N
movzx edx,[I.Reg]
.L0: mov dx,[rdx*2+rbx]
or dx,dx
jz ErrorDec
mov [I.Name],dx
mov [I.Arg1.Type2nd],InVVVV
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],al
mov [I.Arg2.Type],ah
ret
;-----------------------------------------------------------------------------
T6272:
mov ebx,T0F72N
.L0: movzx edx,[I.Reg]
cmp [I.W],1
jnz .L1
add dl,8
.L1: jmp T6271.L0
;-----------------------------------------------------------------------------
T6273:
mov ebx,T0F73N
jmp T6272.L0
;-----------------------------------------------------------------------------
T6216:
cmp [I.VVVV],00000b
jnz T6201
jmp T6203
;-----------------------------------------------------------------------------
T6217:
cmp [I.VVVV],00000b
jnz T6201
jmp T620B
;-----------------------------------------------------------------------------
T6218:
cmp al,XMMRG
jz .L1
inc [I.RandSize]
.L1: jmp T6204
;-----------------------------------------------------------------------------
T62RD: call GetRDRQAH
jmp T62RB.L0
;-----------------------------------------------------------------------------
T62RW: mov ah,GPR16
jmp T62RB.L0
;-----------------------------------------------------------------------------
T62RB: mov ah,GPR08
.L0: cmp [I.Mod],3
jnz ErrorDec
call GetVectorAL
mov [I.XX],0
jmp T6204
;-----------------------------------------------------------------------------
T62V1XYZ:
mov [I.RandSize],xD
;
cmp [I.W],0
jz .L1
;
inc [I.RandSize]
;
dec al
cmp al,XMMRG
jae .L1
mov al,XMMRG
.L1: ;
call SetVT3
;
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type2nd],InReg
mov [I.Arg1.Type],ah
;
mov dl,[I.RandSize]
call GetVectorAndMUL
mov [I.RandSize],dl
mov [I.Arg2.Type],al
ret
;-----------------------------------------------------------------------------
T62V2XYZ:
mov [I.RandSize],xQ
;
cmp [I.W],0
jnz .L1
;
dec [I.RandSize]
;
dec al
cmp al,XMMRG
jae .L1
mov al,XMMRG
;
.L1: push rax
mov al,ah
call SetVT3
pop rax
;
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type2nd],InReg
mov [I.Arg1.Type],ah
mov [I.Arg2.Type],al
ret
;-----------------------------------------------------------------------------
T62XYZVV1:
movzx edx,[I.Reg]
cmp [I.W],0
jz .L1
add dl,8
.L1:
mov edx,[rdx*2+T??C6N]
or dx,dx
jz ErrorDec
mov [I.Name],dx
mov al,ZMMRG
cmp [I.W],0
jz .L2
mov al,YMMRG
.L2:
mov [I.Arg1.Type],ah
mov [I.Arg1.Type2nd],InRM
jmp SetVT3
;-----------------------------------------------------------------------------
T62XYZVV2:
movzx edx,[I.Reg]
cmp [I.W],0
jz .L1
add dl,8
.L1:
mov edx,[rdx*2+T??C7N]
or dx,dx
jz ErrorDec
mov [I.Name],dx
mov al,ZMMRG
mov [I.Arg1.Type],ah
mov [I.Arg1.Type2nd],InRM
jmp SetVT3
;-----------------------------------------------------------------------------
T621D:
cmp [I.Mod],3
jnz ErrorDec
mov ah,KXXRG
jmp T6204
;-----------------------------------------------------------------------------
T621E:
cmp [I.Mod],3
jnz ErrorDec
T621F:
mov al,KXXRG
jmp T6204
;-----------------------------------------------------------------------------
T6224:
mov [I.RandSize],xO
mov ah,XMMRG
jmp T6225.L0
;-----------------------------------------------------------------------------
T6225:
mov [I.RandSize],xY
mov ah,YMMRG
.L0: jmp T6201
;-----------------------------------------------------------------------------

View File

@ -0,0 +1,975 @@
r8d equ edi
r8 equ rdi
;-----------------------------------------------------------------------------
R32RM32C5:
mov eax,R32RM32
jmp R16RM16C5.1
R16RM16C5:
mov eax,R16RM16
.1: cmp byte [rsi],0xC0
jae RtnAVX2C5
or byte [I.Flags],_O
and byte [I.Prefixes],not (bit P66)
jmp rax
RtnAVX2C5:
;F0/66/F2/F3/REX then #UD
test byte [I.Prefixes],bit PF0+bit P66+bit PF2+bit PF3+bit P4X
jnz ErrorDec
FetchB
mov [I.VEX],al
and [I.VEX],7Fh ;clear VEX.R
mov ah,al
and al,10000000b
xor al,10000000b
shr al,5 ;REX.R
jz .L1
cmp [IgnoreInvalid],True
je .L1
cmp [I.Arch],CPUX64
jne ErrorDec
.L1:
mov [I.PreREX],al
call SetMagicBytes
mov [I.P],1
mov al,ah
and al,01111000b ;vvvv
xor al,01111000b
shr al,3
cmp [IgnoreInvalid],True
je .L2
cmp al,7
jbe .L2
cmp [I.Arch],CPUX64
jne ErrorDec
.L2:
mov [I.VVVV],al
mov al,ah
and eax,11b ;pp
;mov [PP],al
mov edx,[rax*4+C4C5Tab]
mov edi,[rax*3+CMPSuffixesX]
jmp C4C5XX
;-----------------------------------------------------------------------------
R32RM32C4:
mov eax,R32RM32
jmp R16RM16C4.1
R16RM16C4:
mov eax,R16RM16
.1: cmp byte [rsi],0xC0
jae RtnAVX2C4
or byte [I.Flags],_O
and byte [I.Prefixes],not (bit P66)
jmp rax
RtnAVX2C4:
mov [I.RandSize],0
;F0/66/F2/F3/REX then #UD
test byte [I.Prefixes],bit PF0+bit P66+bit PF2+bit PF3+bit P4X
jnz ErrorDec
FetchB
mov ah,al
;and al,11100000b
xor al,11100000b
shr al,5 ;REX.RXB
jz .L1
cmp [IgnoreInvalid],True
je .L1
cmp [I.Arch],CPUX64
jne ErrorDec
.L1:
mov [I.PreREX],al
call SetMagicBytes
mov [I.P],1
mov al,ah
and al,11111b
mov [I.MMMMM],al ;mmmmm
FetchB
mov ah,al
mov [I.VEX],al
and al,01111000b ;vvvv
xor al,01111000b
shr al,3
cmp [IgnoreInvalid],True
je .L2
cmp al,7
jbe .L2
cmp [I.Arch],CPUX64
jne ErrorDec
.L2:
mov [I.VVVV],al
mov al,ah
and eax,11b ;pp
;mov [PP],al
mov edx,[rax*4+C4C5Tab]
mov ebx,[rax*4+C438Tab]
mov ecx,[rax*4+C43ATab]
mov edi,[rax*3+CMPSuffixesX]
mov al,[I.MMMMM]
or al,al
jz ErrorDec
cmp al,00011b
ja ErrorDec
;cmp al,00011b
jne .L3
mov edx,ecx
.L3:
cmp al,00010b
jne .L4
mov edx,ebx
.L4:
C4C5XX:
mov word [I.Suffix3rd],di
FetchB
mov [I.AfterVEX],al
mov [I.SaveRSI],rsi
.L1:
cmp dword [rdx],-1
jz ErrorDec
cmp al,[rdx+CXX.Imm]
jz .L2
add edx,CXX.Size
jmp .L1
.L2:
mov eax,dword [rdx+CXX.Flags]
mov word [I.FlagsVEX],ax
mov cl,VEXL
and al,cl
mov ah,[I.VEX]
and ah,al
jnz ErrorDec
test [I.FlagsVEX],VEXN
jz .L3
mov ah,[I.VEX]
and ah,cl
jz ErrorDec
.L3:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
test [I.FlagsVEX+1],VEXG shr 8
jz .L4
xor cl,cl
cmp [I.Arch],CPUX64
jne .L4
mov cl,VEXW
.L4:
mov al,[rdx+CXX.MOS]
test [I.VEX],cl
jz .L5
shr al,4
.L5: and al,0Fh
mov [I.RandSize],al
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov al,byte [rdx+CXX.Flags]
and al,VEXW
mov ah,[I.VEX]
cmp [I.Arch],CPUX64
je .L6
test [I.FlagsVEX+1],VEXC shr 8
jnz .L6
test ah,VEXW
jnz ErrorDec
.L6:
and ah,al
jnz ErrorDec
mov al,byte [rdx+CXX.Flags]
and al,VEXV
jz .L7
cmp [I.VVVV],0 ;!1111b=0000b
jnz ErrorDec
.L7:
movzx r8d,[rdx+CXX.Rtn]
add r8d,RtnXX
mov edx,dword [rdx+CXX.Name]
test [I.FlagsVEX+1],VEXH shr 8
jnz .L8
mov [I.Prefix],'v'
.L8: mov [I.Name],dx
test [I.FlagsVEX+1],VEXF shr 8
jnz .L9
call FetchModRM
.L9:
test [I.FlagsVEX+1],VEXR shr 8
jz .LA
cmp [I.Mod],3
jnz ErrorDec
.LA:
cmp [I.Mod],3
jnz .LB
test [I.FlagsVEX],VEXM
jnz ErrorDec
.LB: jmp r8
RtnC4C5:
lea r8,[I.Arg1]
mov al,XMMRG
test [I.VEX],VEXL
jz .L1
mov al,YMMRG
.L1: mov ah,al
test [I.FlagsVEX+1],VEX2 shr 8
jz .L2
mov ah,XMMRG
.L2:
test [I.FlagsVEX+1],VEX1 shr 8
jz .L3
mov al,XMMRG
.L3:
test [I.FlagsVEX+1],VEXG shr 8
jz .L4
mov ax,GPR32 by GPR32
cmp [I.Arch],CPUX64
jne .L4
test [I.VEX],VEXW
jz .L4
mov ax,GPR64 by GPR64
.L4:
push rax
test [I.FlagsVEX+1],VEXS shr 8
jnz .NDD
mov [r8+TArg.Type],al
mov [r8+TArg.Type2nd],InReg
add r8d,sizeof.TArg
.NDD:
mov al,XMMRG
test [I.VEX],VEXL
jz .L5
mov al,YMMRG
.L5:
test [I.FlagsVEX+1],VEXG shr 8
jz .L6
mov al,GPR32
cmp [I.Arch],CPUX64
jne .L6
test [I.VEX],VEXW
jz .L6
mov al,GPR64
.L6:
test [I.FlagsVEX],VEXV
jnz .L7
mov [r8+TArg.Type],al
mov [r8+TArg.Type2nd],InVVVV
add r8d,sizeof.TArg
.L7: pop rax
;cmp [I.Mod],3
;setnz [r8+TArg.Mem]
mov dl,ah
mov [r8+TArg.Type],dl
mov [r8+TArg.Type2nd],InRM
add r8d,sizeof.TArg
test [I.FlagsVEX],VEXI
jnz .Imm
test [I.FlagsVEX],VEX8
jz .L8
movzx eax,byte [rsi]
cmp al,1Fh
ja .Imm
FetchB
cmp [I.AfterVEX],0xC2
jne .L8
mov edx,[rax*2+CMPxxNames]
mov [I.Name],dx
mov eax,dword [I.Suffix3rd]
mov dword [I.Suffix2nd],eax
ret
.Imm: FetchB
mov [r8+TArg.Type],80h+1
mov [r8+TArg.ImmB],al
ret
.L8:
test [I.FlagsVEX],VEX4
jnz .L9
ret
.L9:
FetchB
shr al,4
cmp [IgnoreInvalid],True
je .LA
cmp [I.Arch],CPUX64
je .LA
and al,111b
.LA: mov [r8+TArg.Reg],al
mov [r8+TArg.Type],XMMRG
test [I.VEX],VEXL
jz .LB
mov [r8+TArg.Type],YMMRG
.LB: ret
;-----------------------------------------------------------------------------
RtnC401:
;cmp [I.Mod],3
;setnz [I.Arg2.Mem]
mov [I.Arg2.Type],XMMRG
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],XMMRG
mov [I.Arg1.Type2nd],InReg
test [I.VEX],VEXL
jz .L1
mov [I.Arg1.Type],YMMRG
.L1: ret
;-----------------------------------------------------------------------------
RtnC404:test [I.VEX],VEXW
jz .L1
mov [I.LastByte],'q'
.L1: ;jmp RtnC402
;-----------------------------------------------------------------------------
RtnC402:mov al,XMMRG
test [I.VEX],VEXL
jz .L1
mov al,YMMRG
.L1:
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type],al
mov [I.Arg3.Type2nd],InReg
ret
;-----------------------------------------------------------------------------
RtnC403:test [I.VEX],VEXW
jz .L1
mov [I.LastByte],'q'
.L1: jmp RtnC4C5
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
RtnC405:test [I.VEX],VEXW
jz .L1
mov [I.LastByte],'q'
.L1: ;jmp RtnC4VT
;-----------------------------------------------------------------------------
RtnC4VT:mov al,XMMRG
test [I.VEX],VEXL
jz .L1
mov al,YMMRG
.L1: call SetVT
;cmp [I.Mod],3
;setnz [I.Arg2.Mem]
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg3.Type],al
mov [I.Arg3.Type2nd],InVVVV
ret
;-----------------------------------------------------------------------------
RtnC406:call RtnC4VT
mov ax,'ps'
test [I.VEX],VEXW
jz .L1
mov ah,'d' ;'pd'
.L1: mov word [I.Suffix2nd],ax
ret
;-----------------------------------------------------------------------------
RtnC407:call RtnC4C5
mov ax,'ps'
test [I.VEX],VEXW
jz .L1
mov ah,'d' ;'pd'
.L1: mov word [I.Suffix2nd],ax
ret
;-----------------------------------------------------------------------------
RtnC408:test [I.VEX],VEXW
jz .L1
mov [I.RandSize],xQ
.L1: call RtnC4C5
mov ax,'ss'
test [I.VEX],VEXW
jz .L2
mov ah,'d' ;'sd'
.L2: mov word [I.Suffix2nd],ax
ret
;-----------------------------------------------------------------------------
RtnC409:
mov al,GPR32
cmp [I.Arch],CPUX64
jne .L1
test [I.VEX],VEXW
jz .L1
mov al,GPR64
.L1:
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
;cmp [I.Mod],3
;setnz [I.Arg2.Mem]
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InRM
mov [I.Arg3.Type],al
mov [I.Arg3.Type2nd],InVVVV
ret
;-----------------------------------------------------------------------------
RtnC40A:
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'w'
.L0:
mov al,KXXRG
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InRM
FetchB
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
;-----------------------------------------------------------------------------
RtnC40B:
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'q'
.L0: jmp RtnC40A.L0
;-----------------------------------------------------------------------------
RtnC40C:
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg1.Type],XMMRG
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type],YMMRG
mov [I.Arg2.Type2nd],InReg
.L1:
FetchB
mov [I.Arg3.Type],80h+1
mov [I.Arg3.ImmB],al
ret
;-----------------------------------------------------------------------------
RtnC40D:
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg1.Type],XMMRG
mov [I.Arg1.Type2nd],InRM
mov al,XMMRG
test [I.XOP],XOPL
jz .L1
mov al,YMMRG
.L1:
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InReg
jmp RtnC40C.L1
;-----------------------------------------------------------------------------
RtnC40F:
mov al,GPR64
cmp [I.Arch],CPUX64
jne RtnC40E.L1
test [I.VEX],VEXW
jnz RtnC40E.L2
RtnC40E:
.L1: mov al,GPR32
.L2:
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type],XMMRG
mov [I.Arg2.Type2nd],InReg
jmp RtnC40C.L1
;-----------------------------------------------------------------------------
RtnC410:
mov [I.Arg1.Type],YMMRG
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],YMMRG
mov [I.Arg2.Type2nd],InVVVV
;cmp [I.Mod],3
;setnz [I.Arg3.Mem]
mov [I.Arg3.Type],XMMRG
mov [I.Arg3.Type2nd],InRM
FetchB
mov [I.Arg4.Type],80h+1
mov [I.Arg4.ImmB],al
ret
;-----------------------------------------------------------------------------
RtnCLMUL:
call RtnC4C5
movzx eax,byte [rsi-1]
cmp al,18
ja .L1
mov edx,[rax*2+TabCLMUL]
or dx,dx
jz .L1
mov [I.Name],dx
mov [I.Arg4.Type],0 ;Delete
.L1: ret
;-----------------------------------------------------------------------------
C40F3A48:
mov ebx,TPERMIL2PSX
jmp C40F3A49.L1
;-----------------------------------------------------------------------------
C40F3A49:
mov ebx,TPERMIL2PDX
.L1:
mov al,XMMRG
test [I.VEX],VEXL
jz .L2
mov al,YMMRG
.L2:
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type],al
mov [I.Arg4.Type],al
FetchB
mov dl,al
shr dl,4
cmp [IgnoreInvalid],True
je .L3
cmp [I.Arch],CPUX64
je .L3
and dl,111b
.L3:
lea r8,[I.Arg3]
test [I.VEX],VEXW
jnz .L7
lea r8,[I.Arg4]
.L7: mov [r8+TArg.Reg],dl
and eax,1111b
cmp al,0011b
ja .L4
mov edx,[rax*2+rbx]
mov [I.Name],dx
jmp .L5
.L4:
mov [I.Arg5.Type],80h+1
mov [I.Arg5.ImmB],al
.L5:
lea r8,[I.Arg4]
test [I.VEX],VEXW
jnz .L6
lea r8,[I.Arg3]
.L6:
mov [r8+TArg.Type2nd],InRM
;cmp [I.Mod],3
;setnz [r8+TArg.Mem]
ret
;-----------------------------------------------------------------------------
RtnC411:
call RM32R32M
mov [I.Arg2.Type],XMMRG
test [I.VEX],VEXW
jz .L1
cmp [I.Arch],CPUX64
jnz ErrorDec
mov [I.Arg1.Type],GPR64
mov [I.RandSize],VQWORD+80h
mov [I.LastByte],'q'
.L1: jmp RtnC40C.L1
;-----------------------------------------------------------------------------
RtnC413:
push RtnPINSR?
RtnC412:
mov [I.Arg1.Type],XMMRG
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],XMMRG
mov [I.Arg2.Type2nd],InVVVV
;cmp [I.Mod],3
;setnz [I.Arg3.Mem]
mov [I.Arg3.Type],GPR32
mov [I.Arg3.Type2nd],InRM
FetchB
mov [I.Arg4.Type],80h+1
mov [I.Arg4.ImmB],al
ret
;-----------------------------------------------------------------------------
RtnC414:
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg2.Type],YMMRG
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],YMMRG
mov [I.Arg1.Type2nd],InReg
jmp RtnC40C.L1
;-----------------------------------------------------------------------------
C4FMA: mov al,XMMRG
test [I.VEX],VEXL
jz .L1
mov al,YMMRG
.L1:
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
mov [I.Arg3.Type],al
mov [I.Arg4.Type],al
FetchB
shr al,4
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InVVVV
lea r8,[I.Arg3]
test [I.VEX],VEXW
jnz .L2
lea r8,[I.Arg4]
.L2:
mov [r8+TArg.Reg],al
lea r8,[I.Arg4]
test [I.VEX],VEXW
jnz .L3
lea r8,[I.Arg3]
.L3:
;cmp [I.Mod],3
;setnz [r8+TArg.Mem]
mov [r8+TArg.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC415:
movzx eax,[I.Reg]
mov edx,[rax*2+BMI1]
or dx,dx
jz ErrorDec
mov [I.Name],dx
mov [I.Prefix],0
mov al,GPR32
cmp [I.Arch],CPUX64
jne .L1
test [I.VEX],VEXW
jz .L1
mov al,GPR64
.L1:
mov [I.Arg2.Type],al
mov [I.Arg1.Type],al
;cmp [I.Mod],3
;setnz [I.Arg2.Mem]
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type2nd],InVVVV
ret
;-----------------------------------------------------------------------------
RtnC416:
call R32RM32M
cmp [I.Arch],CPUX64
jne .L1
test [I.VEX],VEXW
jz .L1
mov [I.Arg1.Type],GPR64
mov [I.Arg2.Type],GPR64
.L1: jmp RtnC40C.L1
;-----------------------------------------------------------------------------
RtnC4C508:
test [I.VEX],VEXW
jz .L1
mov [I.Name],TKUNPCKDQ
.L1: jmp RtnC4C502.L0
;-----------------------------------------------------------------------------
RtnC4C501:
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'q'
.L0: jmp RtnC4C502.L0
;-----------------------------------------------------------------------------
RtnC4C502:
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'d'
.L0: ;
cmp [I.Mod],3
jnz ErrorDec
;
mov al,KXXRG
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
mov [I.Arg3.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InVVVV
;cmp [I.Mod],3
;setnz [I.Arg3.Mem]
mov [I.Arg3.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC4C503:
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'d'
.L0: jmp RtnC4C505.L0
;-----------------------------------------------------------------------------
RtnC4C504:
cmp [I.Mod],3
jnz ErrorDec
RtnC4C505:
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'q'
.L0:
mov al,KXXRG
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
mov [I.Arg1.Type2nd],InReg
;cmp [I.Mod],3
;setnz [I.Arg2.Mem]
mov [I.Arg2.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC4C506:
cmp [I.Mod],3
jz ErrorDec
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'d'
.L0:
mov al,KXXRG
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InReg
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg1.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC4C507:
cmp [I.Mod],3
jz ErrorDec
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'q'
.L0:
jmp RtnC4C506.L0
;-----------------------------------------------------------------------------
RtnC4C509:
cmp [I.Mod],3
jnz ErrorDec
mov al,GPR32
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'q'
mov al,GPR64
.L0:
mov [I.Arg1.Type],KXXRG
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC4C50A:
cmp [I.Mod],3
jnz ErrorDec
mov al,GPR32
test [I.VEX],VEXW
jz .L0
mov [I.LastByte],'q'
mov al,GPR64
.L0:
mov [I.Arg2.Type],KXXRG
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type2nd],InReg
mov [I.Arg1.Type],al
ret
;-----------------------------------------------------------------------------
RtnC4C50B:
cmp [I.Reg],2 ;/2
jb ErrorDec
cmp [I.Reg],3 ;/3
ja ErrorDec
jne .L1
mov [I.Name],TSTMXCSR
.L1:
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg1.Type2nd],InRM
mov [I.Arg1.Type],GPR32
ret
;-----------------------------------------------------------------------------
RtnC4C50C:
mov al,XMMRG
test [I.VEX],VEXL
jz .L1
mov al,YMMRG
.L1:
;cmp [I.Mod],3
;setnz [I.Arg1.Mem]
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type2nd],InReg
mov [I.Arg1.Type],al
mov [I.Arg2.Type],al
ret
;-----------------------------------------------------------------------------
C4C5NB2:
mov dx,TMOVLHPS
jmp C4C5NB1.L1
;-----------------------------------------------------------------------------
C4C5NB1:mov dx,TMOVHLPS
.L1: cmp [I.Mod],3
jne .L2
mov [I.Name],dx
.L2: jmp RtnC4C5
;-----------------------------------------------------------------------------
RtnC4C50D:
mov ah,XMMRG
test [I.VEX],VEXL
jz .L1
mov ah,YMMRG
.L1:
mov al,GPR32
cmp [I.Arch],CPUX64
jnz .L2
mov al,GPR64
.L2:
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],al
mov [I.Arg2.Type],ah
ret
;-----------------------------------------------------------------------------
RtnC4C50E:
test [I.VEX],VEXL
jnz .L1
mov [I.Name],TZEROUPPER
.L1: ret
;-----------------------------------------------------------------------------
RtnC4C5XRM:
mov al,XMMRG
mov ah,GPR32
test [I.VEX],VEXW
jz .L1
cmp [I.Arch],CPUX64
jnz ErrorDec
mov [I.LastByte],'q'
mov ah,GPR64
.L1:
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InRM
mov [I.Arg1.Type],al
mov [I.Arg2.Type],ah
ret
;-----------------------------------------------------------------------------
RtnC4C5RMX:
mov al,XMMRG
mov ah,GPR32
test [I.VEX],VEXW
jz .L1
cmp [I.Arch],CPUX64
jnz ErrorDec
mov [I.LastByte],'q'
mov ah,GPR64
.L1:
mov [I.Arg2.Type2nd],InReg
mov [I.Arg1.Type2nd],InRM
mov [I.Arg2.Type],al
mov [I.Arg1.Type],ah
ret
;-----------------------------------------------------------------------------
RtnC4C50F:
mov al,GPR64
cmp [I.Arch],CPUX64
jz .L1
mov al,GPR32
.L1:
mov [I.Arg1.Type],al
mov [I.Arg2.Type],XMMRG
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type2nd],InRM
jmp RtnC40C.L1
;-----------------------------------------------------------------------------
C4C50F71:
mov edx,T0F71Names
jmp C4C5NDSX
;-----------------------------------------------------------------------------
C4C50F72:
mov edx,T0F72Names
jmp C4C5NDSX
;-----------------------------------------------------------------------------
C4C50F73:
mov edx,T0F73Names
C4C5NDSX:
movzx eax,[I.Reg]
mov edx,[rdx+rax*2]
or dx,dx
jz ErrorDec
mov [I.Name],dx
jmp RtnC4C5
;-----------------------------------------------------------------------------
RtnC4C510:
mov al,YMMRG
test [I.VEX],VEXL
jnz .L1
mov al,XMMRG
.L1:
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],al
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type],XMMRG
mov [I.Arg3.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC4C511:
mov al,GPR32
test [I.VEX],VEXW
jz .L1
cmp [I.Arch],CPUX64
jnz ErrorDec
mov al,GPR64
.L1:
mov [I.Arg1.Type],al
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],XMMRG
mov [I.Arg2.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
RtnC4C512:
mov al,GPR32
test [I.VEX],VEXW
jz .L1
cmp [I.Arch],CPUX64
jnz ErrorDec
mov [I.RandSize],VQWORD
mov al,GPR64
.L1:
mov [I.Arg1.Type],XMMRG
mov [I.Arg1.Type2nd],InReg
mov [I.Arg2.Type],XMMRG
mov [I.Arg2.Type2nd],InVVVV
mov [I.Arg3.Type],al
mov [I.Arg3.Type2nd],InRM
ret
;-----------------------------------------------------------------------------
C4C5MXJ:cmp [I.Mod],3
jz RtnC4C5
cmp [I.VVVV],0 ;!1111b=0000b
jnz ErrorDec
jmp RtnC4C50C
;-----------------------------------------------------------------------------
C4C5XMJ:cmp [I.Mod],3
jz .L1
or [I.FlagsVEX],VEXV
cmp [I.VVVV],0 ;!1111b=0000b
jnz ErrorDec
.L1: jmp RtnC4C5

View File

@ -0,0 +1,50 @@
CntItems = 0
ScanItems = 1 ;must be >0, temporary equal 0
EleSize = 6 ;xxh.Size
virtual at 0
Vals::
rb 64*1024
end virtual
macro AddElement Source
{
local A,B,C,Index,Found
C = 0
Index = 0
Found = 0
if ScanItems
repeat CntItems
Found = 0
load B fword from Vals:+(%-1)*EleSize+C
load A fword from Source+C
if A=B
Found = %
Break
else
Found = 0
end if
end repeat
end if
if ~Found
load A fword from Source+C
store fword A at Vals:+CntItems*EleSize+C
dw (CntItems)*EleSize
CntItems = CntItems+1
else
dw (Found-1)*EleSize
end if
}
macro CpyElements Dst
{
local A
Dst rb CntItems*EleSize
repeat CntItems
load A fword from Vals:(%-1)*EleSize
store fword A at Dst+(%-1)*EleSize
end repeat
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,194 @@
; flat assembler core
; Copyright (c) 1999-2019, Tomasz Grysztar.
; All rights reserved.
out_of_memory:
push _out_of_memory
jmp fatal_error
stack_overflow:
push _stack_overflow
jmp fatal_error
main_file_not_found:
push _main_file_not_found
jmp fatal_error
write_failed:
push _write_failed
jmp fatal_error
unexpected_end_of_file:
push _unexpected_end_of_file
jmp general_error
code_cannot_be_generated:
push _code_cannot_be_generated
jmp general_error
format_limitations_exceeded:
push _format_limitations_exceeded
jmp general_error
invalid_definition:
push _invalid_definition
general_error:
cmp [symbols_file],0
je fatal_error
call dump_preprocessed_source
jmp fatal_error
file_not_found:
push _file_not_found
jmp error_with_source
error_reading_file:
push _error_reading_file
jmp error_with_source
invalid_file_format:
push _invalid_file_format
jmp error_with_source
invalid_macro_arguments:
push _invalid_macro_arguments
jmp error_with_source
incomplete_macro:
push _incomplete_macro
jmp error_with_source
unexpected_characters:
push _unexpected_characters
jmp error_with_source
invalid_argument:
push _invalid_argument
jmp error_with_source
illegal_instruction:
push _illegal_instruction
jmp error_with_source
invalid_operand:
push _invalid_operand
jmp error_with_source
invalid_operand_size:
push _invalid_operand_size
jmp error_with_source
operand_size_not_specified:
push _operand_size_not_specified
jmp error_with_source
operand_sizes_do_not_match:
push _operand_sizes_do_not_match
jmp error_with_source
invalid_address_size:
push _invalid_address_size
jmp error_with_source
address_sizes_do_not_agree:
push _address_sizes_do_not_agree
jmp error_with_source
disallowed_combination_of_registers:
push _disallowed_combination_of_registers
jmp error_with_source
long_immediate_not_encodable:
push _long_immediate_not_encodable
jmp error_with_source
relative_jump_out_of_range:
push _relative_jump_out_of_range
jmp error_with_source
invalid_expression:
push _invalid_expression
jmp error_with_source
invalid_address:
push _invalid_address
jmp error_with_source
invalid_value:
push _invalid_value
jmp error_with_source
value_out_of_range:
push _value_out_of_range
jmp error_with_source
undefined_symbol:
mov edi,message
mov esi,_undefined_symbol
call copy_asciiz
push message
cmp [error_info],0
je error_with_source
mov esi,[error_info]
mov esi,[esi+24]
or esi,esi
jz error_with_source
mov byte [edi-1],20h
call write_quoted_symbol_name
jmp error_with_source
copy_asciiz:
lods byte [esi]
stos byte [edi]
test al,al
jnz copy_asciiz
ret
write_quoted_symbol_name:
mov al,27h
stosb
movzx ecx,byte [esi-1]
rep movs byte [edi],[esi]
mov ax,27h
stosw
ret
symbol_out_of_scope:
mov edi,message
mov esi,_symbol_out_of_scope_1
call copy_asciiz
cmp [error_info],0
je finish_symbol_out_of_scope_message
mov esi,[error_info]
mov esi,[esi+24]
or esi,esi
jz finish_symbol_out_of_scope_message
mov byte [edi-1],20h
call write_quoted_symbol_name
finish_symbol_out_of_scope_message:
mov byte [edi-1],20h
mov esi,_symbol_out_of_scope_2
call copy_asciiz
push message
jmp error_with_source
invalid_use_of_symbol:
push _invalid_use_of_symbol
jmp error_with_source
name_too_long:
push _name_too_long
jmp error_with_source
invalid_name:
push _invalid_name
jmp error_with_source
reserved_word_used_as_symbol:
push _reserved_word_used_as_symbol
jmp error_with_source
symbol_already_defined:
push _symbol_already_defined
jmp error_with_source
missing_end_quote:
push _missing_end_quote
jmp error_with_source
missing_end_directive:
push _missing_end_directive
jmp error_with_source
unexpected_instruction:
push _unexpected_instruction
jmp error_with_source
extra_characters_on_line:
push _extra_characters_on_line
jmp error_with_source
section_not_aligned_enough:
push _section_not_aligned_enough
jmp error_with_source
setting_already_specified:
push _setting_already_specified
jmp error_with_source
data_already_defined:
push _data_already_defined
jmp error_with_source
too_many_repeats:
push _too_many_repeats
jmp error_with_source
assertion_failed:
push _assertion_failed
jmp error_with_source
invoked_error:
push _invoked_error
error_with_source:
cmp [symbols_file],0
je assembler_error
call dump_preprocessed_source
call restore_preprocessed_source
jmp assembler_error

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,155 @@
use32
open: cmp edx,input_magic
jne fail
mov ebx,[edx]
ret
close: cmp ebx,[input_magic]
jne fail
xor ebx,ebx ;CF=0
ret
lseek: cmp ebx,[input_magic]
jne fail
cmp al,2
je .end
cmp al,1
je .pos
cmp al,0
jne fail
.str:
mov eax,edx
cmp eax,[input_size]
ja fail
jmp .ok
.end:
mov eax,[input_size]
neg edx
add eax,edx
jc fail
.ok:
mov [input_start],eax
clc
ret
.pos:
mov eax,[input_start]
add eax,edx
cmp eax,[input_size]
ja fail
jmp .ok
read: cmp ebx,[input_magic]
jne fail
push esi edi
mov esi,[input_start]
add esi,[input_code]
mov eax,[input_size]
mov edi,edx
cmp eax,ecx
jnc skip
mov ecx,eax
skip: mov eax,ecx
add [input_start],eax
shr ecx,2
cld
rep movsd
mov cl,al
and cl,3
rep movsb
pop edi esi
clc
ret
write: ;not implemented
create: ;not implemented
fail: stc
ret
make_timestamp:
xor eax,eax ;not implemented
get_environment_variable: ;not implemented
display_block: ;not implemented
ret
assembler_error: fatal_error:
pop [output_errs]
stc
jmp stack_restore
Assemble:
xor eax,eax
mov [output_errs],eax
mov [output_size],eax
mov [input_start],eax
mov [input_file],input_magic
mov [input_size],ecx
mov [input_code],esi
mov [input_stack],esp
mov [memory_start],StdMemStr
mov [memory_end],StdMemEnd
mov [additional_memory],AddMemStr
mov [additional_memory_end],AddMemEnd
lea eax,[esp-4*1024]
mov [stack_limit],eax
call preprocessor
call parser
call assembler
mov esi,[code_start]
mov ecx,edi
sub ecx,esi
mov eax,256
cmp ecx,eax
jna max_256
mov ecx,eax
max_256:
mov [output_size],ecx
mov edi,output_data
rep movsb
stack_restore:
mov esp,[input_stack]
mov esi,[output_errs]
ret
include 'fasm\version.inc'
include 'fasm\errors.inc'
include 'fasm\symbdump.inc'
include 'fasm\preproce.inc'
include 'fasm\parser.inc'
include 'fasm\exprpars.inc'
include 'fasm\assemble.inc'
include 'fasm\exprcalc.inc'
include 'fasm\formats.inc'
include 'fasm\x86_64.inc'
include 'fasm\avx.inc'
include 'fasm\tables.inc'
include 'fasm\messages.inc'
iglobal
input_magic dd 55AA55AAh
endg
uglobal
input_code dd ?
input_size dd ?
input_start dd ?
input_stack dd ?
output_size dd ?
output_errs dd ?
output_data rb 256
include 'fasm\variable.inc'
endg

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
; flat assembler core
; Copyright (c) 1999-2019, Tomasz Grysztar.
; All rights reserved.
_out_of_memory db 'out of memory',0
_stack_overflow db 'out of stack space',0
_main_file_not_found db 'source file not found',0
_unexpected_end_of_file db 'unexpected end of file',0
_code_cannot_be_generated db 'code cannot be generated',0
_format_limitations_exceeded db 'format limitations exceeded',0
_invalid_definition db 'invalid definition provided',0
_write_failed db 'write failed',0
_file_not_found db 'file not found',0
_error_reading_file db 'error reading file',0
_invalid_file_format db 'invalid file format',0
_invalid_macro_arguments db 'invalid macro arguments',0
_incomplete_macro db 'incomplete macro',0
_unexpected_characters db 'unexpected characters',0
_invalid_argument db 'invalid argument',0
_illegal_instruction db 'illegal instruction',0
_invalid_operand db 'invalid operand',0
_invalid_operand_size db 'invalid size of operand',0
_operand_size_not_specified db 'operand size not specified',0
_operand_sizes_do_not_match db 'operand sizes do not match',0
_invalid_address_size db 'invalid size of address value',0
_address_sizes_do_not_agree db 'address sizes do not agree',0
_disallowed_combination_of_registers db 'disallowed combination of registers',0
_long_immediate_not_encodable db 'not encodable with long immediate',0
_relative_jump_out_of_range db 'relative jump out of range',0
_invalid_expression db 'invalid expression',0
_invalid_address db 'invalid address',0
_invalid_value db 'invalid value',0
_value_out_of_range db 'value out of range',0
_undefined_symbol db 'undefined symbol',0
_symbol_out_of_scope_1 db 'symbol',0
_symbol_out_of_scope_2 db 'out of scope',0
_invalid_use_of_symbol db 'invalid use of symbol',0
_name_too_long db 'name too long',0
_invalid_name db 'invalid name',0
_reserved_word_used_as_symbol db 'reserved word used as symbol',0
_symbol_already_defined db 'symbol already defined',0
_missing_end_quote db 'missing end quote',0
_missing_end_directive db 'missing end directive',0
_unexpected_instruction db 'unexpected instruction',0
_extra_characters_on_line db 'extra characters on line',0
_section_not_aligned_enough db 'section is not aligned enough',0
_setting_already_specified db 'setting already specified',0
_data_already_defined db 'data already defined',0
_too_many_repeats db 'too many repeats',0
_invoked_error db 'error directive encountered in source file',0
_assertion_failed db 'assertion failed',0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,450 @@
; flat assembler core
; Copyright (c) 1999-2019, Tomasz Grysztar.
; All rights reserved.
dump_symbols:
mov edi,[code_start]
call setup_dump_header
mov esi,[input_file]
call copy_asciiz
cmp edi,[tagged_blocks]
jae out_of_memory
mov eax,edi
sub eax,ebx
mov [ebx-40h+0Ch],eax
mov esi,[output_file]
call copy_asciiz
cmp edi,[tagged_blocks]
jae out_of_memory
mov edx,[symbols_stream]
mov ebp,[free_additional_memory]
and [number_of_sections],0
cmp [output_format],4
je prepare_strings_table
cmp [output_format],5
jne strings_table_ready
bt [format_flags],0
jc strings_table_ready
prepare_strings_table:
cmp edx,ebp
je strings_table_ready
mov al,[edx]
test al,al
jz prepare_string
cmp al,80h
je prepare_string
add edx,0Ch
cmp al,0C0h
jb prepare_strings_table
add edx,4
jmp prepare_strings_table
prepare_string:
mov esi,edi
sub esi,ebx
xchg esi,[edx+4]
test al,al
jz prepare_section_string
or dword [edx+4],1 shl 31
add edx,0Ch
prepare_external_string:
mov ecx,[esi]
add esi,4
rep movs byte [edi],[esi]
mov byte [edi],0
inc edi
cmp edi,[tagged_blocks]
jae out_of_memory
jmp prepare_strings_table
prepare_section_string:
mov ecx,[number_of_sections]
mov eax,ecx
inc eax
mov [number_of_sections],eax
xchg eax,[edx+4]
shl ecx,2
add ecx,[free_additional_memory]
mov [ecx],eax
add edx,20h
test esi,esi
jz prepare_default_section_string
cmp [output_format],5
jne prepare_external_string
bt [format_flags],0
jc prepare_external_string
mov esi,[esi]
add esi,[resource_data]
copy_elf_section_name:
lods byte [esi]
cmp edi,[tagged_blocks]
jae out_of_memory
stos byte [edi]
test al,al
jnz copy_elf_section_name
jmp prepare_strings_table
prepare_default_section_string:
mov eax,'.fla'
stos dword [edi]
mov ax,'t'
stos word [edi]
cmp edi,[tagged_blocks]
jae out_of_memory
jmp prepare_strings_table
strings_table_ready:
mov edx,[tagged_blocks]
mov ebp,[memory_end]
sub ebp,[labels_list]
add ebp,edx
prepare_labels_dump:
cmp edx,ebp
je labels_dump_ok
mov eax,[edx+24]
test eax,eax
jz label_dump_name_ok
cmp eax,[memory_start]
jb label_name_outside_source
cmp eax,[source_start]
ja label_name_outside_source
sub eax,[memory_start]
dec eax
mov [edx+24],eax
jmp label_dump_name_ok
label_name_outside_source:
mov esi,eax
mov eax,edi
sub eax,ebx
or eax,1 shl 31
mov [edx+24],eax
movzx ecx,byte [esi-1]
lea eax,[edi+ecx+1]
cmp edi,[tagged_blocks]
jae out_of_memory
rep movsb
xor al,al
stosb
label_dump_name_ok:
mov eax,[edx+28]
test eax,eax
jz label_dump_line_ok
sub eax,[memory_start]
mov [edx+28],eax
label_dump_line_ok:
test byte [edx+9],4
jz convert_base_symbol_for_label
xor eax,eax
mov [edx],eax
mov [edx+4],eax
jmp base_symbol_for_label_ok
convert_base_symbol_for_label:
mov eax,[edx+20]
test eax,eax
jz base_symbol_for_label_ok
cmp eax,[symbols_stream]
mov eax,[eax+4]
jae base_symbol_for_label_ok
xor eax,eax
base_symbol_for_label_ok:
mov [edx+20],eax
mov ax,[current_pass]
cmp ax,[edx+16]
je label_defined_flag_ok
and byte [edx+8],not 1
label_defined_flag_ok:
cmp ax,[edx+18]
je label_used_flag_ok
and byte [edx+8],not 8
label_used_flag_ok:
add edx,LABEL_STRUCTURE_SIZE
jmp prepare_labels_dump
labels_dump_ok:
mov eax,edi
sub eax,ebx
mov [ebx-40h+14h],eax
add eax,40h
mov [ebx-40h+18h],eax
mov ecx,[memory_end]
sub ecx,[labels_list]
mov [ebx-40h+1Ch],ecx
add eax,ecx
mov [ebx-40h+20h],eax
mov ecx,[source_start]
sub ecx,[memory_start]
mov [ebx-40h+24h],ecx
add eax,ecx
mov [ebx-40h+28h],eax
mov eax,[number_of_sections]
shl eax,2
mov [ebx-40h+34h],eax
call prepare_preprocessed_source
mov esi,[labels_list]
mov ebp,edi
make_lines_dump:
cmp esi,[tagged_blocks]
je lines_dump_ok
mov eax,[esi-4]
mov ecx,[esi-8]
sub esi,8
sub esi,ecx
cmp eax,1
je process_line_dump
cmp eax,2
jne make_lines_dump
add dword [ebx-40h+3Ch],8
jmp make_lines_dump
process_line_dump:
push ebx
mov ebx,[esi+8]
mov eax,[esi+4]
sub eax,[code_start]
add eax,[headers_size]
test byte [ebx+0Ah],1
jz store_offset
xor eax,eax
store_offset:
stos dword [edi]
mov eax,[esi]
sub eax,[memory_start]
stos dword [edi]
mov eax,[esi+4]
xor edx,edx
xor cl,cl
sub eax,[ebx]
sbb edx,[ebx+4]
sbb cl,[ebx+8]
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[ebx+10h]
stos dword [edi]
mov eax,[ebx+14h]
test eax,eax
jz base_symbol_for_line_ok
cmp eax,[symbols_stream]
mov eax,[eax+4]
jae base_symbol_for_line_ok
xor eax,eax
base_symbol_for_line_ok:
stos dword [edi]
mov al,[ebx+9]
stos byte [edi]
mov al,[esi+10h]
stos byte [edi]
mov al,[ebx+0Ah]
and al,1
stos byte [edi]
mov al,cl
stos byte [edi]
pop ebx
cmp edi,[tagged_blocks]
jae out_of_memory
mov eax,edi
sub eax,1Ch
sub eax,ebp
mov [esi],eax
jmp make_lines_dump
lines_dump_ok:
mov edx,edi
mov eax,[current_offset]
sub eax,[code_start]
add eax,[headers_size]
stos dword [edi]
mov ecx,edi
sub ecx,ebx
sub ecx,[ebx-40h+14h]
mov [ebx-40h+2Ch],ecx
add ecx,[ebx-40h+28h]
mov [ebx-40h+30h],ecx
add ecx,[ebx-40h+34h]
mov [ebx-40h+38h],ecx
find_inexisting_offsets:
sub edx,1Ch
cmp edx,ebp
jb write_symbols
test byte [edx+1Ah],1
jnz find_inexisting_offsets
cmp eax,[edx]
jb correct_inexisting_offset
mov eax,[edx]
jmp find_inexisting_offsets
correct_inexisting_offset:
and dword [edx],0
or byte [edx+1Ah],2
jmp find_inexisting_offsets
write_symbols:
mov edx,[symbols_file]
call create
jc write_failed
mov edx,[code_start]
mov ecx,[edx+14h]
add ecx,40h
call write
jc write_failed
mov edx,[tagged_blocks]
mov ecx,[memory_end]
sub ecx,[labels_list]
call write
jc write_failed
mov edx,[memory_start]
mov ecx,[source_start]
sub ecx,edx
call write
jc write_failed
mov edx,ebp
mov ecx,edi
sub ecx,edx
call write
jc write_failed
mov edx,[free_additional_memory]
mov ecx,[number_of_sections]
shl ecx,2
call write
jc write_failed
mov esi,[labels_list]
mov edi,[memory_start]
make_references_dump:
cmp esi,[tagged_blocks]
je references_dump_ok
mov eax,[esi-4]
mov ecx,[esi-8]
sub esi,8
sub esi,ecx
cmp eax,2
je dump_reference
cmp eax,1
jne make_references_dump
mov edx,[esi]
jmp make_references_dump
dump_reference:
mov eax,[memory_end]
sub eax,[esi]
sub eax,LABEL_STRUCTURE_SIZE
stosd
mov eax,edx
stosd
cmp edi,[tagged_blocks]
jb make_references_dump
jmp out_of_memory
references_dump_ok:
mov edx,[memory_start]
mov ecx,edi
sub ecx,edx
call write
jc write_failed
call close
ret
setup_dump_header:
xor eax,eax
mov ecx,40h shr 2
rep stos dword [edi]
mov ebx,edi
mov dword [ebx-40h],'fas'+1Ah shl 24
mov dword [ebx-40h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 40h shl 16
mov dword [ebx-40h+10h],40h
ret
prepare_preprocessed_source:
mov esi,[memory_start]
mov ebp,[source_start]
test ebp,ebp
jnz prepare_preprocessed_line
mov ebp,[current_line]
inc ebp
prepare_preprocessed_line:
cmp esi,ebp
jae preprocessed_source_ok
mov eax,[memory_start]
mov edx,[input_file]
cmp [esi],edx
jne line_not_from_main_input
mov [esi],eax
line_not_from_main_input:
sub [esi],eax
test byte [esi+7],1 shl 7
jz prepare_next_preprocessed_line
sub [esi+8],eax
sub [esi+12],eax
prepare_next_preprocessed_line:
call skip_preprocessed_line
jmp prepare_preprocessed_line
preprocessed_source_ok:
ret
skip_preprocessed_line:
add esi,16
skip_preprocessed_line_content:
lods byte [esi]
cmp al,1Ah
je skip_preprocessed_symbol
cmp al,3Bh
je skip_preprocessed_symbol
cmp al,22h
je skip_preprocessed_string
or al,al
jnz skip_preprocessed_line_content
ret
skip_preprocessed_string:
lods dword [esi]
add esi,eax
jmp skip_preprocessed_line_content
skip_preprocessed_symbol:
lods byte [esi]
movzx eax,al
add esi,eax
jmp skip_preprocessed_line_content
restore_preprocessed_source:
mov esi,[memory_start]
mov ebp,[source_start]
test ebp,ebp
jnz restore_preprocessed_line
mov ebp,[current_line]
inc ebp
restore_preprocessed_line:
cmp esi,ebp
jae preprocessed_source_restored
mov eax,[memory_start]
add [esi],eax
cmp [esi],eax
jne preprocessed_line_source_restored
mov edx,[input_file]
mov [esi],edx
preprocessed_line_source_restored:
test byte [esi+7],1 shl 7
jz restore_next_preprocessed_line
add [esi+8],eax
add [esi+12],eax
restore_next_preprocessed_line:
call skip_preprocessed_line
jmp restore_preprocessed_line
preprocessed_source_restored:
ret
dump_preprocessed_source:
mov edi,[free_additional_memory]
call setup_dump_header
mov esi,[input_file]
call copy_asciiz
cmp edi,[additional_memory_end]
jae out_of_memory
mov eax,edi
sub eax,ebx
dec eax
mov [ebx-40h+0Ch],eax
mov eax,edi
sub eax,ebx
mov [ebx-40h+14h],eax
add eax,40h
mov [ebx-40h+20h],eax
call prepare_preprocessed_source
sub esi,[memory_start]
mov [ebx-40h+24h],esi
mov edx,[symbols_file]
call create
jc write_failed
mov edx,[free_additional_memory]
mov ecx,[edx+14h]
add ecx,40h
call write
jc write_failed
mov edx,[memory_start]
mov ecx,esi
call write
jc write_failed
call close
ret

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,155 @@
; flat assembler core variables
; Copyright (c) 1999-2019, Tomasz Grysztar.
; All rights reserved.
; Variables which have to be set up by interface:
memory_start dd ?
memory_end dd ?
additional_memory dd ?
additional_memory_end dd ?
stack_limit dd ?
initial_definitions dd ?
input_file dd ?
output_file dd ?
symbols_file dd ?
passes_limit dw ?
; Internal core variables:
current_pass dw ?
include_paths dd ?
free_additional_memory dd ?
source_start dd ?
code_start dd ?
code_size dd ?
real_code_size dd ?
written_size dd ?
headers_size dd ?
current_line dd ?
macro_line dd ?
macro_block dd ?
macro_block_line dd ?
macro_block_line_number dd ?
macro_symbols dd ?
struc_name dd ?
struc_label dd ?
instant_macro_start dd ?
parameters_end dd ?
default_argument_value dd ?
locals_counter rb 8
current_locals_prefix dd ?
anonymous_reverse dd ?
anonymous_forward dd ?
labels_list dd ?
label_hash dd ?
label_leaf dd ?
hash_tree dd ?
addressing_space dd ?
undefined_data_start dd ?
undefined_data_end dd ?
counter dd ?
counter_limit dd ?
error_info dd ?
error_line dd ?
error dd ?
tagged_blocks dd ?
structures_buffer dd ?
number_start dd ?
current_offset dd ?
value dq ?
fp_value rd 8
adjustment dq ?
symbol_identifier dd ?
address_symbol dd ?
address_high dd ?
uncompressed_displacement dd ?
format_flags dd ?
resolver_flags dd ?
symbols_stream dd ?
number_of_relocations dd ?
number_of_sections dd ?
stub_size dd ?
stub_file dd ?
current_section dd ?
machine dw ?
subsystem dw ?
subsystem_version dd ?
image_base dd ?
image_base_high dd ?
merge_segment dd ?
resource_data dd ?
resource_size dd ?
actual_fixups_size dd ?
reserved_fixups dd ?
reserved_fixups_size dd ?
last_fixup_base dd ?
last_fixup_header dd ?
parenthesis_stack dd ?
blocks_stack dd ?
parsed_lines dd ?
logical_value_parentheses dd ?
file_extension dd ?
operand_size db ?
operand_flags db ?
operand_prefix db ?
rex_prefix db ?
opcode_prefix db ?
vex_required db ?
vex_register db ?
immediate_size db ?
mask_register db ?
broadcast_size db ?
rounding_mode db ?
base_code db ?
extended_code db ?
supplemental_code db ?
postbyte_register db ?
segment_register db ?
xop_opcode_map db ?
mmx_size db ?
jump_type db ?
push_size db ?
value_size db ?
address_size db ?
label_size db ?
size_declared db ?
address_size_declared db ?
displacement_compression db ?
value_undefined db ?
value_constant db ?
value_type db ?
value_sign db ?
fp_sign db ?
fp_format db ?
address_sign db ?
address_register db ?
compare_type db ?
logical_value_wrapping db ?
next_pass_needed db ?
output_format db ?
code_type db ?
adjustment_sign db ?
evex_mode db ?
macro_status db ?
skip_default_argument_value db ?
prefix_flags db ?
formatter_symbols_allowed db ?
decorator_symbols_allowed db ?
free_address_range db ?
characters rb 100h
converted rb 100h
message rb 180h

View File

@ -0,0 +1,39 @@
; flat assembler version 1.73
; Copyright (c) 1999-2019, Tomasz Grysztar.
; All rights reserved.
;
; This programs is free for commercial and non-commercial use as long as
; the following conditions are adhered to.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are
; met:
;
; 1. Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
; The licence and distribution terms for any publically available
; version or derivative of this code cannot be changed. i.e. this code
; cannot simply be copied and put under another distribution licence
; (including the GNU Public Licence).
VERSION_STRING equ "1.73.21"
VERSION_MAJOR = 1
VERSION_MINOR = 73

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
fontname equ 'font8x9.bmp'
virtual at 0
file fontname,3Eh
; sanity check
load a1 word from 0
load a2 dword from 0xE
if (a1 <> 'BM') | (a2 <> 0x28)
error 'not BMP file!'
end if
load a1 dword from 0x12
load a2 dword from 0x16
if (a1 and 0xF) | (a2 and 0xF) | (a1 > 16*16)
error 'font: invalid width or height'
end if
FontWidth = a1 shr 4
font_bmp_scanline = (FontWidth*2 + 3) and not 3
FontHeight = a2 shr 4
load a1 dword from 0x1A
if a1 <> 0x10001
error 'font: not monochrome bitmap'
end if
end virtual
Font:
macro set_name_test a,b
{
if %=a
font_data_#a = b
end if
}
macro set_name b
{
set_name_test 1,b
set_name_test 2,b
set_name_test 3,b
set_name_test 4,b
set_name_test 5,b
set_name_test 6,b
set_name_test 7,b
set_name_test 8,b
set_name_test 9,b
set_name_test 10,b
set_name_test 11,b
set_name_test 12,b
set_name_test 13,b
set_name_test 14,b
set_name_test 15,b
set_name_test 16,b
}
macro db_name_test a
{
if %=a
db font_data_#a
end if
}
macro db_name
{
db_name_test 1
db_name_test 2
db_name_test 3
db_name_test 4
db_name_test 5
db_name_test 6
db_name_test 7
db_name_test 8
db_name_test 9
db_name_test 10
db_name_test 11
db_name_test 12
db_name_test 13
db_name_test 14
db_name_test 15
db_name_test 16
}
macro dw_name_test a
{
if %=a
dw font_data_#a
end if
}
macro dw_name
{
dw_name_test 1
dw_name_test 2
dw_name_test 3
dw_name_test 4
dw_name_test 5
dw_name_test 6
dw_name_test 7
dw_name_test 8
dw_name_test 9
dw_name_test 10
dw_name_test 11
dw_name_test 12
dw_name_test 13
dw_name_test 14
dw_name_test 15
dw_name_test 16
}
repeat FontHeight
cur_scan = %
repeat 16
virtual at 0
file fontname:3Eh + font_bmp_scanline*(FontHeight*(17-%)-cur_scan),FontWidth*2
dd 0
repeat 16
load a1 dword from ((%-1)*FontWidth) shr 3
a1 = ((a1 and 0x55555555) shl 1) or ((a1 and 0xAAAAAAAA) shr 1)
a1 = ((a1 and 0x33333333) shl 2) or ((a1 and 0xCCCCCCCC) shr 2)
a1 = ((a1 and 0x0F0F0F0F) shl 4) or ((a1 and 0xF0F0F0F0) shr 4)
a1 = (a1 shr (((%-1)*FontWidth) and 7)) and ((1 shl FontWidth) - 1)
a1 = a1 xor ((1 shl FontWidth) - 1)
set_name a1
end repeat
end virtual
if FontWidth > 8
repeat 16
dw_name
end repeat
else
repeat 16
db_name
end repeat
end if
end repeat
end repeat
purge set_name_test
purge db_name_test
purge dw_name_test
purge set_name
purge db_name
purge dw_name

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,118 @@
macro forward_list_builder name {
local c
macro .#name a& \{
\local m
c equ m
macro m a
\}
macro name#List \{
irpv v,c \\{
;\\forward
v
\\}
\}
}
macro reverse_list_builder name {
local c
macro .#name a& \{
\local m
c equ m
macro m a
\}
macro name#List \{
irpv v,c \\{
\\reverse
v
\\}
\}
}
forward_list_builder IGlobalBlock
forward_list_builder SGlobalBlock
forward_list_builder TGlobalBlock
forward_list_builder UGlobalBlock
forward_list_builder VGlobalBlock
forward_list_builder XGlobalBlock
;------------------------------------------------------------------
; use "tglobal" for inserting TLS definitions.
;------------------------------------------------------------------
macro tglobal {
.TGlobalBlock { }
macro tglobal_nested {
.TGlobalBlock \{ }
;------------------------------------------------------------------
; use "vglobal" for inserting virtual definitions.
;------------------------------------------------------------------
macro vglobal {
.VGlobalBlock { }
macro vglobal_nested {
.VGlobalBlock \{ }
;------------------------------------------------------------------
; use "iglobal" for inserting initialized global data definitions.
;------------------------------------------------------------------
macro iglobal {
.IGlobalBlock { }
macro iglobal_nested {
.IGlobalBlock \{ }
;------------------------------------------------------------------
; use "sglobal" for inserting strings definitions.
;------------------------------------------------------------------
macro sglobal {
.SGlobalBlock { }
macro sglobal_nested {
.SGlobalBlock \{ }
;-------------------------------------------------------------
; use 'uglobal' for inserting uninitialized global definitions.
; even when you define some data values, these variables
; will be stored as uninitialized data.
;-------------------------------------------------------------
macro uglobal {
.UGlobalBlock { }
macro uglobal_nested {
.UGlobalBlock \{ }
;-------------------------------------------------------------
; use 'xglobal' for inserting uninitialized global definitions.
; even when you define some data values, these variables
; will be stored as uninitialized data.
;-------------------------------------------------------------
macro xglobal {
.XGlobalBlock { }
macro xglobal_nested {
.XGlobalBlock \{ }
endg fix } ; Use endg for ending iglobal and uglobal blocks.
endg_nested fix \}
macro IncludeGlobals MacroName
{
local Begin,Size
virtual at $
Begin = $
MacroName
Size = $-Begin
end virtual
rb Size
}
macro IncludeAllGlobals {
IGlobalBlockList
SGlobalBlockList
UDataStr:
IncludeGlobals UGlobalBlockList ;will be zeroed
UDataEnd:
IncludeGlobals XGlobalBlockList ;will be undefined
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,298 @@
; KolibriOS system functions:
SF_TERMINATE_PROCESS=-1
SF_CREATE_WINDOW=0 ; define and draw the window
SF_PUT_PIXEL=1 ; draw pixel to the window
SF_GET_KEY=2 ; get code of the pressed key
SF_GET_SYS_TIME=3
SF_DRAW_TEXT=4
SF_SLEEP=5 ; pause process
SF_PUT_IMAGE=7 ; draw image to the window
SF_DEFINE_BUTTON=8 ; define/delete the button
SF_THREAD_INFO=9 ; information on execution thread
SF_WAIT_EVENT=10 ; wait for event
SF_CHECK_EVENT=11 ; check for event and return
SF_REDRAW=12
SSF_BEGIN_DRAW=1
SSF_END_DRAW=2
SF_DRAW_RECT=13 ; draw rectangle to the window
SF_GET_SCREEN_SIZE=14 ; get screen resolution
SF_BACKGROUND_SET=15 ; work with desktop background graphics
SSF_SIZE_BG=1 ; set a size of the background image
SSF_PIXEL_BG=2 ; put pixel on the background image
SSF_REDRAW_BG=3 ; redraw background
SSF_MODE_BG=4 ; set drawing mode for the background
SSF_IMAGE_BG=5 ; put block of pixels on the background image
SSF_MAP_BG=6 ; map background image to the address space of the process
SSF_UNMAP_BG=7 ; close mapped background data
SSF_LAST_DRAW=8 ; get coordinates of the last draw to the background
SSF_REDRAW_RECT=9 ; redraws a rectangular part of the background
SF_RD_TO_FLOPPY=16 ; save ramdisk on the floppy
SF_GET_BUTTON=17 ; get ID of the pressed button
SF_SYSTEM=18
SSF_UNFOCUS_WINDOW=1 ; take focus from the window of the given thread
SSF_TERMINATE_THREAD=2 ; terminate process/thread by the slot number
SSF_FOCUS_WINDOW=3 ; give focus to the window of the given thread
SSF_GET_IDLE_COUNT=4 ; get counter of idle cycles per second
SSF_GET_CPU_FREQUENCY=5 ; get CPU clock rate
SSF_RD_TO_HDD=6 ; save ramdisk to the file on hard disk
SSF_GET_ACTIVE_WINDOW=7 ; get slot number of the active window
SSF_SPEAKER=8
SSSF_GET_STATE=1
SSSF_TOGGLE=2
SSF_SHUTDOWN=9 ; system shutdown/reboot
SSF_MINIMIZE_WINDOW=10 ; minimize active window
SSF_INFO_DISC_SYS=11 ; get disk subsystem information
SSF_KERNEL_VERSION=13 ; get kernel version
SSF_WAIT_RETRACE=14 ; wait for screen retrace
SSF_CURSOR_CENTER=15 ; center mouse cursor on the screen
SSF_GET_FREE_RAM=16 ; get size of free RAM
SSF_GET_TOTAL_RAM=17 ; get total amount of RAM
SSF_TERMINATE_THREAD_ID=18 ; Terminate process/thread by the ID
SSF_MOUSE_SETTINGS=19
SSSF_GET_SPEED=0
SSSF_SET_SPEED=1
SSSF_GET_SPEEDUP=2
SSSF_SET_SPEEDUP=3 ; set mouse acceleration
SSSF_SET_POS=4 ; set mouse pointer position
SSSF_SET_BUTTON=5 ; simulate state of mouse buttons
SSSF_GET_DOUBLE_CLICK_DELAY=6
SSSF_SET_DOUBLE_CLICK_DELAY=7
SSF_GET_RAM_INFO=20 ; get information on RAM
SSF_GET_THREAD_SLOT=21 ; get slot number of process/thread by the ID
SSF_FOREIGN_WINDOW=22 ; operations with window of another thread by slot/ID
SSSF_MINIMIZE=0
SSSF_MINIMIZE_ID=1
SSSF_RESTORE=2
SSSF_RESTORE_ID=3
SSF_MINIMIZE_ALL=23
SSF_SET_SCREEN_LIMITS=24
SSF_WINDOW_BEHAVIOR=25 ; window focus relation with other windows
SSSF_GET_WB=1
SSSF_SET_WB=2
SF_MIDI=20
SSF_RESET=1
SSF_OUTPUT=2
SF_SYSTEM_SET=21
SSF_MPU_MIDI_BASE=1
SSF_KEYBOARD_LAYOUT=2
SSF_SYS_LANG=5
SSF_ACCESS_HD_LBA=11 ; setting of low-level access to HD
SSF_ACCESS_PCI=12 ; setting of low-level access to PCI
SF_SET_TIME_DATE=22
SF_WAIT_EVENT_TIMEOUT=23; wait for event with timeout
SF_CD=24
SSF_EJECT_TRAY=4
SSF_INSERT_TRAY=5
SF_SCREEN_PUT_IMAGE=25 ; put image on the background layer
SF_SYSTEM_GET=26
; Same as SF_SYSTEM_SET, plus:
SSF_TIME_COUNT=9
SSF_TIME_COUNT_PRO=10 ; get value of the high precision time counter
SF_GET_SYS_DATE=29
SF_CURRENT_FOLDER=30
SSF_SET_CF=1 ; set current folder for the thread
SSF_GET_CF=2
SSF_ADD_SYS_FOLDER=3 ; install the add.system directory for the kernel
SF_GET_PIXEL_OWNER=34 ; get slot number of the screen pixel owner
SF_GET_PIXEL=35 ; read the screen pixel color
SF_GET_IMAGE=36 ; read the screen area
SF_MOUSE_GET=37
SSF_SCREEN_POSITION=0
SSF_WINDOW_POSITION=1
SSF_BUTTON=2 ; states of the mouse buttons
SSF_BUTTON_EXT=3 ; states and events of the mouse buttons
SSF_LOAD_CURSOR=4
SSF_SET_CURSOR=5
SSF_DEL_CURSOR=6
SSF_SCROLL_DATA=7
SF_DRAW_LINE=38
SF_BACKGROUND_GET=39
;SSF_SIZE_BG=1
;SSF_PIXEL_BG=2
;SSF_MODE_BG=4
SF_SET_EVENTS_MASK=40 ; turn on/off desired events
SF_PORT_IN_OUT=43 ; input/output to a port
SF_SET_PORTS=46 ; reserve/free a group of input/output ports
SF_DRAW_NUMBER=47 ; draw number to the window
SF_STYLE_SETTINGS=48
SSF_APPLY=0 ; apply screen settings
SSF_SET_BUTTON_STYLE=1
SSF_SET_COLORS=2
SSF_GET_COLORS=3 ; get standard window colors
SSF_GET_SKIN_HEIGHT=4
SSF_GET_SCREEN_AREA=5 ; get screen working area
SSF_SET_SCREEN_AREA=6
SSF_GET_SKIN_MARGINS=7
SSF_SET_SKIN=8
SSF_GET_FONT_SMOOTH=9
SSF_SET_FONT_SMOOTH=10
SSF_GET_FONT_SIZE=11
SSF_SET_FONT_SIZE=12
SF_APM=49
SF_SET_WINDOW_SHAPE=50
SF_CREATE_THREAD=51
SF_CLIPBOARD=54
SSF_GET_SLOT_COUNT=0 ; get the number of slots in the clipboard
SSF_READ_CB=1
SSF_WRITE_CB=2
SSF_DEL_SLOT=3 ; delete the last slot in the clipboard
SSF_UNLOCK_BUFFER=4 ; emergency buffer unlock
SF_SPEAKER_PLAY=55
SF_PCI_BIOS=57
SF_IPC=60 ; Inter Process Communication
SSF_SET_AREA=1 ; set area for IPC receiving
SSF_SEND_MESSAGE=2
SF_GET_GRAPHICAL_PARAMS=61
SSF_SCREEN_SIZE=1
SSF_BITS_PER_PIXEL=2
SSF_BYTES_PER_LINE=3
SF_PCI=62
SSF_GET_VERSION=0 ; get version of PCI-interface
SSF_GET_LAST_BUS=1 ; get number of the last PCI-bus
SSF_GET_ADRR_MODE=2 ; get addressing mode of the PCI configuration space
SSF_READ_BYTE=4
SSF_READ_WORD=5
SSF_READ_DWORD=6
SSF_WRITE_BYTE=8
SSF_WRITE_WORD=9
SSF_WRITE_DWORD=10
SF_BOARD=63
SSF_DEBUG_WRITE=1
SSF_DEBUG_READ=2
SF_MEMORY_RESIZE=64 ; resize total application memory
SF_PUT_IMAGE_EXT=65 ; draw image with palette to the window
SF_KEYBOARD=66
SSF_SET_INPUT_MODE=1
SSF_GET_INPUT_MODE=2
SSF_GET_CONTROL_KEYS=3; get status of control keys
SSF_SET_SYS_HOTKEY=4
SSF_DEL_SYS_HOTKEY=5
SSF_LOCK_INPUT=6 ; block normal input
SSF_UNLOCK_INPUT=7 ; restore normal input
SF_CHANGE_WINDOW=67 ; change position/sizes of the window
SF_SYS_MISC=68
SSF_GET_TASK_SWITCH_COUNT=0
SSF_SWITCH_TASK=1
SSF_PERFORMANCE=2
SSSF_ALLOW_RDPMC=0
SSSF_CACHE_STATUS=1
SSSF_CACHE_ON=2
SSSF_CACHE_OFF=3
SSF_READ_MSR=3
SSF_WRITE_MSR=4
SSF_HEAP_INIT=11
SSF_MEM_ALLOC=12
SSF_MEM_FREE=13
SSF_WAIT_SIGNAL=14 ; wait for signal from another program/driver
SSF_LOAD_DRIVER=16
SSF_CONTROL_DRIVER=17
SSF_LOAD_DLL=19
SSF_MEM_REALLOC=20
SSF_LOAD_DRIVER_PE=21
SSF_MEM_OPEN=22 ; open named memory area
SSF_MEM_CLOSE=23
SSF_SET_EXCEPTION_HANDLER=24
SSF_SET_EXCEPTION_STATE=25
SSF_MEM_FREE_EXT=26
SSF_LOAD_FILE=27
SF_DEBUG=69
SSF_SET_MESSAGE_AREA=0
SSF_GET_REGISTERS=1
SSF_SET_REGISTERS=2
SSF_DETACH=3
SSF_SUSPEND=4
SSF_RESUME=5
SSF_READ_MEMORY=6
SSF_WRITE_MEMORY=7
SSF_TERMINATE=8
SSF_DEFINE_BREAKPOINT=9
SF_FILE=70
SSF_READ_FILE=0
SSF_READ_FOLDER=1
SSF_CREATE_FILE=2
SSF_WRITE_FILE=3
SSF_SET_END=4
SSF_GET_INFO=5
SSF_SET_INFO=6
SSF_START_APP=7
SSF_DELETE=8
SSF_CREATE_FOLDER=9
SF_SET_CAPTION=71
SF_SEND_MESSAGE=72
SF_BLITTER=73
SF_NETWORK_DEVICE=74
SSF_DEVICE_COUNT=255 ; get number of active network devices
SSF_DEVICE_TYPE=0
SSF_DEVICE_NAME=1
SSF_RESET_DEVICE=2
SSF_STOP_DEVICE=3
SSF_DEVICE_POINTER=4
SSF_TX_PACKET_COUNT=6
SSF_RX_PACKET_COUNT=7
SSF_TX_BYTE_COUNT=8
SSF_RX_BYTE_COUNT=9
SSF_LINK_STATUS=10
SSF_TX_PACKET_ERROR_COUNT=11
SSF_TX_PACKET_DROP_COUNT=12
SSF_TX_PACKET_MISS_COUNT=13
SSF_RX_PACKET_ERROR_COUNT=14
SSF_RX_PACKET_DROP_COUNT=15
SSF_RX_PACKET_MISS_COUNT=16
SF_NETWORK_SOCKET=75
SSF_OPEN=0
SSF_CLOSE=1
SSF_BIND=2
SSF_LISTEN=3
SSF_CONNECT=4
SSF_ACCEPT=5
SSF_SEND=6
SSF_RECEIVE=7
SSF_SET_OPTIONS=8
SSF_GET_OPTIONS=9
SSF_SOCKET_PAIR=10
SF_NETWORK_PROTOCOL=76
SSF_ETHERNET_READ_MAC=0
SSF_IP4_PACKETS_SENT=10000h
SSF_IP4_PACKETS_RECEIVED=10001h
SSF_IP4_READ_IP=10002h
SSF_IP4_WRITE_IP=10003h
SSF_IP4_READ_DNS=10004h
SSF_IP4_WRITE_DNS=10005h
SSF_IP4_READ_SUBNET=10006h
SSF_IP4_WRITE_SUBNET=10007h
SSF_IP4_READ_GATEWAY=10008h
SSF_IP4_WRITE_GATEWAY=10009h
SSF_ICMP_PACKETS_SENT=20000h
SSF_ICMP_PACKETS_RECEIVED=20001h
SSF_ICMP_ECHO_REPLY=20003h
SSF_UDP_PACKETS_SENT=30000h
SSF_UDP_PACKETS_RECEIVED=30001h
SSF_TCP_PACKETS_SENT=40000h
SSF_TCP_PACKETS_RECEIVED=40001h
SSF_ARP_PACKETS_SENT=50000h
SSF_ARP_PACKETS_RECEIVED=50001h
SSF_ARP_GET_ENTRY_COUNT=50002h
SSF_ARP_READ_ENTRY=50003h
SSF_ARP_ADD_STATIC_ENTRY=50004h
SSF_ARP_DEL_ENTRY=50005h
SSF_ARP_SEND_ANNOUNCE=50006h
SSF_ARP_CONFLICTS_COUNT=50007h
SF_FUTEX=77
SSF_CREATE=0
SSF_DESTROY=1
SSF_WAIT=2
SSF_WAKE=3
; File system errors:
FSERR_SUCCESS=0
FSERR_UNSUPPORTED=2
FSERR_UNKNOWN=3
FSERR_FILE_NOT_FOUND=5
FSERR_END_OF_FILE=6
FSERR_INVALID_BUFFER=7
FSERR_DISK_FULL=8
FSERR_FAIL=9
FSERR_ACCESS_DENIED=10
FSERR_DEVICE_FAIL=11
FSERR_OUT_OF_MEMORY=12

View File

@ -0,0 +1,43 @@
uglobal
LastNames dq ?
ShowNames db ?
endg
FindEAX:push esi
and [LastNames],0
cmp [ShowNames],0
jnz .NoSymb
cmp eax,0x80
jl .NoSymb
lea esi,[eax-1]
test eax,esi
jz .NoSymb
call FindSymbol
jc .NoSymb
mov [LastNames],esi
cmp rdi,[TheBufferO]
jz .SetCol ;Skip starting address
push edi
@@:
lodsb
test al,al
jz @F
stosb
jmp @B
.SetCol:
mov [BufferO-1],byte 31h ;Label Color
.NoSymb:
stc
pop esi
ret
@@: mov ecx,edi
sub ecx,[esp]
cmp ecx,255
ifa mov ecx,255
pop edi
add edi,ecx
clc
pop esi
ret
include "symbols.inc"

View File

@ -0,0 +1 @@
fasm koldbg.asm koldbg

View File

@ -0,0 +1,120 @@
;-----------------------------------------------------------------------------
; Working with messages
; in: esi->ASCIIZ message
PutMessageNoDraw:
mov edx,[MessagesPos]
.M:
lea edi,[Messages+edx]
.L:
lodsb
cmp al,0
jz .Done
call TestScroll
cmp al,10
jz .NewLine
cmp al,'%'
jnz @F
cmp dword [esp],Z1
jnz .Format
@@:
stosb
inc edx
jmp .L
.NewLine:
push edx
mov ecx,MSG_WIDTH
xor eax,eax
xchg eax,edx
div ecx
xchg eax,edx
pop edx
test eax,eax
jz .M
sub edx,eax
add edx,ecx
jmp .M
.Done:
if 0
cmp byte [esi-2],10
jz .Exit
call TestScroll
if 1
push edx
mov ecx,MSG_WIDTH
xor eax,eax
xchg eax,edx
div ecx
xchg eax,edx
pop edx
test eax,eax
jz .Exit
sub edx,eax
add edx,ecx
end if
end if
.Exit:
mov [MessagesPos],edx
ret
; at this moment all format specs must be %<digit>X
.Format:
lodsb ; get <digit>
sub al,'0'
movzx ecx,al
lodsb
pop eax
pop ebp
push eax
; write number in ebp with ecx digits
dec ecx
shl ecx,2
.WriteNibble:
push ecx
call TestScroll
pop ecx
mov eax,ebp
shr eax,cl
and al,0xF
cmp al,10
sbb al,69h
das
stosb
inc edx
sub ecx,4
jns .WriteNibble
jmp .L
TestScroll:
cmp edx,MSG_WIDTH*MSG_HEIGHT
jnz .Ret
push esi
mov edi,Messages
lea esi,[edi+MSG_WIDTH]
mov ecx,(MSG_HEIGHT-1)*MSG_WIDTH/4
rep movsd
push eax
mov al,' '
push edi
push MSG_WIDTH
pop ecx
sub edx,ecx
rep stosb
pop edi
pop eax
pop esi
.Ret:
ret
MSG_WIDTH = DATA_WIDTH
MSG_HEIGHT = 14 ; in text lines
NewLine db 10,0
Prompt db '> ',0
uglobal
MessagesPos dd ?
Messages rb MSG_HEIGHT*MSG_WIDTH
endg

View File

@ -0,0 +1,396 @@
;-----------------------------------------------------------------------------
TokenEnd = 1
TokenReg = 2
TokenHex = 3
TokenOr = 4
TokenAnd = 5
TokenXor = 6
TokenAdd = 7
TokenSub = 8
TokenMul = 9
TokenDiv = 10
TokenLP = 11
TokenRP = 12
TokenErr = -1
;-----------------------------------------------------------------------------
RegTable:
db 2,'al',0
db 2,'cl',1
db 2,'dl',2
db 2,'bl',3
db 2,'ah',4
db 2,'ch',5
db 2,'dh',6
db 2,'bh',7
db 2,'ax',8
db 2,'cx',9
db 2,'dx',10
db 2,'bx',11
db 2,'sp',12
db 2,'bp',13
db 2,'si',14
db 2,'di',15
db 3,'eax',16
db 3,'ecx',17
db 3,'edx',18
db 3,'ebx',19
db 3,'esp',20
db 3,'ebp',21
db 3,'esi',22
db 3,'edi',23
db 3,'eip',24
db 0
;-----------------------------------------------------------------------------
; Check if byte is hex digit
IsHexDigit:
cmp al,'0'
jb .No
cmp al,'9'
jbe .09
cmp al,'A'
jb .No
cmp al,'F'
jbe .AF
cmp al,'a'
jb .No
cmp al,'f'
jbe .FA
.No:
stc
ret
.09:
sub al,'0'
; clc
ret
.AF:
sub al,'A'-10
; clc
ret
.FA:
sub al,'a'-10
; clc
ret
;-----------------------------------------------------------------------------
; Find register in the table
FindReg:
mov edi,RegTable
.FindReg:
movzx ecx,byte [edi]
stc
jecxz .RegNotFound
inc edi
push esi edi ecx
@@:
lodsb
or al,20h
scasb
loopz @B
pop ecx edi esi
lea edi,[edi+ecx+1]
jnz .FindReg
movzx edi,byte [edi-1]
add esi,ecx
.RegNotFound:
ret
;-----------------------------------------------------------------------------
; Tokenize expressions
ExprGetToken:
lodsb
cmp al,0
jz .EndToken
cmp al,' '
jbe ExprGetToken
cmp al,'|'
jz .Or
cmp al,'&'
jz .And
cmp al,'^'
jz .Xor
cmp al,'+'
jz .Add
cmp al,'-'
jz .Sub
cmp al,'*'
jz .Mul
cmp al,'/'
jz .Div
cmp al,'('
jz .LP
cmp al,')'
jnz .NotSign
.RP:
mov al,TokenRP
ret
.Or:
mov al,TokenOr
ret
.And:
mov al,TokenAnd
ret
.Xor:
mov al,TokenXor
ret
.Div:
mov al,TokenDiv
ret
.EndToken:
mov al,TokenEnd
ret
.Add:
mov al,TokenAdd
ret
.Sub:
mov al,TokenSub
ret
.Mul:
mov al,TokenMul
ret
.LP:
mov al,TokenLP
ret
.NotSign:
dec esi
call FindReg
jc .RegNotFound
mov al,TokenReg
ret
.RegNotFound:
; test for symbol
push esi
@@:
lodsb
cmp al,' '
ja @B
push eax
mov byte [esi],0
xchg esi,[esp+4]
call FindSymbolName
mov edi,eax
pop eax
xchg esi,[esp]
mov byte [esi],al
jc @F
add esp,4
mov al,TokenHex
ret
@@:
pop esi
; test for hex number
xor ecx,ecx
xor edi,edi
xor eax,eax
@@:
lodsb
call IsHexDigit
jc @F
shl edi,4
or edi,eax
inc ecx
jmp @B
@@:
dec esi
jecxz .Err
cmp ecx,8
ja .Err
mov al,TokenHex
ret
.Err:
mov al,TokenErr
mov esi,aParseError
ret
;-----------------------------------------------------------------------------
ExprRead2:
cmp al,TokenHex
jz .Hex
cmp al,TokenReg
jz .Reg
cmp al,TokenLP
jz .LP
mov al,TokenErr
mov esi,aParseError
ret
.Hex:
mov ebp,edi
.Ret:
jmp ExprGetToken
.Reg:
cmp edi,24
jz .EIP
sub edi,4
jb .8LO
sub edi,4
jb .8HI
sub edi,8
jb .16
mov ebp,[_EAX+edi*4]
jmp .Ret
.16:
movzx ebp,word [_EAX+(edi+8)*4]
jmp .Ret
.8LO:
movzx ebp,byte [_EAX+(edi+4)*4]
jmp .Ret
.8HI:
movzx ebp,byte [_EAX+(edi+4)*4+1]
jmp .Ret
.EIP:
mov ebp,[_EIP]
jmp .Ret
.LP:
call ExprGetToken
call ExprRead0
cmp al,TokenErr
jz @F
cmp al,TokenRP
jz ExprGetToken
mov al,TokenErr
mov esi,aParseError
@@:
ret
;-----------------------------------------------------------------------------
ExprRead1:
call ExprRead2
.1:
cmp al,TokenMul
jz .Mul
cmp al,TokenDiv
jz .Div
ret
.Mul:
push ebp
call ExprGetToken
call ExprRead2
pop edx
; ebp := edx*ebp
imul ebp,edx
jmp .1
.Div:
push ebp
call ExprGetToken
call ExprRead2
pop edx
; ebp := edx/ebp
test ebp,ebp
jz .Div0
push eax
xor eax,eax
xchg eax,edx
div ebp
xchg eax,ebp
pop eax
jmp .1
.Div0:
mov al,TokenErr
mov esi,aDivByZero
ret
;-----------------------------------------------------------------------------
ExprRead0:
xor ebp,ebp
cmp al,TokenOr
jz .Or
cmp al,TokenAnd
jz .And
cmp al,TokenXor
jz .Xor
cmp al,TokenAdd
jz .Add
cmp al,TokenSub
jz .Sub
call ExprRead1
.1:
cmp al,TokenOr
jz .Or
cmp al,TokenAnd
jz .And
cmp al,TokenXor
jz .Xor
cmp al,TokenAdd
jz .Add
cmp al,TokenSub
jz .Sub
ret
.Or:
push ebp
call ExprGetToken
call ExprRead1
pop edx
; ebp := edx | ebp
or ebp,edx
jmp .1
.And:
push ebp
call ExprGetToken
call ExprRead1
pop edx
; ebp := edx & ebp
and ebp,edx
jmp .1
.Xor:
push ebp
call ExprGetToken
call ExprRead1
pop edx
; ebp := edx ^ ebp
xor ebp,edx
jmp .1
.Add:
push ebp
call ExprGetToken
call ExprRead1
pop edx
; ebp := edx+ebp
add ebp,edx
jmp .1
.Sub:
push ebp
call ExprGetToken
call ExprRead1
pop edx
; ebp := edx-ebp
xchg edx,ebp
sub ebp,edx
jmp .1
;-----------------------------------------------------------------------------
; in: esi->expression
; out: CF=1 if error
; CF=0 and ebp=value if ok
CalcExpression:
call ExprGetToken
call ExprRead0
cmp al,TokenEnd
jz .End
cmp al,TokenErr
jz @F
mov esi,aParseError
@@:
call PutMessage
stc
ret
.End:
clc
ret
GetArg:
lodsb
cmp al,' '
ja GetArg
mov byte [esi-1],0
cmp al,0
jnz .SkipSpaces
dec esi
.SkipSpaces:
lodsb
cmp al,0
jz @F
cmp al,' '
jbe .SkipSpaces
@@:
dec esi
ret

View File

@ -0,0 +1,119 @@
Введение.
koldbg представляет собой интерактивный отладчик для операционной системы KolibriOS. Автор программы - Евгений Гречников (Diamond). Данная документация описывает возможности отладчика и работу с ним. Если у вас есть какие-либо вопросы по работе с программой или нужны какие-то возможности отладчика, которых ещё нет, обращайтесь на форум board.kolibrios.org в соответствующую тему - http://board.kolibrios.org/viewtopic.php?f=45&t=358, или по адресу автора - mailto:diamondz@land.ru.
Общее описание.
В каждый момент времени koldbg может отлаживать только одну программу. Назовём такую программу загруженной для отладки. Если никакая программа не загружена, абсолютное большинство действий по отладке недоступно.
koldbg управляется командной строкой, вводимой с клавиатуры. Командная строка изображается в нижней части окна отладчика. Обрабатываются стандартные клавиши ввода Backspace, Delete, Home, End, стрелки влево/вправо, стрелки вверх/вниз (прокручивание истории команд). Команды нечувствительны к регистру символов. В качестве разделителя используется произвольное ненулевое число пробелов.
В любой момент отладчик можно завершить командой "quit" (без аргументов). Впрочем, можно и просто нажать на кнопку закрытия в правом верхнем углу окна.
Запуск отладчика без параметров командной строки приводит к тому, что никакая программа не загружена. Также koldbg можно запускать с командной
строкой, в этом случае он попытается загрузить программу с именем, указанным как первый аргумент командной строки, и параметрами, указанными как
последующие (если они есть).
Если никакая программа не загружена, то можно загрузить программу командой load:
load <полное имя исполняемого файла> [<аргументы>]
Например:
load /rd/1/example
LOAD /rd/1/aclock w200 h200
LoaD /hd0/1/menuetos/dosbox/dosbox
Всё, что стоит после первого пробела после имени исполняемого файла, дословно передаётся программе в качестве командной строки.
Команда load сообщает о результате в окне сообщений (немного выше окна командной строки). Если программу удалось загрузить, то об этом появится соответствующее сообщение; если не удалось, то в сообщении будет указана причина ошибки. Наиболее вероятная - "file not found", если неправильно указано имя файла.
Отладчик может загружать файлы с информацией об именах в программе (метки, глобальные переменные) - текстовые файлы, каждая строка которых имеет вид 0x<hex_значение_адреса> <имя> (строки, не имеющие такой вид, игнорируются). Такой файл может быть создан вручную или сгенерирован автоматически при компиляции исходника fasm'ом.
Явная загрузка осуществляется командой load-symbols:
load-symbols <полное имя файла символов>
Кроме того, при выполнении команды load отладчик проверяет наличие файла с таким же именем, как загружаемый бинарник, и расширением .dbg (/rd/1/example.dbg для первого из примеров выше), и если такой есть, загружает его автоматически (выдавая сообщение "Symbols loaded", если всё в
порядке).
Может случиться так, что загруженная программа упакована. Общий принцип упаковки программ следующий: сначала исходный файл пакуется (каким-нибудь алгоритмом сжатия), потом приписывается небольшой по размеру код, который получает управление при запуске программы, распаковывает в памяти исходный код, после чего передаёт ему управление. Если программа упакована, то её "настоящий" код не виден и для отладки нужно предварительно пройти код распаковщика. koldbg определяет большинство существующих упаковщиков (mxp, mxp_lzo, mxp_nrv, mtappack) и в этом случае предлагает автоматически пройти до "настоящего" кода. Рекомендуется согласиться (нажать 'y' или <Enter>), но можно и отказаться. При отказе и в случае, когда программа упакована чем-то неизвестным, можно использовать команду "unpack" (без аргументов). Вызывайте её только в случае,
когда вы уверены, что программа упакована и что управление ещё не дошло до основного кода! [Начиная с версии Kolibri 0.6.5.0, весь этот абзац уже неактуален, поскольку приложения можно упаковывать как и любые двоичные файлы kpack'ом и при этом код распаковщика находится в ядре и распаковка прозрачна для отладки.]
Загруженную программу можно прибить командой "terminate" (без аргументов). Команда "detach" (без аргументов) отключается от программы, после чего программа продолжает выполняться нормально, как если бы отладчика не было. После обеих этих команд программа перестаёт быть отлаживаемой.
Можно заново загрузить программу для отладки командой "reload" (без аргументов). Если уже есть загруженная программа, то она прибивается и
запускается (с самого начала) новый экземпляр (с той же командной строкой), в этом случае команда аналогична командам:
terminate
load <last program name> <last program arguments>
В противном случае заново загружается программа, которую отлаживали последней (в текущем сеансе работы с koldbg) (с той же командной строкой), т.е. почти то же самое, что и load <last program name> <last program arguments>, но команда reload в обоих случаях короче и удобнее; кроме того, load считает, что загружается новая программа, и переводит окно данных (см. ниже) на нулевой адрес, а reload сохраняет текущий адрес.
Всегда доступна команда "help", которую можно сокращать до "h".
Все команды разбиты на группы.
help без аргументов показывает список групп команд.
help с указанием группы выводит список команд этой группы с краткими
комментариями.
help с указанием команды выводит информацию о заданной команде.
Например:
help
help control
h LoaD
Окно отладчика состоит из следующих элементов, перечисляемых сверху вниз:
- строка состояния. При наличии загруженной программы показывает ее имя и состояние ("Running"/"Paused"), при отсутствии сообщает "No program loaded".
- окно регистров - показывает значения регистров общего назначения, регистра eip, регистра флагов и регистров FPU/MMX. Регистр флагов отображается двумя способами: полное hex-значение и состояния отдельных флагов: CF,PF,AF,ZF,SF,DF,OF: если флаг сброшен, то изображается маленькая буква, если установлен, то заглавная. Регистры, изменившиеся с предыдущего момента, подсвечиваются оранжевым.
- окно данных (окно дампа) - показывает содержимое памяти загруженной программы
- окно кода (окно дизассемблера) - показывает код программы в виде дизассемблированных инструкций
- окно сообщений
- окно командной строки
В окне дампа можно просматривать данные, начиная с любого адреса, для этого есть команда:
d <выражение>
Команда d без аргументов пролистывает окно дампа вниз. То же самое относится к окну кода и команде u <выражение> или просто u.
Например:
d esi - показывает данные, находящиеся по адресу esi (например, полезна перед выполнением инструкции rep movsb)
d esp - показывает стек
u eip - дизассемблирует инструкции, начиная с текущей
Выражения в koldbg могут включать
- шестнадцатеричные константы
- имена всех регистров общего назначения (8 32-битных, 8 16-битных и 8 8-битных) и регистра eip; значения 16- и 8-битных регистров расширяются
нулями до 32 бит
- четыре арифметические операции +,-,*,/ (со стандартными приоритетами) и скобки
- [если есть информация о символах] имена, загруженные из dbg-файла
Все вычисления производятся по модулю 2^32.
Примеры выражений:
eax
eip+2
ecx-esi-1F
al+AH*bl
ax + 2* bH*(eip+a73)
3*esi*di/EAX
Команда
? <выражение> вычисляет значение указанного выражения.
Значения регистров загруженной программы можно изменять командой r, имеющей две абсолютно эквивалентные формы:
r <регистр> <выражение>
r <регистр>=<выражение>
(в обоих случаях можно расставлять пробелы по вкусу). В качестве регистра можно указывать любой из вышеупомянутых - 24 регистра общего назначения и eip.
Допустим, команда load успешно загрузила программу для отладки. Сразу после загрузки программа приостановлена и не выполняется.
Нажатие F7 (аналог командной строки - команда "s") делает один шаг в загруженной программе, после чего управление возвращается отладчику, который показывает новое содержимое регистров и памяти. Системный вызов int 40h (а также инструкции sysenter и syscall) при этом считается одним шагом.
Нажатие F8 (аналог командной строки - команда "p") также делает шаг в загруженной программе, но при этом вызовы процедур, строковые операции с
префиксом rep/repz/repnz и циклы loop выполняются как один шаг.
Команды пошагового выполнения используются, как правило, на отдельных участках программы, когда нужно, например, регулярно отслеживать значения регистров и/или каких-то переменных в памяти.
Команда g <выражение> возобновляет выполнение программы и ждёт, пока управление дойдёт до eip=соответствующему адресу, и в этот момент приостанавливает программу. Команда "g" без аргументов просто возобновляет выполнение программы.
Приостановить выполнение программы можно командой "stop" (без аргументов).
Обычно требуется, чтобы программа нормально выполнялась, но при наступлении определённых условий программа приостанавалась и управление получал отладчик. Соответствующие условия называются точками останова, breakpoint(s), в просторечии - бряками. Простейший тип точек останова - на конкретный адрес, т.е. прерывать выполнение при eip=<заданное значение>. Такие точки останова устанавливаются командой:
bp <выражение>
Замечание. Если есть только одна такая точка останова, удобнее вместо неё использовать команду "g" с аргументом.
Другой тип точек останова - по обращению к заданному участку памяти. Таких точек останова может быть не больше четырёх (поскольку используются
аппаратные возможности процессоров x86, где допускаются только 4 таких точки).
bpm <выражение> - брякается на любой доступ к байту по указанному адресу
bpm w <выражение> - брякается на запись байта по указанному адресу
bpmb/bpmw/bpmd <выражение> - брякаются на доступ к соответственно байту, слову и двойному слову по указанному адресу. bpm и bpmb - синонимы. При использовании bpmw/bpmd адрес должен быть выровнен соответственно на границу слова (т.е. быть чётным) или на границу двойного слова (т.е. делиться на 4).
bpmb,bpmw,bpmd w <выражение> - аналогично для бряка на запись.
Список установленных точек останова можно просмотреть командой "bl", информацию о конкретной точке останова можно получить с помощью "bl <номер>". Ненужные точки останова удаляются командой "bc <номер>", временно ненужные можно запретить командой "bd <номер>", когда они станут снова нужны, используйте команду "be <номер>".
Замечания.
1. При отладке собственных программ можно вставлять в код инструкции int3 (обратите внимание на отсутствие пробела!). Такая инструкция вызывает исключение при нормальном запуске, что приведёт к завершению процесса, но при работе под отладчиком просто активизируется отладчик (с сообщением "int3 command at xxx"). Это позволяет не думать о том, какие адреса использовать в командах g и/или bp. Можно также генерировать файл с информацией о символах и загружать его, тогда не только нет нужды самостоятельно вычислять адреса для "g" и "bp", но и "u","d","?" будут понимать указание имени метки/переменной.
2. Весь вывод и весь ввод ориентирован на 16-ричную систему счисления.
3. Когда программа выполняется, окна регистров и данных показывают информацию, относящуюся к моменту до возобновления; установка значений регистров в этом режиме невозможна. Впрочем, команда "d" в этом режиме показывает информацию, верную в момент выдачи команды.

View File

@ -0,0 +1,68 @@
; Sorting bunch of dwords, count = ecx, locating at address = edx,
; comparison function at ebx
; Destroy content of eax, ecx, esi, edi
Sort:
jecxz .Done
mov eax,ecx
@@:
push eax
call .Restore
pop eax
dec eax
jnz @B
@@:
cmp ecx,1
jz .Done
mov esi,1
mov edi,ecx
call .Exchange
dec ecx
mov eax,1
call .Restore
jmp @B
.Done:
ret
.Exchange:
push eax ecx
mov eax,[edx+esi*4-4]
mov ecx,[edx+edi*4-4]
mov [edx+esi*4-4],ecx
mov [edx+edi*4-4],eax
pop ecx eax
ret
.Restore:
lea esi,[eax+eax]
cmp esi,ecx
ja .DonErr
push esi
mov esi,[edx+esi*4-4]
mov edi,[edx+eax*4-4]
call ebx
pop esi
ja .NeedXchg
cmp esi,ecx
jae .DonErr
push esi
mov esi,[edx+esi*4]
mov edi,[edx+eax*4-4]
call ebx
pop esi
jbe .DonErr
.NeedXchg:
cmp esi,ecx
jz .DoXchg
push esi
mov edi,[edx+esi*4-4]
mov esi,[edx+esi*4]
call ebx
pop esi
sbb esi,-1
.DoXchg:
mov edi,eax
call .Exchange
mov eax,esi
jmp .Restore
.DonErr:
ret

View File

@ -0,0 +1,415 @@
include 'sort.inc'
; compare proc for sorter
Compare:
cmpsd
jnz @F
cmp esi,edi
@@:
ret
; compare proc for sorter 2
Compare2:
cmpsd
@@:
cmpsb
jnz @F
cmp byte [esi-1],0
jnz @B
cmp esi,edi
@@:
ret
FreeSymbols:
mov ecx,[Symbols]
jecxz @F
mcall 68,13
and [Symbols],0
and [NumSymbols],0
@@:
ret
;-----------------------------------------------------------------------------
; Load symbols event
OnLoadSymbols.FileErr:
test ebp,ebp
jz @f
mcall 68,13,edi
ret
@@:
push eax
mcall 68,13,edi
mov esi,aCannotLoadFile
call PutMessageNoDraw
pop eax
cmp eax,0x20
jae .Unk
mov esi,[LoadErrMsgs+eax*4]
test esi,esi
jnz PutMessage
.Unk:
mov esi,UnkErrMsg2
jmp PutMessage
OnLoadSymbols:
xor ebp,ebp
; load input file
mov esi,[CurArg]
call FreeSymbols
.Silent:
; esi = ptr to symbols filename
xor edi,edi
cmp [NumSymbols],edi ; Any previously loaded symbols?
je .LoadFile
call FreeSymbols ; Yep, free them
.LoadFile:
mov ebx,FN70AttrBlock ; Get file attributes
mov [ebx+21],esi
mcall 70
test eax,eax
jnz .FileErr
cmp dword [FileAttr+36],edi ; Is upper dword of filesize larger then 0?
jnz .MemErr
mov ecx,dword [FileAttr+32] ; Lower dword of filesize
mcall 68,12 ; allocate the memory
test eax,eax
jz .MemErr
mov edi,eax
mov ebx,FN70ReadBlock
mov [ebx+12],ecx
mov [ebx+16],edi
mov [ebx+21],esi
mcall 70 ; Read the file into the allocated buffer
test eax,eax
jnz .FileErr
; calculate memory requirements to load debug symbols
lea edx,[ecx+edi-1] ; edx = EOF-1
mov esi,edi
xor ecx,ecx
mov [SymbolSection],1 ;;;;;
.CalcLoop:
cmp esi,edx
jae .CalcDone
cmp byte [esi],' ' ; skip spaces at the beginning of a line
jne .NotSpace
inc esi
jmp .CalcLoop
.NotSpace:
cmp byte [esi],'.'
jne .NotSection
inc esi
mov [SymbolSection],0
cmp dword [esi],'text'
je .SectionOK
cmp dword [esi],'data'
je .SectionOK
cmp dword [esi],'bss '
jne .SkipLine
.SectionOK:
inc [SymbolSection]
jmp .SkipLine
.NotSection:
cmp [SymbolSection],0
je .SkipLine
cmp word [esi],'0x'
jne .SkipLine
inc esi
inc esi
@@:
cmp esi,edx
jae .CalcDone
lodsb
or al,20h
sub al,'0'
cmp al,9
jbe @B
sub al,'a'-'0'-10
cmp al,15
jbe @B
dec esi
@@:
cmp esi,edx
ja .CalcDone
lodsb
cmp al,20h
je @B
jb .CalcLoop
cmp al,9
jz @B
add ecx,12+1
inc [NumSymbols]
@@:
inc ecx
cmp esi,edx
ja .CalcDone
lodsb
cmp al,0xD
jz .CalcLoop
cmp al,0xA
jz .CalcLoop
jmp @B
.SkipLine:
cmp esi,edx
jae .CalcDone
lodsb
cmp al,0xD
jz .CalcLoop
cmp al,0xA
jz .CalcLoop
jmp .SkipLine
.CalcDone:
; Allocate memory to place the debug symbols in
mcall 68,12
test eax,eax
jnz .MemOK
inc ebx
mov ecx,edi
mov al,68
mcall
.MemErr:
mov esi,aNoMemory
jmp PutMessage
.MemOK:
mov [Symbols],eax
mov ebx,eax
push edi
mov esi,edi
mov edi,[NumSymbols]
lea ebp,[eax+edi*4]
lea edi,[eax+edi*8]
; Actual loading of the debug symbols
; esi->input, edx->EOF, ebx->ptrs, edi->names
mov [SymbolSection],1 ;;;;;
.ReadLoop:
cmp esi,edx
jae .ReadDone
cmp byte [esi],' '
jne .NotSpace2
inc esi
jmp .ReadLoop
.NotSpace2:
cmp byte [esi],'.'
jne .NotSection2
inc esi
mov [SymbolSection],0
cmp dword [esi],'text'
je .SectionOK2
cmp dword [esi],'data'
je .SectionOK2
cmp dword [esi],'bss '
jne .ReadLine
.SectionOK2:
inc [SymbolSection]
jmp .ReadLine
.NotSection2:
cmp [SymbolSection],0
je .ReadLine
cmp word [esi],'0x'
jnz .ReadLine
inc esi
inc esi
xor eax,eax
xor ecx,ecx
@@:
shl ecx,4
add ecx,eax
cmp esi,edx
jae .ReadDone
lodsb
or al,20h
sub al,'0'
cmp al,9
jbe @B
sub al,'a'-'0'-10
cmp al,15
jbe @B
dec esi
@@:
cmp esi,edx
ja .ReadDone
lodsb
cmp al,20h
jz @B
jb .ReadLoop
cmp al,9
jz @B
mov dword [ebx],edi
add ebx,4
mov dword [ebp],edi
add ebp,4
mov dword [edi],ecx
add edi,4
stosb
@@:
xor eax,eax
stosb
cmp esi,edx
ja .ReadDone
lodsb
cmp al,0xD
jz .ReadLoop
cmp al,0xA
jz .ReadLoop
mov byte [edi-1],al
jmp @B
.ReadLine:
cmp esi,edx
jae .ReadDone
lodsb
cmp al,0xD
jz .ReadLoop
cmp al,0xA
jz .ReadLoop
jmp .ReadLine
.ReadDone:
pop ecx
mcall 68,13
mov ecx,[NumSymbols]
mov edx,[Symbols]
mov ebx,Compare
call Sort
mov ecx,[NumSymbols]
lea edx,[edx+ecx*4]
mov ebx,Compare2
call Sort
mov esi,aSymbolsLoaded
call PutMessage
jmp DrawMessages;DrawDisAsm
;
; in: EAX = address
; out: ESI, CF
FindSymbol:
cmp [NumSymbols],0
jnz @F
.Ret0:
xor esi,esi
stc
ret
@@:
push ebx ecx edx
xor edx,edx
mov esi,[Symbols]
mov ecx,[NumSymbols]
mov ebx,[esi]
cmp [ebx],eax
jz .DoneZ
jb @F
pop edx ecx ebx
jmp .Ret0
@@:
; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
; TODO: add meaningful label names
.0:
push edx
.1:
add edx,ecx
sar edx,1
cmp edx,[esp]
jz .Done2
mov ebx,[esi+edx*4]
cmp [ebx],eax
jz .Done
ja .2
mov [esp],edx
jmp .1
.2:
mov ecx,edx
pop edx
jmp .0
.DoneCont:
dec edx
.Done:
test edx,edx
jz @F
mov ebx,[esi+edx*4-4]
cmp [ebx],eax
jz .DoneCont
@@:
pop ecx
.DoneZ:
mov esi,[esi+edx*4]
add esi,4
pop edx ecx ebx
clc
ret
.Done2:
lea esi,[esi+edx*4]
pop ecx edx ecx ebx
stc
ret
;-----------------------------------------------------------------------------
; in: esi->name
; out: if found: CF = 0, EAX = value
; otherwise CF = 1
FindSymbolName:
cmp [NumSymbols],0
jnz @F
.StcRet:
stc
ret
@@:
push ebx ecx edx edi
push -1
pop edx
mov ebx,[Symbols]
mov ecx,[NumSymbols]
lea ebx,[ebx+ecx*4]
; invariant: symbols_name[edx] < name < symbols_name[ecx]
.0:
push edx
.1:
add edx,ecx
sar edx,1
cmp edx,[esp]
jz .Done2
call .Cmp
jz .Done
jb .2
mov [esp],edx
jmp .1
.2:
mov ecx,edx
pop edx
jmp .0
.Done:
pop ecx
.DoneZ:
mov eax,[ebx+edx*4]
mov eax,[eax]
pop edi edx ecx ebx
clc
ret
.Done2:
pop edx edi edx ecx ebx
stc
ret
.Cmp:
mov edi,[ebx+edx*4]
push esi
add edi,4
@@:
cmpsb
jnz @F
cmp byte [esi-1],0
jnz @B
@@:
pop esi
ret

View File

@ -0,0 +1,22 @@
PGAlloc:
; in: ecx=size
; out: eax=pointer or NULL
push ebx
push 68
pop eax
push 12
pop ebx
int 40h
pop ebx
ret
PGFree:
; in: ecx=pointer
; destroys eax
push ebx
push 68
pop eax
push 13
pop ebx
int 40h
pop ebx
ret