Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions litmus/dumpRun.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,35 @@ end = struct
(List.rev sources) ;
fprintf chan "\n"
end ;
begin
fprintf chan "SHARED_LIB = $(SRCDIR)/shared_lib\n" ;
fprintf chan "GCCOPTS += -I $(SHARED_LIB)\n\n"
end ;
begin
match Cfg.mode with
| Mode.Std|Mode.PreSi -> ()
| Mode.Kvm ->
let utils =
["litmus_rand.o"; "utils.o"; "kvm_timeofday.o";] in
["litmus_rand.c"; "utils.c"; "kvm_timeofday.c";] in
let utils =
if Cfg.stdio then utils
else
"platform_io.o" :: "litmus_io.o" :: utils in
"platform_io.c" :: "litmus_io.c" :: utils in
let utils =
if flags.Flags.memtag then
"memtag.o"::utils
"memtag.c"::utils
else utils in
let utils =
if flags.Flags.pac then
"auth.o"::utils
"auth.c"::utils
else utils in
fprintf chan "UTILS=%s\n"
(String.concat " " utils)
let shared_utils =
List.map (fun util -> "$(SHARED_LIB)/" ^ util) utils in
fprintf chan "UTILS_SRC = %s\n\n"
(String.concat " " shared_utils)
end ;
begin
fprintf chan "UTILS_OBJ = $(UTILS_SRC:.c=.o)\n\n"
end ;
()

Expand Down
5 changes: 4 additions & 1 deletion litmus/libdir/_aarch64/kvm.rules
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cleansource:
awk -f show.awk $< > $@

