summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2020-07-18 21:49:29 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2020-07-18 21:49:29 +0200
commitf7d14ea364fc7d592cfe6e5664b3bc7ad72b7804 (patch)
tree512b00dec0e3169c1423ad3ddb8a32fe38a4916b
parent93fb293b9cbed65c5324c51632ef6951c5c23cd5 (diff)
downloadcompilertests-f7d14ea364fc7d592cfe6e5664b3bc7ad72b7804.tar.gz
compilertests-f7d14ea364fc7d592cfe6e5664b3bc7ad72b7804.tar.bz2
playing with small elf binaries in assembly
-rw-r--r--ecomp-c/README5
-rw-r--r--ecomp-c/asm-i386.c14
-rw-r--r--ecomp-c/tests/asm-i386/elf.asm39
3 files changed, 56 insertions, 2 deletions
diff --git a/ecomp-c/README b/ecomp-c/README
index 4e1e88c..0f8e907 100644
--- a/ecomp-c/README
+++ b/ecomp-c/README
@@ -122,6 +122,11 @@ C compiler). We prefer the hierarchical approach
one file per assembly file, load at fixed ORG (sort of in a.out style).
+another assembler, 0:15:00
+
+neested functions allow more efficient compiling as local scopes can
+be dropped and their local symbols.
+
syscalls
--------
diff --git a/ecomp-c/asm-i386.c b/ecomp-c/asm-i386.c
index 431ed52..fc91130 100644
--- a/ecomp-c/asm-i386.c
+++ b/ecomp-c/asm-i386.c
@@ -70,8 +70,8 @@ enum {
};
static int DEBUG_GETCHAR = 0;
-static int DEBUG_SCANNER = 0;
-static int DEBUG_PARSER = 0;
+static int DEBUG_SCANNER = 1;
+static int DEBUG_PARSER = 1;
/* scanner */
@@ -88,6 +88,8 @@ typedef enum {
S_comma,
S_lbrak,
S_rbrak,
+ S_plus,
+ S_minus,
S_eof
} S_Symbol;
@@ -104,6 +106,8 @@ static char *symname[S_eof+1] = {
",",
"[",
"]",
+ "+",
+ "-",
"eof"
};
@@ -385,6 +389,12 @@ static S_Symbol getSym( void )
number( );
s = S_number;
break;
+ case '-':
+ s = S_minus;
+ break;
+ case '+':
+ s = S_plus;
+ break;
case 'f':
identifier( );
if( strcmp( ident, "format" ) == 0 ) {
diff --git a/ecomp-c/tests/asm-i386/elf.asm b/ecomp-c/tests/asm-i386/elf.asm
new file mode 100644
index 0000000..16f40e1
--- /dev/null
+++ b/ecomp-c/tests/asm-i386/elf.asm
@@ -0,0 +1,39 @@
+format binary
+use32
+org $08048000
+ehdr:
+db $7F, "ELF" ; e_ident: magic
+db 1 ; EI_CLASS: ELFCLASS32
+db 1 ; EI_BYTE: ELFDATA2LSB (little endian, 2's complement)
+db 1 ; version of the object file format
+db 0 ; EI_VERSION: EV_CURRENT, ABI version
+dd 0, 0 ; EI_PAD: padding
+dw 2 ; e_type: executable
+dw 3 ; e_machine: Intel 80386
+dd 1 ; e_version: current version
+dd _start ; e_entry: entry address to _start
+dd phdr - $$ ; e_phoff: program header offset at phdr - current position
+dd 0 ; e_shoff, no section header table
+dd 0 ; e_flags
+dw ehdrsize ; e_hsize: header size
+dw phdrsize ; e_phentsize: size of a program header entry
+dw 1 ; e_phnum: 1 entry in the program header table
+dw 0 ; e_shentsize
+dw 0 ; e_shnum
+dw 0 ; e_shstrndx
+ehdrsize = $ - ehdr
+phdr:
+dd 1 ; e_type: PT_LOAD
+dd 0 ; e_offset
+dd $$ ; p_vaddr
+dd 0 ; p_paddr
+dd filesize ; p_filesz
+dd filesize ; p_memsz
+dd 5 ; p_flags: Read & Execute
+dd 0x1000 ; p_align
+phdrsize = $ - phdr
+_start:
+mov eax, 1
+mov ebx, 42
+int $80
+filesize = $ - $$