about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
Diffstat (limited to 'subx')
-rw-r--r--subx/012elf.cc22
-rw-r--r--subx/028translate.cc2
-rw-r--r--subx/034compute_segment_address.cc34
-rw-r--r--subx/035labels.cc6
-rw-r--r--subx/036global_variables.cc2
-rwxr-xr-xsubx/apps/crenshaw2-1bin1905 -> 1905 bytes
-rwxr-xr-xsubx/apps/factorialbin1903 -> 1903 bytes
-rwxr-xr-xsubx/examples/ex1bin96 -> 96 bytes
-rwxr-xr-xsubx/examples/ex10bin165 -> 165 bytes
-rwxr-xr-xsubx/examples/ex11bin1125 -> 1125 bytes
-rwxr-xr-xsubx/examples/ex12bin167 -> 167 bytes
-rwxr-xr-xsubx/examples/ex2bin97 -> 97 bytes
-rwxr-xr-xsubx/examples/ex3bin114 -> 114 bytes
-rwxr-xr-xsubx/examples/ex4bin171 -> 171 bytes
-rwxr-xr-xsubx/examples/ex5bin139 -> 139 bytes
-rwxr-xr-xsubx/examples/ex6bin165 -> 165 bytes
-rwxr-xr-xsubx/examples/ex7bin313 -> 313 bytes
-rwxr-xr-xsubx/examples/ex8bin139 -> 139 bytes
-rwxr-xr-xsubx/examples/ex9bin129 -> 129 bytes
19 files changed, 32 insertions, 34 deletions
diff --git a/subx/012elf.cc b/subx/012elf.cc
index 85eb406a..2e10246e 100644
--- a/subx/012elf.cc
+++ b/subx/012elf.cc
@@ -80,7 +80,7 @@ void load_elf_contents(uint8_t* elf_contents, size_t size, int argc, char* argv[
       assert(overlap.find(argv_data) == overlap.end());  // don't bother comparing ARGV and STACK
       write_mem_u8(argv_data, argv[i][j]);
       argv_data += sizeof(char);
-      assert(argv_data < ARGV_DATA_SEGMENT + SEGMENT_SIZE);
+      assert(argv_data < ARGV_DATA_SEGMENT + INITIAL_SEGMENT_SIZE);
     }
   }
   push(argc-/*skip 'subx_bin' and 'run'*/2);