%.elf: LDFLAGS = -nostdlib -pie -n
%.elf: %.o $(UTILS) $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o)
%.elf: %.o $(UTILS_OBJ) $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o)
$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \
-DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
$(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \
Expand All @@ -25,3 +25,6 @@ cleansource:
$(call arch_elf_check, $^)
$(OBJCOPY) -O binary $^ $@
@chmod a-x $@

$(SHARED_LIB)/%.o: $(SHARED_LIB)/%.c
$(CC) $(GCCOPTS) -c -o $@ $<
5 changes: 4 additions & 1 deletion litmus/libdir/_x86_64/kvm.rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ cleansource:
%.t: %.s
awk -f show.awk $< > $@

%.elf: %.o $(UTILS) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
%.elf: %.o $(UTILS_OBJ) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
$(CC) $(GCCOPTS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds $(filter %.o, $^) $(FLATLIBS)
@chmod a-x $@

%.flat: %.elf
$(OBJCOPY) -O elf32-i386 $^ $@
@chmod a-x $@

$(SHARED_LIB)/%.o: $(SHARED_LIB)/%.c
$(CC) $(GCCOPTS) -c -o $@ $<
2 changes: 1 addition & 1 deletion litmus/litmus.ml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ let () =
let asmcomment = !asmcomment
let asmcommentaslabel = !asmcommentaslabel
end in
let module T = Top_litmus.Top (Config) (Tar) in
let module T = Top_litmus.Top (Config) (Tar) in
T.from_files sources ;
if not (Option.is_out ()) then MySys.rmdir outname ;
exit 0
Expand Down
72 changes: 48 additions & 24 deletions litmus/objUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ module Make(O:Config)(Tar:Tar.S) =
close_in in_chan ;
fnames

(* Reference to the shared library *)
let shared_lib = if Tar.is_archive then "shared_lib/" else "../shared_lib/"

(* Copy lib file *)
let cpy ?sub ?prf fnames name ext =
do_cpy ?sub ?prf fnames ("_" ^ name) name ext
Expand All @@ -166,6 +169,14 @@ module Make(O:Config)(Tar:Tar.S) =
let cpy' ?sub ?prf fnames src dst ext =
do_cpy ?sub ?prf fnames ("_" ^ src) dst ext

(* Copy lib file to shared library *)
let cpy_shared ?sub ?prf fnames name ext =
do_cpy ?sub ?prf fnames ("_" ^ name) (shared_lib ^ name) ext

(* Copy lib file to shared library, changing its name *)
let cpy'_shared ?sub ?prf fnames src dst ext =
do_cpy ?sub ?prf fnames ("_" ^ src) (shared_lib ^ dst) ext

(* Copy from platform subdirectory *)
let cpy_platform fnames name ext =
let name = sprintf "platform_%s" name in
Expand All @@ -175,6 +186,15 @@ module Make(O:Config)(Tar:Tar.S) =
| Mode.PreSi|Mode.Std -> O.platform in
do_cpy fnames (Filename.concat platform name) name ext

(* Copy from platform subdirectory to shared library *)
let cpy_shared_platform fnames name ext =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same argument as for cpy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the previous case, I agree that we can use cpy' but for cpy_platform this needs change because this method does not specify distinct src and dst arguments. I think simply removing cpy_platform and moving cpy_shared_platform to cpy_platform should solve the problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the difference. I don't understand why there is cpy and cpy' - to me, it could have been a single function but whenever the call happened to cpy then dst=src. Am I missing anything?

That would be my preferred approach for `cpy_platform' - we can introduce a new argument that is the destination. I am open to suggestions, but let's not duplicate code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I also agree -- I think cpy can also be removed. Happy to do so if you think it should be done.

let name = sprintf "platform_%s" name in
let platform =
match O.mode with
| Mode.Kvm -> "_kvm" ^ O.platform
| Mode.PreSi|Mode.Std -> O.platform in
do_cpy fnames (Filename.concat platform name) (shared_lib ^ name) ext

let affinity_base () = match O.targetos with
| Linux|FreeBsd -> "_linux_affinity"
| AIX -> "_aix_affinity"
Expand All @@ -183,6 +203,9 @@ module Make(O:Config)(Tar:Tar.S) =
Warn.fatal "Affinity not implemented for %s" (TargetOS.pp os)

let dump flags =
(* Create shared library directory *)
let () = MySys.mkdirp (Tar.outname shared_lib) in

let fnames = [] in
let fnames = match O.driver with
| Driver.Shell -> fnames
Expand All @@ -205,22 +228,22 @@ module Make(O:Config)(Tar:Tar.S) =
|`BPF | `CPP|`LISA | `JAVA | `ASL -> Warn.fatal "no support for arch '%s'" (Archs.pp O.arch)
in
let fnames =
let fnames = cpy fnames "litmus_rand" ".c" in
let fnames = cpy fnames "litmus_rand" ".h" in
let fnames = cpy_shared fnames "litmus_rand" ".c" in
let fnames = cpy_shared fnames "litmus_rand" ".h" in
let sub = dir_of_sysarch O.sysarch in
let fnames = cpy ~sub:sub fnames "cache" ".h" in
let fnames = cpy_shared ~sub:sub fnames "cache" ".h" in
fnames in
let fnames =
if O.stdio then fnames
else
let fnames = cpy_platform fnames "io" ".c" in
let fnames = cpy_platform fnames "io" ".h" in
let fnames = cpy fnames "litmus_io" ".c" in
let fnames = cpy fnames "litmus_io" ".h" in
let fnames = cpy_shared_platform fnames "io" ".c" in
let fnames = cpy_shared_platform fnames "io" ".h" in
let fnames = cpy_shared fnames "litmus_io" ".c" in
let fnames = cpy_shared fnames "litmus_io" ".h" in
fnames in
let fnames = match O.mode with
| Mode.Std ->
let fnames = cpy fnames "utils" ".c" in
let fnames = cpy_shared fnames "utils" ".c" in
(* Select cached conditional variables, disabled.
if O.cached then
cpy ~prf:"#define CACHE 1" fnames "utils" ".h"
Expand All @@ -229,29 +252,30 @@ module Make(O:Config)(Tar:Tar.S) =
| Mode.PreSi ->
if do_dynalloc then
let fnames =
cpy' ~prf:"#define DYNALLOC 1" fnames "presi" "utils" ".c" in
cpy' ~prf:"#define DYNALLOC 1" fnames "presi" "utils" ".h"
cpy'_shared ~prf:"#define DYNALLOC 1" fnames "presi" "utils" ".c" in
cpy'_shared ~prf:"#define DYNALLOC 1" fnames "presi" "utils" ".h"
else
let fnames = cpy' fnames "presi" "utils" ".c" in
let fnames = cpy'_shared fnames "presi" "utils" ".c" in
cpy' fnames "presi" "utils" ".h"
| Mode.Kvm ->
let prf =
if do_dynalloc then
"#define KVM 1\n#define DYNALLOC 1"
else
"#define KVM 1" in
let fnames = cpy' ~prf:prf fnames "presi" "utils" ".c" in
let fnames = cpy' ~prf:prf fnames "presi" "utils" ".h" in
let fnames = cpy fnames "kvm_timeofday" ".h" in
let fnames = cpy'_shared ~prf:prf fnames "presi" "utils" ".c" in
let fnames = cpy'_shared ~prf:prf fnames "presi" "utils" ".h" in
let fnames = cpy_shared fnames "kvm_timeofday" ".h" in
let module I = Insert(O) in
I.copy "kvm_timeofday.c" Tar.outname ;
I.copy "kvm-headers.h" Tar.outname ;
let tar_outname = (fun str -> Tar.outname (shared_lib ^ str)) in
I.copy "kvm_timeofday.c" tar_outname ;
I.copy "kvm-headers.h" tar_outname ;
fnames in
let fnames =
match O.mode with
| Mode.Std ->
let fnames = cpy fnames "outs" ".c" in
let fnames = cpy fnames "outs" ".h" in
let fnames = cpy_shared fnames "outs" ".c" in
let fnames = cpy_shared fnames "outs" ".h" in
fnames
| Mode.PreSi|Mode.Kvm ->
fnames in
Expand All @@ -260,23 +284,23 @@ module Make(O:Config)(Tar:Tar.S) =
| Affinity.No -> fnames
| _ ->
let affi = affinity_base () in
let fnames = do_cpy fnames affi "affinity" ".c" in
let fnames = cpy fnames "affinity" ".h" in
let fnames = do_cpy fnames affi (shared_lib ^ "affinity") ".c" in
let fnames = cpy_shared fnames "affinity" ".h" in
fnames in
let fnames =
if flags.Flags.memtag then
begin
let sub = dir_of_sysarch O.sysarch in
let fnames = cpy ~sub:sub fnames "memtag" ".c" in
let fnames = cpy ~sub:sub fnames "memtag" ".h" in
let fnames = cpy_shared ~sub:sub fnames "memtag" ".c" in
let fnames = cpy_shared ~sub:sub fnames "memtag" ".h" in
fnames
end
else fnames in
let fnames =
if flags.Flags.pac then
let sub = dir_of_sysarch O.sysarch in
let fnames = cpy ~sub:sub fnames "auth" ".c" in
let fnames = cpy ~sub:sub fnames "auth" ".h" in
let fnames = cpy_shared ~sub:sub fnames "auth" ".c" in
let fnames = cpy_shared ~sub:sub fnames "auth" ".h" in
fnames
else fnames in
fnames
Expand Down
20 changes: 10 additions & 10 deletions litmus/preSi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ module Make
O.o "}"
end ;
O.o ""
end else if Cfg.is_kvm then begin
O.o "static void set_fault_vector(int role) { }" ;
O.o ""
end
end else if Cfg.is_kvm then begin
O.o "static void set_fault_vector(int role) { }" ;
O.o ""
end

(* User mode *)
let dump_user_stacks procs_user = match procs_user with
Expand Down Expand Up @@ -685,8 +685,8 @@ module Make
let data_zero = SkelUtil.data_symb_id pp_data_zero

let dump_data_indices test =
O.f "#define %-25s 0" data_unknown ;
O.f "#define %-25s 1" data_zero ;
O.f "#define %-25s 0" data_unknown ;
O.f "#define %-25s 1" data_zero ;
(* Define indices for data *)
List.iteri
(fun k (a,_) ->
Expand Down Expand Up @@ -1919,10 +1919,10 @@ module Make
O.o "/*************/" ;
O.o "" ;
if do_ascall then begin
List.iter
(dump_thread_code procs_user env)
test.T.code
end
List.iter
(dump_thread_code procs_user env)
test.T.code
end

let dump_run_def env test some_ptr stats procs_user =
let faults = U.get_faults test in
Expand Down
2 changes: 1 addition & 1 deletion litmus/skelUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ end
end

let dump_label_defs lbls =
O.f "#define %-25s 0" (instr_symb_id "UNKNOWN") ;
O.f "#define %-25s 0" (instr_symb_id "UNKNOWN") ;
(* Define indices for labels *)
List.iteri
(fun i (p,lbl) ->
Expand Down