diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-07-08 22:57:50 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-07-08 22:57:50 -0700 |
commit | 43b170ea0375e829cf5208a88ab9705aa4be413d (patch) | |
tree | fc5273eab927767940643ee4ddad0d403f5e47ad | |
parent | 1e1eca1742ec396e5daa686e6b425dbd11f25baf (diff) | |
download | mu-43b170ea0375e829cf5208a88ab9705aa4be413d.tar.gz |
4330 - start allocating data/stack/heap segments
ex4 now writes to the (global) data segment, rather than trying to write to the code segment. We still need to specify the other segments in the generated ELF, though.
-rw-r--r-- | subx/020elf.cc | 10 | ||||
-rw-r--r-- | subx/021translate.cc | 2 | ||||
-rwxr-xr-x | subx/ex4 | bin | 113 -> 113 bytes | |||
-rw-r--r-- | subx/ex4.subx | 2 |
4 files changed, 12 insertions, 2 deletions
diff --git a/subx/020elf.cc b/subx/020elf.cc index d5f1e109..807010ea 100644 --- a/subx/020elf.cc +++ b/subx/020elf.cc @@ -6,6 +6,7 @@ if (is_equal(argv[1], "run")) { assert(argc > 2); reset(); cerr << std::hex; + initialize_mem(); load_elf(argv[2]); while (EIP < End_of_program) // weak final-gasp termination check run_one_instruction(); @@ -90,6 +91,15 @@ void load_segment_from_program_header(uint8_t* elf_contents, size_t size, uint32 End_of_program = p_vaddr+p_memsz; } +void initialize_mem() { + // Very primitive/fixed/insecure ELF segments for now. + // code: 0x08048000 -> 0x08048fff + // data: 0x08049000 -> 0x08049fff + // heap: 0x0804a000 -> 0x0804afff + // stack: 0x0804bfff -> 0x0804b000 (downward) + Mem.resize(0x0804c000 - 0x08048000); +} + inline uint32_t u32_in(uint8_t* p) { return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; } diff --git a/subx/021translate.cc b/subx/021translate.cc index 5757805e..c32b8fef 100644 --- a/subx/021translate.cc +++ b/subx/021translate.cc @@ -34,7 +34,7 @@ void perform_all_transforms(string& program) { // write out the current Memory contents from address 1 to End_of_program to a // bare-bones ELF file with a single section/segment and a hard-coded origin address. void dump_elf(const string& program, const char* filename) { - Mem.resize(1024); + initialize_mem(); // load program into memory, filtering out comments load_program(program, 1); // Not where 'program' should be loaded for running. // But we're not going to run it right now, so we diff --git a/subx/ex4 b/subx/ex4 index 8fd70fbb..b20490ad 100755 --- a/subx/ex4 +++ b/subx/ex4 Binary files differdiff --git a/subx/ex4.subx b/subx/ex4.subx index 98b9f55a..303cba1e 100644 --- a/subx/ex4.subx +++ b/subx/ex4.subx @@ -8,7 +8,7 @@ # fd = 1 bb 1/imm32 # copy 1 to EBX # set location to write to - b9 00 80 04 08 # copy 0x08040000 to ECX + b9 00 90 04 08 # copy 0x08040000 to ECX # size = 1 character ba 1/imm32 # copy 1 to EDX # syscall = read |