@@ -111,7 +111,7 @@ void load_segment_from_program_header(uint8_t* elf_contents, int segment_index,
 
   if (p_offset + p_filesz > size)
     raise << "Invalid binary; segment at offset " << offset << " is too large: wants to end at " << p_offset+p_filesz << " but the file ends at " << size << '\n' << die();
-  if (p_memsz > INITIAL_SEGMENT_SIZE) {
+  if (p_memsz >= INITIAL_SEGMENT_SIZE) {
     raise << "Code segment too small for SubX; for now please manually increase INITIAL_SEGMENT_SIZE.\n" << end();
     return;
   }
@@ -129,16 +129,14 @@ void load_segment_from_program_header(uint8_t* elf_contents, int segment_index,
 
 :(before "End Includes")
 // Very primitive/fixed/insecure ELF segments for now.
-//   code: 0x08048000 -> 0x08048fff
-//   data/heap: 0x08050000 -> 0x08050fff
-//   stack: 0x08060fff -> 0x08060000 (downward)
-const int SEGMENT_SIZE = 0x1000;
-const int CODE_START = 0x08048000;
-const int DATA_SEGMENT = 0x08050000;
-const int HEAP_SEGMENT = DATA_SEGMENT;
-const int STACK_SEGMENT = 0x08060000;
-const int AFTER_STACK = 0x08060ffc;  // forget final word because of the off-by-one with INITIAL_SEGMENT_SIZE;
-const int ARGV_DATA_SEGMENT = 0x08070000;
+//   code: 0x09000000 -> 0x09ffffff
+//   data/heap: 0x0a000000 -> 0x0affffff
+//   stack: 0x0b000ffc -> 0x0b000000 (downward)
+const int CODE_SEGMENT = 0x09000000;
+const int DATA_SEGMENT = 0x0a000000;
+const int STACK_SEGMENT = 0x0b000000;
+const int AFTER_STACK = 0x0b000ffc;  // forget final word because of the off-by-one with INITIAL_SEGMENT_SIZE;
+const int ARGV_DATA_SEGMENT = 0x0c000000;
 :(code)
 inline uint32_t u32_in(uint8_t* p) {
   return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
diff --git a/subx/028translate.cc b/subx/028translate.cc
index 7330fa74..38f8a223 100644
--- a/subx/028translate.cc
+++ b/subx/028translate.cc
@@ -137,7 +137,7 @@ void write_elf_header(ostream& out, const program& p) {
     emit(p_start);
     // p_filesz
     uint32_t size = num_words(p.segments.at(i));
-    assert(p_offset + size < SEGMENT_SIZE);
+    assert(p_offset + size < INITIAL_SEGMENT_SIZE);
     emit(size);
     // p_memsz
     emit(size);
diff --git a/subx/034compute_segment_address.cc b/subx/034compute_segment_address.cc
index 587f25b4..28aab137 100644
--- a/subx/034compute_segment_address.cc
+++ b/subx/034compute_segment_address.cc
@@ -6,11 +6,11 @@
 == code
 05/add 0x0d0c0b0a/imm32  # add 0x0d0c0b0a to EAX
 # code starts at 0x08048000 + p_offset, which is 0x54 for a single-segment binary
-+load: 0x08048054 -> 05
-+load: 0x08048055 -> 0a
-+load: 0x08048056 -> 0b
-+load: 0x08048057 -> 0c
-+load: 0x08048058 -> 0d
++load: 0x09000054 -> 05
++load: 0x09000055 -> 0a
++load: 0x09000056 -> 0b
++load: 0x09000057 -> 0c
++load: 0x09000058 -> 0d
 +run: add imm32 0x0d0c0b0a to reg EAX
 +run: storing 0x0d0c0b0a
 
@@ -70,16 +70,16 @@ if (Currently_parsing_named_segment) {
 2d/subtract 0xddccbbaa/imm32  # subtract 0xddccbbaa from EAX
 +parse: new segment 'code'
 +parse: prepending to segment 'code'
-+load: 0x08048054 -> 2d
-+load: 0x08048055 -> aa
-+load: 0x08048056 -> bb
-+load: 0x08048057 -> cc
-+load: 0x08048058 -> dd
-+load: 0x08048059 -> 05
-+load: 0x0804805a -> 0a
-+load: 0x0804805b -> 0b
-+load: 0x0804805c -> 0c
-+load: 0x0804805d -> 0d
++load: 0x09000054 -> 2d
++load: 0x09000055 -> aa
++load: 0x09000056 -> bb
++load: 0x09000057 -> cc
++load: 0x09000058 -> dd
++load: 0x09000059 -> 05
++load: 0x0900005a -> 0a
++load: 0x0900005b -> 0b
++load: 0x0900005c -> 0c
++load: 0x0900005d -> 0d
 
 //: compute segment address
 
@@ -93,11 +93,11 @@ void compute_segment_starts(program& p) {
   for (size_t i = 0;  i < p.segments.size();  ++i) {
     segment& curr = p.segments.at(i);
     if (curr.start == 0) {
-      curr.start = CODE_START + i*SEGMENT_SIZE + p_offset;
+      curr.start = CODE_SEGMENT + i*SPACE_FOR_SEGMENT + p_offset;
       trace(99, "transform") << "segment " << i << " begins at address 0x" << HEXWORD << curr.start << end();
     }
     p_offset += size_of(curr);
-    assert(p_offset < SEGMENT_SIZE);  // for now we get less and less available space in each successive segment
+    assert(p_offset < INITIAL_SEGMENT_SIZE);  // for now we get less and less available space in each successive segment
   }
 }
 
diff --git a/subx/035labels.cc b/subx/035labels.cc
index c2965b2c..6461f88e 100644
--- a/subx/035labels.cc
+++ b/subx/035labels.cc
@@ -263,13 +263,13 @@ xz:
 //: ignore them.
 
 :(scenario segment_size_ignores_labels)
-== code  # 0x08048074
+== code  # 0x09000074
 05/add 0x0d0c0b0a/imm32  # 5 bytes
 foo:                     # 0 bytes
-== data  # 0x08049079
+== data  # 0x0a000079
 bar:
 00
-+transform: segment 1 begins at address 0x08049079
++transform: segment 1 begins at address 0x0a000079
 
 :(before "End num_bytes(curr) Special-cases")
 else if (is_label(curr))
diff --git a/subx/036global_variables.cc b/subx/036global_variables.cc
index e34c5b73..b29207bf 100644
--- a/subx/036global_variables.cc
+++ b/subx/036global_variables.cc
@@ -12,7 +12,7 @@ b9/copy x/imm32  # copy to ECX
 == data
 x:
 00 00 00 00
-+transform: global variable 'x' is at address 0x08049079
++transform: global variable 'x' is at address 0x0a000079
 
 :(before "End Level-2 Transforms")
 Transform.push_back(rewrite_global_variables);
diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index 5468a4cb..7ea3fe58 100755
--- a/subx/apps/crenshaw2-1
+++ b/subx/apps/crenshaw2-1
Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial
index cad39e27..b15f8fc7 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differdiff --git a/subx/examples/ex1 b/subx/examples/ex1
index f3c9730d..1c983c03 100755
--- a/subx/examples/ex1
+++ b/subx/examples/ex1
Binary files differdiff --git a/subx/examples/ex10 b/subx/examples/ex10
index 59cbc497..e6d8b3c4 100755
--- a/subx/examples/ex10
+++ b/subx/examples/ex10
Binary files differdiff --git a/subx/examples/ex11 b/subx/examples/ex11
index 78b7a6ae..cf0d0c85 100755
--- a/subx/examples/ex11
+++ b/subx/examples/ex11
Binary files differdiff --git a/subx/examples/ex12 b/subx/examples/ex12
index 236afe98..c13a86ed 100755
--- a/subx/examples/ex12
+++ b/subx/examples/ex12
Binary files differdiff --git a/subx/examples/ex2 b/subx/examples/ex2
index 24e81d3f..f7ddb783 100755
--- a/subx/examples/ex2
+++ b/subx/examples/ex2
Binary files differdiff --git a/subx/examples/ex3 b/subx/examples/ex3
index 5f8160d6..884da188 100755
--- a/subx/examples/ex3
+++ b/subx/examples/ex3
Binary files differdiff --git a/subx/examples/ex4 b/subx/examples/ex4
index 7721c94b..477dab46 100755
--- a/subx/examples/ex4
+++ b/subx/examples/ex4
Binary files differdiff --git a/subx/examples/ex5 b/subx/examples/ex5
index 906846db..090e1f60 100755
--- a/subx/examples/ex5
+++ b/subx/examples/ex5
Binary files differdiff --git a/subx/examples/ex6 b/subx/examples/ex6
index 10e38936..aa84591c 100755
--- a/subx/examples/ex6
+++ b/subx/examples/ex6
Binary files differdiff --git a/subx/examples/ex7 b/subx/examples/ex7
index d756271e..28c5bda9 100755
--- a/subx/examples/ex7
+++ b/subx/examples/ex7
Binary files differdiff --git a/subx/examples/ex8 b/subx/examples/ex8
index d447f676..dda61510 100755
--- a/subx/examples/ex8
+++ b/subx/examples/ex8
Binary files differdiff --git a/subx/examples/ex9 b/subx/examples/ex9
index 144cec89..dc9c0e3c 100755
--- a/subx/examples/ex9
+++ b/subx/examples/ex9
Binary files differ
lt;david.morgan@gmail.com> 2016-04-11 08:29:41 -0400 committer David Morgan <david.morgan@gmail.com> 2016-04-11 08:29:41 -0400 Add bashrc' href='/djm/dotfiles/commit/.bashrc?h=sops&id=bc8d66d1476c59957b8152358ff9b0f3d84936bd'>bc8d66d ^
011cf16 ^
bc8d66d ^






011cf16 ^
bc8d66d ^



























































011cf16 ^













bc8d66d ^


011cf16 ^
bc8d66d ^








011cf16 ^
bc8d66d ^


















011cf16 ^
bc8d66d ^



























011cf16 ^
bc8d66d ^










443f8e3 ^










6177533 ^
1d32352 ^
011cf16 ^









7926f27 ^

1d32352 ^

bc8d66d ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594