From c1100182501e2dca7893b3c891470b33c43a71b1 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 3 Jul 2018 16:36:37 -0700 Subject: 4311 - subx running binaries with global variables Learning to use the data segment. Currently, subx can only run the teensy files generated from flat assembler: test4 test5 test7 This is not a priority to fix. These files are just useful references to have around. --- subx/teensy/test7-global.s | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 subx/teensy/test7-global.s (limited to 'subx/teensy/test7-global.s') diff --git a/subx/teensy/test7-global.s b/subx/teensy/test7-global.s new file mode 100644 index 00000000..4cb4e8f3 --- /dev/null +++ b/subx/teensy/test7-global.s @@ -0,0 +1,58 @@ +; https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html +; nasm -f bin test7-global.s -o test7 +; chmod +x test7 +BITS 32 + + org 0x08048000 + +ehdr: ; Elf32_Ehdr + db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident + times 8 db 0 + dw 2 ; e_type + dw 3 ; e_machine + dd 1 ; e_version + dd _start ; e_entry + dd phdr1 - $$ ; e_phoff + dd 0 ; e_shoff + dd 0 ; e_flags + dw ehdrsize ; e_ehsize + dw phdrsize ; e_phentsize + dw 2 ; e_phnum + dw 0 ; e_shentsize + dw 0 ; e_shnum + dw 0 ; e_shstrndx +ehdrsize equ $ - ehdr + +phdr1: ; Elf32_Phdr + dd 1 ; p_type + dd 0 ; p_offset + dd $$ ; p_vaddr + dd $$ ; p_paddr + dd codesize ; p_filesz + dd codesize ; p_memsz + dd 5 ; p_flags = r-x + dd 0x1000 ; p_align +phdrsize equ $ - phdr1 + +phdr2: + dd 1 ; p_type + dd _data - $$ ; p_offset + dd _data ; p_vaddr + dd _data ; p_paddr + dd datasize ; p_filesz + dd datasize ; p_memsz + dd 6 ; p_flags = rw- + dd 0x1000 ; p_align + +_start: + mov ebx, [foo] + mov eax, 1 + int 0x80 + +codesize equ $ - $$ ; TODO: why include the headers?! + +alignb 0x1000 +_data: + foo: dd 42 + +datasize equ $ - _data -- cgit 1.4.1-2-gfad0