Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shen, Siran
arm11_
Commits
097de796
Commit
097de796
authored
Jun 09, 2020
by
sea19
Browse files
EMULATE WORKS, some test case say they fail on ruby but look exactly the same
parent
8fe5a49f
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/decode.c
View file @
097de796
...
...
@@ -16,7 +16,7 @@ void decode(unsigned int instruction, decoded *decodedInstr) {
}
else
if
(
bit26and27
==
2
)
{
decodedInstr
->
type
=
branch
;
}
}
void
findOpcode
(
decoded
*
decodedInstr
,
unsigned
int
instruction
)
{
...
...
src/emulate.c
View file @
097de796
...
...
@@ -6,10 +6,7 @@
#include "fetch.h"
#include "execute.h"
#include <math.h>
#define NREGS 17
#define STACK_SIZE 16384 //Defined stack as ints which are 4 bytes so (64*1024)/4
#define PC 15
#include <time.h>
void
bigToLittleEndian
(
armstate
*
state
)
{
int
temp
;
...
...
@@ -20,18 +17,26 @@ void bigToLittleEndian(armstate *state) {
}
}
void
printResult
(
armstate
*
state
,
int
numOfInstr
)
{
void
printResult
(
armstate
*
state
)
{
//clock_t start, end;
//double timeTaken;
//start = clock();
#define INRANGE(x) (x < 0xc4653601) && (x >= 0x80000000)
bigToLittleEndian
(
state
);
printf
(
"Registers:
\n
"
);
for
(
int
i
=
0
;
i
<
13
;
i
++
)
{
if
(
i
<
10
)
{
printf
(
"$%d :%11d (0x%08x)
\n
"
,
i
,
state
->
regs
[
i
],
state
->
regs
[
i
]);
}
else
{
printf
(
"$%d :%11d (0x%08x)
\n
"
,
i
,
state
->
regs
[
i
],
state
->
regs
[
i
]);
if
(
INRANGE
(
state
->
regs
[
i
]))
{
printf
(
"$%d :%12d (0x%08x)
\n
"
,
i
,
state
->
regs
[
i
],
state
->
regs
[
i
]);
}
else
{
printf
(
"$%d :%11d (0x%08x)
\n
"
,
i
,
state
->
regs
[
i
],
state
->
regs
[
i
]);
}
}
else
{
printf
(
"$%d :%11i (0x%08x)
\n
"
,
i
,
state
->
regs
[
i
],
state
->
regs
[
i
]);
}
}
}
printf
(
"PC :%11d (0x%08x)
\n
"
,
state
->
regs
[
PC
],
state
->
regs
[
PC
]);
if
(
state
->
regs
[
16
]
>=
pow
(
2
,
31
))
{
if
(
state
->
regs
[
16
]
>=
(
1
<<
31
))
{
printf
(
"CPSR:%12d (0x%08x)
\n
"
,
state
->
regs
[
16
],
state
->
regs
[
16
]);
}
else
{
printf
(
"CPSR:%11d (0x%08x)
\n
"
,
state
->
regs
[
16
],
state
->
regs
[
16
]);
...
...
@@ -42,11 +47,14 @@ void printResult(armstate *state, int numOfInstr) {
printf
(
"0x%08x: 0x%08x
\n
"
,
i
*
4
,
state
->
memory
[
i
]);
}
}
//end = clock();
//timeTaken = ((double)(end - start)) / CLOCKS_PER_SEC;
//printf("Time Taken for printing results: %f\n", timeTaken);
}
void
startCycle
(
armstate
*
state
)
{
unsigned
int
*
pc
=
&
(
state
->
regs
[
PC
]);
//pc takes the value of the program counter
unsigned
int
fetched
,
counter
=
0
;
unsigned
int
fetched
;
decoded
*
decodedInstr
=
(
decoded
*
)
calloc
(
1
,
sizeof
(
decoded
));
bool
finished
=
false
;
unsigned
int
*
objectcode
=
state
->
memory
;
...
...
@@ -72,21 +80,21 @@ void startCycle(armstate *state) {
if
(
decodedInstr
->
condition
==
0
&&
decodedInstr
->
bit0to25
==
0
&&
decodedInstr
->
type
==
and
){
finished
=
true
;
counter
-=
2
;
}
}
state
->
regs
[
16
]
=
state
->
n
<<
31
|
state
->
z
<<
30
|
state
->
c
<<
29
|
state
->
v
<<
28
;
counter
++
;
}
printResult
(
state
,
counter
);
printResult
(
state
);
free
(
decodedInstr
);
}
//pipeline
int
main
(
int
argc
,
char
**
argv
)
{
//clock_t start, end;
//double timeTaken;
//start = clock();
//unsigned int registers[NREGS];
armstate
*
state
=
(
armstate
*
)
calloc
(
1
,
sizeof
(
armstate
));
...
...
@@ -99,5 +107,8 @@ int main(int argc, char **argv) {
free
(
state
->
memory
);
free
(
state
);
//end = clock();
//timeTaken = ((double)(end - start)) / CLOCKS_PER_SEC;
//printf("Time Taken: %f\n", timeTaken);
return
EXIT_SUCCESS
;
}
src/emulate.h
0 → 100644
View file @
097de796
#define NREGS 17
#define STACK_SIZE 16384 //Defined stack as ints which are 4 bytes so (64*1024)/4
#define PC 15
void
bigToLittleEndian
(
armstate
*
state
);
void
printResult
(
armstate
*
state
,
int
numOfInstr
);
void
startCycle
(
armstate
*
state
);
int
main
(
int
argc
,
char
**
argv
);
src/execute.c
View file @
097de796
...
...
@@ -118,14 +118,14 @@ void decode_data_processing(decoded *decodedInstr, decoded_dp *decodedDp, armsta
imm
=
imm
>>
1
&
0x7fffffff
;
}
else
{
imm
=
(
imm
>>
1
)
|
0x80000000
;
}
}
}
}
operand2
=
imm
;
}
else
{
val_reg_last12bits
(
decodedInstr
,
&
operand2
,
state
);
}
decodedDp
->
operand2
=
operand2
;
decodedDp
->
operand2
=
operand2
;
}
void
execute
(
decoded
*
decodedInstr
,
armstate
*
state
){
...
...
@@ -176,4 +176,3 @@ void execute(decoded *decodedInstr, armstate *state){
}
//state->regs[PC] += 4;
}
src/instrType.c
View file @
097de796
...
...
@@ -37,7 +37,6 @@ void eor_instr(decoded *decodedInstr, armstate *state, decoded_dp *decodedDp){
}
void
sub_instr
(
decoded
*
decodedInstr
,
armstate
*
state
,
decoded_dp
*
decodedDp
){
decode_data_processing
(
decodedInstr
,
decodedDp
,
state
);
unsigned
int
res
=
(
state
->
regs
[
decodedDp
->
rn
]
-
decodedDp
->
operand2
);
state
->
regs
[
decodedDp
->
rd
]
=
res
;
...
...
@@ -136,7 +135,6 @@ void teq_instr(decoded *decodedInstr, armstate *state, decoded_dp *decodedDp){
}
void
cmp_instr
(
decoded
*
decodedInstr
,
armstate
*
state
,
decoded_dp
*
decodedDp
){
decode_data_processing
(
decodedInstr
,
decodedDp
,
state
);
unsigned
res
=
(
state
->
regs
[
decodedDp
->
rn
]
-
decodedDp
->
operand2
);
...
...
@@ -173,7 +171,6 @@ void orr_instr(decoded *decodedInstr, armstate *state, decoded_dp *decodedDp){
}
void
mov_instr
(
decoded
*
decodedInstr
,
armstate
*
state
,
decoded_dp
*
decodedDp
){
decode_data_processing
(
decodedInstr
,
decodedDp
,
state
);
state
->
regs
[
decodedDp
->
rd
]
=
decodedDp
->
operand2
;
...
...
@@ -273,6 +270,7 @@ void multiply_instr(decoded *decodedInstr, armstate *state){
//not sure about branch execution///////////////
void
branch_instr
(
decoded
*
decodedInstr
,
armstate
*
state
){
signed
int
offset
;
unsigned
int
iw
=
decodedInstr
->
bit0to25
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment