Skip to content

Commit

Permalink
prepare asm macro wrapper before clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
RadWolfie authored and ergo720 committed Sep 30, 2024
1 parent 164e636 commit 1be3c2f
Show file tree
Hide file tree
Showing 22 changed files with 1,031 additions and 1,057 deletions.
36 changes: 18 additions & 18 deletions nboxkrnl/ex/ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,34 +141,34 @@ EXPORTNUM(51) LONG FASTCALL InterlockedCompareExchange
LONG Comparand
)
{
__asm {
mov eax, Comparand
cmpxchg [ecx], edx
}
ASM_BEGIN
ASM(mov eax, Comparand);
ASM(cmpxchg [ecx], edx);
ASM_END
}

EXPORTNUM(52) LONG FASTCALL InterlockedDecrement
(
volatile PLONG Addend
)
{
__asm {
or eax, 0xFFFFFFFF
xadd [ecx], eax
dec eax
}
ASM_BEGIN
ASM(or eax, 0xFFFFFFFF);
ASM(xadd [ecx], eax);
ASM(dec eax);
ASM_END
}

EXPORTNUM(53) LONG FASTCALL InterlockedIncrement
(
volatile PLONG Addend
)
{
__asm {
mov eax, 1
xadd [ecx], eax
inc eax
}
ASM_BEGIN
ASM(mov eax, 1);
ASM(xadd [ecx], eax);
ASM(inc eax);
ASM_END
}

EXPORTNUM(54) LONG FASTCALL InterlockedExchange
Expand All @@ -177,8 +177,8 @@ EXPORTNUM(54) LONG FASTCALL InterlockedExchange
LONG Value
)
{
__asm {
mov eax, Value
xchg [ecx], eax
}
ASM_BEGIN
ASM(mov eax, Value);
ASM(xchg [ecx], eax);
ASM_END
}
92 changes: 46 additions & 46 deletions nboxkrnl/ex/exp_sup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@ EXPORTNUM(26) __declspec(naked) VOID XBOXAPI ExRaiseException
PEXCEPTION_RECORD ExceptionRecord
)
{
__asm {
push ebp
mov ebp, esp
sub esp, SIZE CONTEXT
push esp
call RtlCaptureContext
add [esp]CONTEXT.Esp, 4 // pop ExceptionRecord argument
mov [esp]CONTEXT.ContextFlags, CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS // set ContextFlags member of CONTEXT
mov eax, [ebp + 8]
mov ecx, [ebp + 4]
mov [eax]EXCEPTION_RECORD.ExceptionAddress, ecx // set ExceptionAddress member of ExceptionRecord argument to caller's eip
push esp
push eax
call RtlDispatchException
ASM_BEGIN
ASM(push ebp);
ASM(mov ebp, esp);
ASM(sub esp, SIZE CONTEXT);
ASM(push esp);
ASM(call RtlCaptureContext);
ASM(add [esp]CONTEXT.Esp, 4); // pop ExceptionRecord argument
ASM(mov [esp]CONTEXT.ContextFlags, CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS); // set ContextFlags member of CONTEXT
ASM(mov eax, [ebp + 8]);
ASM(mov ecx, [ebp + 4]);
ASM(mov [eax]EXCEPTION_RECORD.ExceptionAddress, ecx); // set ExceptionAddress member of ExceptionRecord argument to caller's eip
ASM(push esp);
ASM(push eax);
ASM(call RtlDispatchException);
// If the exception is continuable, then RtlDispatchException will return
mov ecx, esp
push FALSE
push ecx
test al, al
jz exp_unhandled
call ZwContinue // won't return
exp_unhandled:
push [ebp + 8]
call ZwRaiseException // won't return
}
ASM(mov ecx, esp);
ASM(push FALSE);
ASM(push ecx);
ASM(test al, al);
ASM(jz exp_unhandled);
ASM(call ZwContinue); // won't return
exp_unhandled:
ASM(push [ebp + 8]);
ASM(call ZwRaiseException); // won't return
ASM_END
}

