Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ARM Emulator
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sella, Iftach
ARM Emulator
Commits
6fe9fa3f
Commit
6fe9fa3f
authored
2 years ago
by
James, Ben
Committed by
Sella, Iftach
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Step/main/branch
parent
1f28301d
No related branches found
Branches containing commit
No related tags found
2 merge requests
!2
fixed a bug
,
!1
Step/main/branch
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
emulate.c
+86
-1
86 additions, 1 deletion
emulate.c
with
86 additions
and
1 deletion
emulate.c
+
86
−
1
View file @
6fe9fa3f
...
...
@@ -308,6 +308,89 @@ void dataProcessingInstr(struct ProcessorState *processor, int address)
}
}
void
branchInstr
(
struct
ProcessorState
*
processor
,
uint32_t
address
)
{
// Check if address is valid
verifyAddress
(
address
);
uint32_t
instr
=
processor
->
memory
[
address
];
// Check if the instruction should be executed according to its condition codes
if
(
!
validCond
(
getBits
(
instr
,
28
,
31
),
processor
)){
return
;
}
// Get offset and sign
int32_t
offset
=
getBits
(
instr
,
0
,
23
);
int
sign
=
getBits
(
offset
,
23
,
23
);
// New address calculated with left shift and sign extension (and offset of 8)
uint32_t
branchAddr
=
processor
->
registers
[
14
]
+
((
offset
*
4
)
|
((
sign
)
?
0xFC000000
:
0
))
+
8
;
// New address verified
verifyAddress
(
branchAddr
);
// New address loaded to PC
processor
->
registers
[
14
]
=
branchAddr
;
return
;
}
// Steps through pipeline calling appropriate instruction method.
// Sets teminate if instruction is all-0.
void
step
(
struct
ProcessorState
*
processor
,
bool
*
terminate
)
{
// Fetches next instruction location (including offset)
uint32_t
nextAddr
=
processor
->
registers
[
14
]
+
8
;
// Fetches next instruction to be executed
uint32_t
nextInstr
=
processor
->
memory
[
nextAddr
];
// Checks for all-0
if
(
nextInstr
==
0
)
{
*
terminate
=
1
;
return
;
}
// Check instruction type and call appropriate method
switch
(
getBits
(
nextInstr
,
26
,
27
))
{
case
0
:
if
((
getBits
(
nextInstr
,
25
,
25
)
==
0
)
&&
(
getBits
(
nextInstr
,
4
,
8
)
==
9
))
{
multiplyInstr
(
processor
,
nextAddr
);
}
else
{
dataProcessingInstr
(
processor
,
nextAddr
);
}
case
1
:
dataTransferInstr
(
processor
,
nextAddr
);
case
2
:
branchInstr
(
processor
,
nextAddr
);
}
return
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
ProcessorState
*
processor
;
// Load file into processor state
if
(
argc
==
2
)
{
processor
=
loadBinary
(
argv
[
1
]);
}
else
if
(
argc
>
2
)
{
printf
(
"Too many arguments"
);
return
0
;
}
else
{
printf
(
"No file given"
);
return
0
;
}
bool
terminate
=
0
;
// Loop through instructions until all-0 met
while
(
!
terminate
)
{
step
(
processor
,
&
terminate
);
}
}
//*** TESTING FUNCTIONS ***//
...
...
@@ -389,10 +472,12 @@ struct ProcessorState *makeProcessor(void)
return
processor
;
}
/*
int main(void)
{
testBitGetters();
printf("\n");
testBarrelShifter();
return 0;
}
\ No newline at end of file
}
*/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment