diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-07-16 11:03:08 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-07-16 11:05:19 -0700 |
commit | 0c57224ccff9727fb699994a4c3d5f5c6d6d1881 (patch) | |
tree | 50608e44d326f83b12381b41bf0ebdb66f8563f8 /subx/021translate.cc | |
parent | 66050b796e436735c74504b90f915dd6bc66b8b0 (diff) | |
download | mu-0c57224ccff9727fb699994a4c3d5f5c6d6d1881.tar.gz |
4356 - subx: first program with a data segment
We read() a character from stdin and write() it out to stdout, saving it to a global variable in between. ELF binaries are inefficient; you can ask for a low alignment, but the kernel may not be able to handle it. If you set up a high alignment then you end up wasting an increasing amount of space in each segment because of the constraint that the offset bear some relationship with the loaded address.
Diffstat (limited to 'subx/021translate.cc')
-rw-r--r-- | subx/021translate.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/subx/021translate.cc b/subx/021translate.cc index 4cecb030..2aa4efaa 100644 --- a/subx/021translate.cc +++ b/subx/021translate.cc @@ -88,9 +88,9 @@ void dump_elf_header(ostream& out, const program& p) { // p_offset emit(p_offset); // p_vaddr - emit(e_entry); + emit(p.segments.at(i).start); // p_paddr - emit(e_entry); + emit(p.segments.at(i).start); // p_filesz uint32_t size = size_of(p.segments.at(i)); assert(size < SEGMENT_SIZE); @@ -101,7 +101,7 @@ void dump_elf_header(ostream& out, const program& p) { uint32_t p_flags = (i == 0) ? /*r-x*/0x5 : /*rw-*/0x6; // convention: only first segment is code emit(p_flags); // p_align - uint32_t p_align = 0x4; + uint32_t p_align = 0x1000; // smaller alignments may not be respected by the kernel emit(p_align); // prepare for next segment |