about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-09 22:43:40 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-09 22:43:40 -0700
commit1ce67ba21bce706932d0d3b3a6531075cf73c8ce (patch)
tree73424727bf1ba133f758d8495da67f3f5f314da1
parent8291833d086ff74e490dae410e26fc08e480af3d (diff)
downloadmu-1ce67ba21bce706932d0d3b3a6531075cf73c8ce.tar.gz
4332
Minimize memory footprint while running subx ELF binaries. We don't use
memory before address 0x08048000, so we don't need to allocate space for
it.
-rw-r--r--subx/020elf.cc1
-rw-r--r--subx/021translate.cc6
2 files changed, 5 insertions, 2 deletions
diff --git a/subx/020elf.cc b/subx/020elf.cc
index 807010ea..18b52634 100644
--- a/subx/020elf.cc
+++ b/subx/020elf.cc
@@ -7,6 +7,7 @@ if (is_equal(argv[1], "run")) {
   reset();
   cerr << std::hex;
   initialize_mem();
+  Mem_offset = CODE_START;
   load_elf(argv[2]);
   while (EIP < End_of_program)  // weak final-gasp termination check
     run_one_instruction();
diff --git a/subx/021translate.cc b/subx/021translate.cc
index c32b8fef..9ab33026 100644
--- a/subx/021translate.cc
+++ b/subx/021translate.cc
@@ -13,7 +13,8 @@ typedef void (*transform_fn)(const string& input, string& output);
 vector<transform_fn> Transform;
 
 :(before "End Includes")
-const int START = 0x08048000;
+const int CODE_START = 0x08048000;
+const int CODE_SIZE = 0x1000;
 :(before "End Main")
 if (is_equal(argv[1], "translate")) {
   assert(argc > 3);
@@ -68,7 +69,7 @@ void dump_elf_header(ostream& out) {
   // e_version
   O(0x01); O(0x00); O(0x00); O(0x00);
   // e_entry
-  int e_entry = START + /*size of ehdr*/52 + /*size of phdr*/32;
+  int e_entry = CODE_START + /*size of ehdr*/52 + /*size of phdr*/32;
   emit(e_entry);
   // e_phoff -- immediately after ELF header
   int e_phoff = 52;
@@ -108,6 +109,7 @@ void dump_elf_header(ostream& out) {
   emit(e_entry);
   // p_filesz
   uint32_t size = End_of_program - /*we're not using location 0*/1;
+  assert(size < CODE_SIZE);
   emit(size);
   // p_memsz
   emit(size);