4973
Support immediate operands in the data segment in all the ways we support them in the code segment.
This commit is contained in:
parent
5522bc9ec5
commit
9b16f19049
|
@ -104,9 +104,26 @@ void replace_global_variables_in_data_segment(segment& data, const map<string, u
|
|||
for (int j = 0; j < SIZE(l.words); ++j) {
|
||||
const word& curr = l.words.at(j);
|
||||
if (!contains_key(address, curr.data)) {
|
||||
if (!looks_like_hex_int(curr.data))
|
||||
if (looks_like_hex_int(curr.data)) {
|
||||
if (has_operand_metadata(curr, "imm32"))
|
||||
emit_hex_bytes(new_l, curr, 4);
|
||||
else if (has_operand_metadata(curr, "imm16"))
|
||||
emit_hex_bytes(new_l, curr, 2);
|
||||
else if (has_operand_metadata(curr, "imm8"))
|
||||
emit_hex_bytes(new_l, curr, 1);
|
||||
else if (has_operand_metadata(curr, "disp8"))
|
||||
raise << "can't use /disp8 in a non-code segment\n" << end();
|
||||
else if (has_operand_metadata(curr, "disp16"))
|
||||
raise << "can't use /disp16 in a non-code segment\n" << end();
|
||||
else if (has_operand_metadata(curr, "disp32"))
|
||||
raise << "can't use /disp32 in a non-code segment\n" << end();
|
||||
else
|
||||
new_l.words.push_back(curr);
|
||||
}
|
||||
else {
|
||||
raise << "missing reference to global '" << curr.data << "'\n" << end();
|
||||
new_l.words.push_back(curr);
|
||||
new_l.words.push_back(curr);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
trace(99, "transform") << curr.data << " maps to " << HEXWORD << get(address, curr.data) << end();
|
||||
|
@ -193,6 +210,19 @@ y:
|
|||
+load: 0x0a000003 -> 0a
|
||||
$error: 0
|
||||
|
||||
:(scenario raw_number_with_imm32_in_data_segment)
|
||||
== 0x1
|
||||
b9 x/imm32
|
||||
== 0x0a000000
|
||||
x:
|
||||
1/imm32
|
||||
# check that we loaded 'x' with the address of 1
|
||||
+load: 0x0a000000 -> 01
|
||||
+load: 0x0a000001 -> 00
|
||||
+load: 0x0a000002 -> 00
|
||||
+load: 0x0a000003 -> 00
|
||||
$error: 0
|
||||
|
||||
:(scenario duplicate_global_variable)
|
||||
% Hide_errors = true;
|
||||
== 0x1
|
||||
|
|
|
@ -82,12 +82,12 @@ $check-ints-equal:end:
|
|||
# convenient to have when printing messages and so on
|
||||
Newline:
|
||||
# size
|
||||
01 00 00 00
|
||||
1/imm32
|
||||
# data
|
||||
0a/newline
|
||||
|
||||
# every test failure increments this counter
|
||||
Num-test-failures:
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -48,16 +48,16 @@ $new-segment:end:
|
|||
# various constants used here were found in the Linux sources (search for file mman-common.h)
|
||||
_mmap-new-segment: # type mmap_arg_struct
|
||||
# addr
|
||||
00 00 00 00 # null
|
||||
0/imm32
|
||||
# len
|
||||
00 00 00 00 # 0x1000
|
||||
0/imm32
|
||||
# protection flags
|
||||
03 00 00 00 # PROT_READ | PROT_WRITE
|
||||
3/imm32 # PROT_READ | PROT_WRITE
|
||||
# sharing flags
|
||||
22 00 00 00 # MAP_PRIVATE | MAP_ANONYMOUS
|
||||
0x22/imm32 # MAP_PRIVATE | MAP_ANONYMOUS
|
||||
# fd
|
||||
ff ff ff ff # -1 since MAP_ANONYMOUS is specified
|
||||
-1/imm32 # since MAP_ANONYMOUS is specified
|
||||
# offset
|
||||
00 00 00 00 # 0 since MAP_ANONYMOUS is specified
|
||||
0/imm32 # since MAP_ANONYMOUS is specified
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
|
||||
# We'll save the address of the trace segment here.
|
||||
Trace-stream:
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
|
||||
# Fake trace-stream for tests.
|
||||
# Also illustrates the layout of the real trace-stream (segment).
|
||||
_test-trace-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -154,11 +154,11 @@ test-write-appends:
|
|||
|
||||
_test-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -351,11 +351,11 @@ test-read-returns-0-on-end-of-file:
|
|||
|
||||
_test-tmp-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
# buffered-file.
|
||||
Stdin:
|
||||
# file descriptor or (address stream)
|
||||
00 00 00 00 # 0 = standard input
|
||||
0/imm32 # standard input
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
@ -291,11 +291,11 @@ _test-buffered-file:
|
|||
# file descriptor or (address stream)
|
||||
_test-stream/imm32
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (6)
|
||||
06 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
6/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 # 6 bytes
|
||||
|
||||
|
|
|
@ -228,12 +228,12 @@ test-write-stream-appends:
|
|||
|
||||
_test-stream2:
|
||||
# current write index
|
||||
04 00 00 00
|
||||
4/imm32
|
||||
# current read index
|
||||
01 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
1/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
41 42 43 44 00 00 00 00 # 8 bytes
|
||||
41/A 42/B 43/C 44/D 00 00 00 00 # 8 bytes
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
# The buffered file for standard output.
|
||||
Stdout:
|
||||
# file descriptor or (address stream)
|
||||
01 00 00 00 # 1 = standard output
|
||||
1/imm32 # standard output
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -96,13 +96,13 @@ $error-byte:dead-end:
|
|||
# The buffered file for standard error.
|
||||
Stderr:
|
||||
# file descriptor or (address stream)
|
||||
02 00 00 00 # 1 = standard error
|
||||
2/imm32 # standard error
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
# hitherto unused bit of memory.
|
||||
Heap:
|
||||
Start-of-heap/imm32 # curr
|
||||
00 00 00 0b # limit = 0x0b000000; keep sync'd with DATA_SEGMENT + SEGMENT_ALIGNMENT
|
||||
0x0b000000/imm32 # limit; keep sync'd with DATA_SEGMENT + SEGMENT_ALIGNMENT
|
||||
|
||||
== code
|
||||
# instruction effective address register displacement immediate
|
||||
|
|
|
@ -574,26 +574,26 @@ $is-digit?:end:
|
|||
|
||||
== data
|
||||
|
||||
Look: # (char)
|
||||
00 00 00 00 # = 0
|
||||
Look: # (char with some extra padding)
|
||||
0/imm32
|
||||
|
||||
_test-output-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
_test-error-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -771,26 +771,26 @@ $is-digit?:end:
|
|||
|
||||
== data
|
||||
|
||||
Look: # (char)
|
||||
00 00 00 00 # = 0
|
||||
Look: # (char with some extra padding)
|
||||
0/imm32
|
||||
|
||||
_test-output-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
_test-error-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
|
|
@ -356,6 +356,6 @@ test-lookup-failure:
|
|||
|
||||
# Monotonically increasing counter for calls to 'new'
|
||||
Next-alloc-id:
|
||||
01 00 00 00 # 1
|
||||
1/imm32
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -1511,11 +1511,11 @@ test-skip-until-newline:
|
|||
|
||||
_test-error-stream:
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (= 8)
|
||||
08 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
8/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 00 00 # 8 bytes
|
||||
|
||||
|
@ -1524,11 +1524,11 @@ _test-error-buffered-file:
|
|||
# file descriptor or (address stream)
|
||||
_test-error-stream/imm32
|
||||
# current write index
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
# current read index
|
||||
00 00 00 00
|
||||
# length (6)
|
||||
06 00 00 00
|
||||
0/imm32
|
||||
# length
|
||||
6/imm32
|
||||
# data
|
||||
00 00 00 00 00 00 # 6 bytes
|
||||
|
||||
|
|
|
@ -343,7 +343,7 @@ write-stderr: # s : (address array byte) -> <void>
|
|||
|
||||
Newline:
|
||||
# size
|
||||
01 00 00 00
|
||||
1/imm32
|
||||
# data
|
||||
0a/newline
|
||||
|
||||
|
|
|
@ -29,16 +29,16 @@
|
|||
# various constants used here were found in the Linux sources (search for file mman-common.h)
|
||||
Mmap-new-segment: # type mmap_arg_struct
|
||||
# addr
|
||||
00 00 00 00 # null
|
||||
0/imm32
|
||||
# len
|
||||
00 01 00 00 # 0x1000
|
||||
0x100/imm32
|
||||
# protection flags
|
||||
03 00 00 00 # PROT_READ | PROT_WRITE
|
||||
3/imm32 # PROT_READ | PROT_WRITE
|
||||
# sharing flags
|
||||
22 00 00 00 # MAP_PRIVATE | MAP_ANONYMOUS
|
||||
0x22/imm32 # MAP_PRIVATE | MAP_ANONYMOUS
|
||||
# fd
|
||||
ff ff ff ff # -1 since MAP_ANONYMOUS is specified
|
||||
-1/imm32 # since MAP_ANONYMOUS is specified
|
||||
# offset
|
||||
00 00 00 00 # 0 since MAP_ANONYMOUS is specified
|
||||
0/imm32 # since MAP_ANONYMOUS is specified
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -35,6 +35,6 @@ cd/syscall 0x80/imm8
|
|||
== data
|
||||
|
||||
X:
|
||||
00 00 00 00 # space for read() to write to
|
||||
0/imm32 # space for read() to write to
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
== data
|
||||
|
||||
Size: # size of string
|
||||
0e 00 00 00 # 14
|
||||
0x0e/imm32 # 14
|
||||
X: # string to print
|
||||
48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00
|
||||
# H e l l o , ␣ w o r l d ! newline null
|
||||
|
|
|
@ -94,12 +94,13 @@
|
|||
== data
|
||||
|
||||
Stream:
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
A:
|
||||
61 00 00 00
|
||||
61/imm32/A
|
||||
B:
|
||||
00 00 00 00
|
||||
0/imm32
|
||||
Filename:
|
||||
2e 66 6f 6f 00 00 00 00
|
||||
# . f o o null
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
Loading…
Reference in New Issue