aboutsummaryrefslogtreecommitdiff
path: root/bfc.S
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-12-28 15:39:57 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2024-12-28 15:39:57 +0100
commit9e99fb787c3d5b13d8bc24a3b5193691e9f79e45 (patch)
tree28f9d57eb7cfe65c730f706ed103ee80f1fe44b7 /bfc.S
parente91a05788ba7e765eca7df2c93ce2650a24d85fb (diff)
elf: add null section
Diffstat (limited to 'bfc.S')
-rw-r--r--bfc.S77
1 files changed, 27 insertions, 50 deletions
diff --git a/bfc.S b/bfc.S
index 134d2d1..f20d3bf 100644
--- a/bfc.S
+++ b/bfc.S
@@ -11,7 +11,14 @@
.section translations, "a"
t_init:
- mov $0x3001b0, %rbx
+ mov $SYS_BRK, %rax
+ mov $0x0, %rdi
+ syscall
+ add $0x400, %rax
+ mov %rax, %rbx
+ mov %rax, %rdi
+ mov $SYS_BRK, %rax
+ syscall
t_init_end:
t_exit:
@@ -73,63 +80,41 @@ c_elf_header:
.byte 0x1 # ELFv1
.byte 0x0 # System V ABI
.quad 0x0 #
- .hword 0x02 # Executable
+ .hword 0x2 # Executable
.hword 0x3e # AMD x86-64
.int 0x1 # ELFv1
- .quad 0x4005b0 # Entry
+ .quad 0x400148 # Entry
.quad 0x40 # Program Header Offset
- .quad 0xb0 # TODO: Section Header Offset
+ .quad 0x78 # TODO: Section Header Offset
.int 0x0 #
.hword 0x40 # ELF Header Size
.hword 0x38 # Program Header Table Entry Size
- .hword 0x2 # TODO: Number Of Entries in Program Header Table
+ .hword 0x1 # TODO: Number Of Entries in Program Header Table
.hword 0x40 # Section Header Table Entry Size
.hword 0x3 # TODO: Number Of Entries in Section Header Table
.hword 0x2 # TODO: Index of Section Header Table Entry containing section names
-c_elf_data_program_header:
- .int 0x1 # Loadable
- .int 0x6 # Read Write
- .quad 0x1b0 # Offset in ELF
- .quad 0x3001b0 # Virtual Address
- .quad 0x3001b0 # Physical Address
- .quad 0x400 # Virtual Size
- .quad 0x400 # Size in file
- .quad 0x1000 # Aligning
-
-c_elf_data_section_header:
- .int 0x1 # Index of name in SHSTRTAB
- .int 0x1 # Load as Program data
- .quad 0x3 # Is Writable and Readable
- .quad 0x3001b0 # Virtual Address
- .quad 0x1b0 # Offset in ELF
- .quad 0x400 # Size
- .int 0x0 # Index
- .int 0x0 # Info
- .quad 0x1000 # Aligning
- .quad 0x0
+c_elf_null_section_header:
+ .fill 0x40, 1, 0
c_elf_shstrtab_section_header:
- .int 0xb # Index of name in SHSTRTAB
+ .int 0x6 # Index of name in SHSTRTAB
.int 0x3 # Don't load
.quad 0x0 # No Attributes
.quad 0x0 # Not mapped to virtual memory
- .quad 0x170 # Offset in ELF
- .quad 0x40 # Size in ELF
+ .quad 0x138 # Offset in ELF
+ .quad 0xf # Size in ELF
.int 0x0 # Index
- .int 0x0 # No Inof
+ .int 0x0 # No Info
.quad 0x1 # Aligning
.quad 0x0
c_elf_shstrtab:
.byte 0
- .asciz "data"
.asciz "code"
.asciz "shstrtab"
-
-c_elf_data:
- .fill 0x400, 1, 0
+ .byte 0
c_usage_message:
.asciz "bfc [input file] [output file]\n"
@@ -139,9 +124,9 @@ c_usage_message:
c_elf_code_program_header:
.int 0x1 # Loadable
.int 0x5 # Read Executable
- .quad 0x5b0 # Offset in ELF
- .quad 0x4005b0 # Virtual Address
- .quad 0x4005b0 # Physical Address
+ .quad 0x148 # Offset in ELF
+ .quad 0x400148 # Virtual Address
+ .quad 0x400148 # Physical Address
v_elf_code_program_header_file_size:
.quad 0x0 # File Size
v_elf_code_program_header_memory_size:
@@ -149,11 +134,11 @@ v_elf_code_program_header_memory_size:
.quad 0x1000 # Aligning
c_elf_code_section_header:
- .int 0x6 # Index of name in SHSTRTAB
+ .int 0x1 # Index of name in SHSTRTAB
.int 0x1 # Load as program data
.quad 0x6 # Is Readable and Executable
- .quad 0x4005b0 # Virtual Address
- .quad 0x5b0 # Offset in ELF
+ .quad 0x400148 # Virtual Address
+ .quad 0x148 # Offset in ELF
v_elf_code_section_header_size:
.quad 0x0
.int 0x0 # Index
@@ -298,15 +283,11 @@ l_read_loop_end:
mov $0x40, %rdx
call f_write_to_output
- mov $c_elf_data_program_header, %rsi
- mov $0x38, %rdx
- call f_write_to_output
-
mov $c_elf_code_program_header, %rsi
mov $0x38, %rdx
call f_write_to_output
- mov $c_elf_data_section_header, %rsi
+ mov $c_elf_null_section_header, %rsi
mov $0x40, %rdx
call f_write_to_output
@@ -319,11 +300,7 @@ l_read_loop_end:
call f_write_to_output
mov $c_elf_shstrtab, %rsi
- mov $0x40, %rdx
- call f_write_to_output
-
- mov $c_elf_data, %rsi
- mov $0x400, %rdx
+ mov $0x10, %rdx
call f_write_to_output
mov $v_buffer_start, %rbx