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
Martin Pepin
sysdig
Commits
8dd59d96
Commit
8dd59d96
authored
Jan 14, 2017
by
Martin Pépin
Browse files
Complète l'implémentation des syscalls
- Suppression provisoire de `input_string` - Écriture de `print_string`
parent
7542f7ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
simulator/interpreter.ml
View file @
8dd59d96
...
...
@@ -60,6 +60,7 @@ module Env = struct
|
n
->
wrong_size
n
let
ram
env
=
env
.
ram
let
rom
env
=
env
.
rom
end
...
...
@@ -184,6 +185,7 @@ let interp asm_file n script_mode input_c output_c p =
)
p
.
p_outputs
;
(* Handling system calls *)
let
return_code
=
Ram
.
bits_of_int
32
@@
Syscall
.
syscall
(
Env
.
ram
env
)
in
Env
.
write_on_ram
32
env
[
|
true
;
true
;
false
;
false
|
]
return_code
let
return_code
=
Syscall
.
syscall
(
Env
.
ram
env
)
(
Env
.
rom
env
)
in
let
return_code_bin
=
Ram
.
bits_of_int
32
return_code
in
Env
.
write_on_ram
32
env
[
|
true
;
true
;
false
;
false
|
]
return_code_bin
done
simulator/syscall.ml
View file @
8dd59d96
(** Prints an integer on stdout and returns 0 *)
let
sys_print_int
a0
=
Format
.
printf
"
\n\n
===> %d <==
\n\n
@?"
a0
;
Format
.
printf
"
%d
@?"
a0
;
0
let
sys_print_str
_
=
assert
false
(** Reads an integer from stdin and returns it *)
let
sys_input_int
()
=
Scanf
.
scanf
"%d "
(
fun
x
->
x
)
let
sys_input_str
_
_
=
assert
false
(** Prints the string starting at start_addr in RAM on stdout.
The string must end with \000. *)
let
sys_print_str
rom
start_addr
=
let
addr
=
ref
start_addr
in
let
current_char
=
ref
0
in
let
read_char
()
=
let
c
=
Ram
.
int_of_bits
@@
Ram
.
get_byte
rom
!
addr
in
current_char
:=
c
;
incr
addr
in
while
(
read_char
()
;
!
current_char
<>
0
)
do
print_char
(
char_of_int
!
current_char
)
done
;
0
(** Stops the simulator execution, maybe a little bit violent but… It will do
the trick. *)
let
sys_exit
()
=
exit
0
let
syscall
ram
=
(** The switch for syscalls:
- The values of $a0, $a1, $v0 are read from the RAM
- The syscall is executed
- The return value is written at the right place in RAM
*)
let
syscall
ram
rom
=
let
a0
=
Ram
.
int_of_bits
@@
Ram
.
get_word
ram
4
in
let
a1
=
Ram
.
int_of_bits
@@
Ram
.
get_word
ram
8
in
let
v0
=
Ram
.
int_of_bits
@@
Ram
.
get_byte
ram
1
in
Printf
.
printf
"SYSCALL: $v0=%d $a0=%d $a1=%d
\n
"
v0
a0
a1
;
match
v0
with
|
0
->
0
|
0
->
0
(* a dummy syscall *)
|
1
->
sys_print_int
a0
|
4
->
sys_print_str
a0
|
4
->
sys_print_str
rom
a0
|
5
->
sys_input_int
()
|
8
->
sys_input_str
a0
a1
|
10
->
sys_exit
()
|
_
->
assert
false
|
n
->
failwith
@@
Printf
.
sprintf
"Invalid syscall code: %d"
n
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