-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get info registers #1
Open
i4ki
wants to merge
4
commits into
master
Choose a base branch
from
xxx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−0
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
TARGET = xxx | ||
|
||
all: clean $(TARGET) | ||
|
||
$(TARGET): | ||
smlrcc main.c regs.c -I./include -o $(TARGET) | ||
|
||
debug: | ||
gdb ./xxx \ | ||
-ex "target remote localhost:1234" \ | ||
-ex "set architecture i80386" \ | ||
-ex "set disassembly-flavor intel" \ | ||
-ex "layout asm" -ex "layout regs" \ | ||
-ex "break *0x80490b0" | ||
|
||
clean: | ||
rm -f $(TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* common data types | ||
*/ | ||
|
||
typedef int32_t i32; | ||
typedef int16_t i16; | ||
typedef int8_t i8; | ||
|
||
typedef uint32_t u32; | ||
typedef uint16_t u16; | ||
typedef uint8_t u8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
void printRegs() { | ||
printf("eax=%08x\tesp=%08x\n", eax(), esp()); | ||
printf("ebx=%08x\tebp=%08x\n", ebx(), ebp()); | ||
} | ||
|
||
int main() { | ||
printf("xxx v0.0.1\n"); | ||
|
||
printRegs(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* get register info | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include "types.h" | ||
|
||
/* 32bit registers */ | ||
|
||
i32 eax() { | ||
/* by calling convention */ | ||
} | ||
|
||
i32 ebx() { | ||
asm("mov eax, ebx"); | ||
} | ||
|
||
i32 ecx() { | ||
asm("mov eax, ecx"); | ||
} | ||
|
||
i32 edx() { | ||
asm("mov eax, edx"); | ||
} | ||
|
||
i32 eip() { | ||
asm("__geteip: mov eax, [esp]\n" | ||
" ret\n" | ||
"call __geteip"); | ||
} | ||
|
||
i32 esp() { | ||
asm("mov eax, esp"); | ||
} | ||
|
||
i32 ebp() { | ||
asm("mov eax, ebp"); | ||
} | ||
|
||
i32 esi() { | ||
asm("mov eax, esi"); | ||
} | ||
|
||
i32 edi() { | ||
asm("mov eax, edi"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's awesome.... i didn't know asm allowed to define function like that =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That inlined assembly works as a label definition. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the old school
asm
directive. C and asm was cool before gcc introduced the extended inline asm thing...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCC dislikes that because people unaware of calling convention could mess things up trying to set local C variables from inside
asm
directives... To do that, you need to set things directly to ebp+8, ebp+16, and so on (arch dependent) and this could change depending on compiler optimizations (and compiler flags). To pack local variables, the order of variables in the stack could change also.Then, to use oldish
asm
directive best to leave it alone inside the function (as I did). Never put C and asm together inside same function...