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.cc19
-rwxr-xr-xsubx/ex9bin147 -> 144 bytes
-rw-r--r--subx/ex9.subx12
3 files changed, 9 insertions, 22 deletions
diff --git a/subx/012elf.cc b/subx/012elf.cc
index 78131090..f82b48aa 100644
--- a/subx/012elf.cc
+++ b/subx/012elf.cc
@@ -68,26 +68,18 @@ void load_elf_contents(uint8_t* elf_contents, size_t size, int argc, char* argv[
 
   // initialize args on stack
   // no envp for now
-//?   cerr << ARGV_POINTER_SEGMENT << " at " << Reg[ESP].u-4 << '\n';
-  push(ARGV_POINTER_SEGMENT);
-//?   cerr << argc-2 << " at " << Reg[ESP].u-4 << '\n';
-  push(argc-/*skip 'subx_bin' and 'run'*/2);
-  // initialize arg data
-  // we wastefully use 2 whole pages of memory for this
+  // we wastefully use a separate page of memory for argv
   uint32_t argv_data = ARGV_DATA_SEGMENT;
-  uint32_t argv_pointers = ARGV_POINTER_SEGMENT;
-  for (int i = /*skip 'subx_bin' and 'run'*/2;  i < argc;  ++i) {
-//?     cerr << "pointer: " << argv_pointers << " => " << argv_data << '\n';
-    write_mem_u32(argv_pointers, argv_data);
-    argv_pointers += sizeof(uint32_t);
-    assert(argv_pointers < ARGV_POINTER_SEGMENT + SEGMENT_SIZE);
+  for (int i = argc-1;  i >= /*skip 'subx_bin' and 'run'*/2;  --i) {
+    dbg << "push " << argv_data << end();
+    push(argv_data);
     for (size_t j = 0;  j <= strlen(argv[i]);  ++j) {
-//?       cerr << "  data: " << argv[i][j] << " (" << NUM(argv[i][j]) << ")\n";
       write_mem_u8(argv_data, argv[i][j]);
       argv_data += sizeof(char);
       assert(argv_data < ARGV_DATA_SEGMENT + SEGMENT_SIZE);
     }
   }
+  push(argc-/*skip 'subx_bin' and 'run'*/2);
 }
 
 void push(uint32_t val) {
@@ -134,7 +126,6 @@ void load_segment_from_program_header(uint8_t* elf_contents, size_t size, uint32
 const int CODE_START = 0x08048000;
 const int SEGMENT_SIZE = 0x1000;
 const int AFTER_STACK = 0x0804c000;
-const int ARGV_POINTER_SEGMENT = 0x0804d000;
 const int ARGV_DATA_SEGMENT = 0x0804e000;
 :(code)
 void initialize_mem() {
diff --git a/subx/ex9 b/subx/ex9
index c7f1e9e6..47c79e3c 100755
--- a/subx/ex9
+++ b/subx/ex9
Binary files differdiff --git a/subx/ex9.subx b/subx/ex9.subx
index b8482c43..9ea547f1 100644
--- a/subx/ex9.subx
+++ b/subx/ex9.subx
@@ -2,16 +2,15 @@
 #
 # To run:
 #   $ subx translate ex9.subx ex9
-#   $ subx run ex9 abc d e f g h
+#   $ subx run ex9 abc de fghi
 # Expected result:
 #   $ echo $?
 #   3  # length of 'abc'
 #
 # At the start of a SubX program:
 #   argc: *ESP
-#   argv: *(ESP+4)
-#   argv[0]: *argv ("ex9" in this case)
-#   argv[1]: *(argv+4)
+#   argv[0]: *(ESP+4)
+#   argv[1]: *(ESP+8)
 #   ...
 # Locals start from ESP-4 downwards.
 
@@ -20,10 +19,7 @@
 # op          subop               mod             rm32          base        index         scale       r32
 # 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
   # var s = argv[1] (EBX)
-    # var s = argv
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              3/r32/EBX   4/disp8         .                       # copy *(ESP+4) to EBX
-    # s = *(s+4)
-  8b/copy                         1/mod/*+disp8   3/rm32/EBX    .           .             .           3/r32/EBX   4/disp8         .                       # copy *(EBX+4) to EBX
+  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              3/r32/EBX   8/disp8         .                       # copy *(ESP+8) to EBX
   # call ascii_length(EBX)
     # prepare call
   55/push                         .               .             .           .             .           .           .               .                       # push EBP
ef='/danisanti/profani-tty/blame/themes/bios?id=6ec3f71a5450c81a10d699fb6df67d19119f8ac8'>^
adb470c4 ^


2df622f9 ^


adb470c4 ^


2df622f9 ^


adb470c4 ^


2df622f9 ^




0ae975c2 ^

2df622f9 ^

adb470c4 ^








a952776b ^
adb470c4 ^
503e0ae3 ^
adb470c4 ^








































84ccee20 ^
adb470c4 ^

d3cc5bd7 ^



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