EXPORTNUM(27) __declspec(naked) VOID XBOXAPI ExRaiseStatus
(
NTSTATUS Status
)
{
__asm {
push ebp
mov ebp, esp
sub esp, SIZE CONTEXT + SIZE EXCEPTION_RECORD
push esp
call RtlCaptureContext
add [esp]CONTEXT.Esp, 4 // pop Status argument
mov [esp]CONTEXT.ContextFlags, CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS // set ContextFlags member of CONTEXT
lea ecx, [ebp - SIZE EXCEPTION_RECORD]
mov eax, [ebp + 8]
mov [ecx]EXCEPTION_RECORD.ExceptionCode, eax // set ExceptionCode member of ExceptionRecord to Status argument
mov [ecx]EXCEPTION_RECORD.ExceptionFlags, EXCEPTION_NONCONTINUABLE
mov [ecx]EXCEPTION_RECORD.ExceptionRecord, 0
mov eax, [ebp + 4]
mov [ecx]EXCEPTION_RECORD.ExceptionAddress, eax // set ExceptionAddress member of ExceptionRecord to caller's eip
mov [ecx]EXCEPTION_RECORD.NumberParameters, 0
push esp
push ecx
call RtlDispatchException
ASM_BEGIN
ASM(push ebp);
ASM(mov ebp, esp);
ASM(sub esp, SIZE CONTEXT + SIZE EXCEPTION_RECORD);
ASM(push esp);
ASM(call RtlCaptureContext);
ASM(add [esp]CONTEXT.Esp, 4); // pop Status argument
ASM(mov [esp]CONTEXT.ContextFlags, CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS); // set ContextFlags member of CONTEXT
ASM(lea ecx, [ebp - SIZE EXCEPTION_RECORD]);
ASM(mov eax, [ebp + 8]);
ASM(mov [ecx]EXCEPTION_RECORD.ExceptionCode, eax); // set ExceptionCode member of ExceptionRecord to Status argument
ASM(mov [ecx]EXCEPTION_RECORD.ExceptionFlags, EXCEPTION_NONCONTINUABLE);
ASM(mov [ecx]EXCEPTION_RECORD.ExceptionRecord, 0);
ASM(mov eax, [ebp + 4]);
ASM(mov [ecx]EXCEPTION_RECORD.ExceptionAddress, eax); // set ExceptionAddress member of ExceptionRecord to caller's eip
ASM(mov [ecx]EXCEPTION_RECORD.NumberParameters, 0);
ASM(push esp);
ASM(push ecx);
ASM(call RtlDispatchException);
// Because the exception is non-continuable, RtlDispatchException should never return. If it does return, then it must be a bug
push NORETURN_FUNCTION_RETURNED
call KeBugCheckLogEip // won't return
}
ASM(push NORETURN_FUNCTION_RETURNED);
ASM(call KeBugCheckLogEip); // won't return
ASM_END
}
64 changes: 32 additions & 32 deletions nboxkrnl/hal/halp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ KEVENT HalpSmbusComplete;

VOID HalpInitPIC()
{
__asm {
mov al, ICW1_ICW4_NEEDED | ICW1_CASCADE | ICW1_INTERVAL8 | ICW1_EDGE | ICW1_INIT
out PIC_MASTER_CMD, al
out PIC_SLAVE_CMD, al
mov al, PIC_MASTER_VECTOR_BASE
out PIC_MASTER_DATA, al
mov al, PIC_SLAVE_VECTOR_BASE
out PIC_SLAVE_DATA, al
mov al, 4
out PIC_MASTER_DATA, al
mov al, 2
out PIC_SLAVE_DATA, al
mov al, ICW4_8086 | ICW4_NORNAL_EOI | ICW4_NON_BUFFERED | ICW4_NOT_FULLY_NESTED
out PIC_MASTER_DATA, al
out PIC_SLAVE_DATA, al
ASM_BEGIN
ASM(mov al, ICW1_ICW4_NEEDED | ICW1_CASCADE | ICW1_INTERVAL8 | ICW1_EDGE | ICW1_INIT);
ASM(out PIC_MASTER_CMD, al);
ASM(out PIC_SLAVE_CMD, al);
ASM(mov al, PIC_MASTER_VECTOR_BASE);
ASM(out PIC_MASTER_DATA, al);
ASM(mov al, PIC_SLAVE_VECTOR_BASE);
ASM(out PIC_SLAVE_DATA, al);
ASM(mov al, 4);
ASM(out PIC_MASTER_DATA, al);
ASM(mov al, 2);
ASM(out PIC_SLAVE_DATA, al);
ASM(mov al, ICW4_8086 | ICW4_NORNAL_EOI | ICW4_NON_BUFFERED | ICW4_NOT_FULLY_NESTED);
ASM(out PIC_MASTER_DATA, al);
ASM(out PIC_SLAVE_DATA, al);
// Mask all interrupts in the IMR (except for IRQ2 on the master)
mov al, 0xFB
out PIC_MASTER_DATA, al
add al, 4
out PIC_SLAVE_DATA, al
}
ASM(mov al, 0xFB);
ASM(out PIC_MASTER_DATA, al);
ASM(add al, 4);
ASM(out PIC_SLAVE_DATA, al);
ASM_END
}

VOID HalpInitPIT()
{
__asm {
mov al, PIT_COUNT_BINARY | PIT_COUNT_MODE | PIT_COUNT_16BIT | PIT_COUNT_CHAN0
out PIT_PORT_CMD, al
mov ax, PIT_COUNTER_1MS
out PIT_CHANNEL0_DATA, al
shr ax, 8
out PIT_CHANNEL0_DATA, al
}
ASM_BEGIN
ASM(mov al, PIT_COUNT_BINARY | PIT_COUNT_MODE | PIT_COUNT_16BIT | PIT_COUNT_CHAN0);
ASM(out PIT_PORT_CMD, al);
ASM(mov ax, PIT_COUNTER_1MS);
ASM(out PIT_CHANNEL0_DATA, al);
ASM(shr ax, 8);
ASM(out PIT_CHANNEL0_DATA, al);
ASM_END
}

VOID HalpInitSMCstate()
Expand Down Expand Up @@ -150,10 +150,10 @@ VOID HalpShutdownSystem()
outl(KE_ABORT, 0);

while (true) {
__asm {
cli
hlt
}
ASM_BEGIN
ASM(cli);
ASM(hlt);
ASM_END
}
}

Expand Down
Loading

0 comments on commit 1be3c2f

Please sign in to comment.