Skip to content

Commit 1c748d3

Browse files
committed
Add RISC-V 32-bit/64-bit ELF templates
1 parent d32b771 commit 1c748d3

8 files changed

+281
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
; build with:
2+
; nasm elf_dll_riscv32le_template.s -f bin -o template_riscv32le_linux_dll.bin
3+
4+
BITS 32
5+
6+
org 0
7+
8+
ehdr:
9+
db 0x7f, "ELF", 1, 1, 1, 0 ; e_ident
10+
db 0, 0, 0, 0, 0, 0, 0, 0
11+
dw 3 ; e_type = ET_DYN
12+
dw 0xF3 ; e_machine = EM_RISCV
13+
dd 1 ; e_version = EV_CURRENT
14+
dd _start ; e_entry = _start
15+
dd phdr - $$ ; e_phoff
16+
dd shdr - $$ ; e_shoff
17+
dd 0 ; e_flags
18+
dw ehdrsize ; e_ehsize
19+
dw phdrsize ; e_phentsize
20+
dw 2 ; e_phnum
21+
dw shentsize ; e_shentsize
22+
dw 2 ; e_shnum
23+
dw 1 ; e_shstrndx
24+
25+
ehdrsize equ $ - ehdr
26+
27+
phdr:
28+
dd 1 ; p_type = PT_LOAD
29+
dd 0 ; p_offset
30+
dd $$ ; p_vaddr
31+
dd $$ ; p_paddr
32+
dd 0xDEADBEEF ; p_filesz
33+
dd 0xDEADBEEF ; p_memsz
34+
dd 7 ; p_flags = rwx
35+
dd 0x1000 ; p_align
36+
37+
phdrsize equ $ - phdr
38+
39+
dd 2 ; p_type = PT_DYNAMIC
40+
dd 7 ; p_flags = rwx
41+
dd dynsection ; p_offset
42+
dd dynsection ; p_vaddr
43+
dd dynsection ; p_vaddr
44+
dd dynsz ; p_filesz
45+
dd dynsz ; p_memsz
46+
dd 0x1000 ; p_align
47+
48+
shdr:
49+
dd 1 ; sh_name
50+
dd 6 ; sh_type = SHT_DYNAMIC
51+
dd 0 ; sh_flags
52+
dd dynsection ; sh_addr
53+
dd dynsection ; sh_offset
54+
dd dynsz ; sh_size
55+
dd 0 ; sh_link
56+
dd 0 ; sh_info
57+
dd 8 ; sh_addralign
58+
dd 7 ; sh_entsize
59+
shentsize equ $ - shdr
60+
dd 0 ; sh_name
61+
dd 3 ; sh_type = SHT_STRTAB
62+
dd 0 ; sh_flags
63+
dd strtab ; sh_addr
64+
dd strtab ; sh_offset
65+
dd strtabsz ; sh_size
66+
dd 0 ; sh_link
67+
dd 0 ; sh_info
68+
dd 0 ; sh_addralign
69+
dd 0 ; sh_entsize
70+
71+
dynsection:
72+
; DT_INIT
73+
dd 0x0c
74+
dd _start
75+
; DT_STRTAB
76+
dd 0x05
77+
dd strtab
78+
; DT_SYMTAB
79+
dd 0x06
80+
dd strtab
81+
; DT_STRSZ
82+
dd 0x0a
83+
dd 0
84+
; DT_SYMENT
85+
dd 0x0b
86+
dd 0
87+
; DT_NULL
88+
dd 0x00
89+
dd 0
90+
dynsz equ $ - dynsection
91+
92+
strtab:
93+
db 0
94+
db 0
95+
strtabsz equ $ - strtab
96+
97+
global _start
98+
_start:
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
; build with:
2+
; nasm elf_dll_riscv64le_template.s -f bin -o template_riscv64le_linux_dll.bin
3+
4+
BITS 64
5+
6+
org 0
7+
8+
ehdr: ; Elf64_Ehdr
9+
db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident
10+
db 0, 0, 0, 0, 0, 0, 0, 0 ;
11+
dw 3 ; e_type = ET_DYN
12+
dw 0xF3 ; e_machine = RISCV
13+
dd 1 ; e_version
14+
dq _start ; e_entry
15+
dq phdr - $$ ; e_phoff
16+
dq shdr - $$ ; e_shoff
17+
dd 0 ; e_flags
18+
dw ehdrsize ; e_ehsize
19+
dw phdrsize ; e_phentsize
20+
dw 2 ; e_phnum
21+
dw shentsize ; e_shentsize
22+
dw 2 ; e_shnum
23+
dw 1 ; e_shstrndx
24+
25+
ehdrsize equ $ - ehdr
26+
27+
phdr: ; Elf32_Phdr
28+
dd 1 ; p_type = PT_LOAD
29+
dd 7 ; p_flags = rwx
30+
dq 0 ; p_offset
31+
dq $$ ; p_vaddr
32+
dq $$ ; p_paddr
33+
dq 0xDEADBEEF ; p_filesz
34+
dq 0xDEADBEEF ; p_memsz
35+
dq 0x1000 ; p_align
36+
37+
phdrsize equ $ - phdr
38+
dd 2 ; p_type = PT_DYNAMIC
39+
dd 7 ; p_flags = rwx
40+
dq dynsection ; p_offset
41+
dq dynsection ; p_vaddr
42+
dq dynsection ; p_vaddr
43+
dq dynsz ; p_filesz
44+
dq dynsz ; p_memsz
45+
dq 0x1000 ; p_align
46+
47+
shdr:
48+
dd 1 ; sh_name
49+
dd 6 ; sh_type = SHT_DYNAMIC
50+
dq 0 ; sh_flags
51+
dq dynsection ; sh_addr
52+
dq dynsection ; sh_offset
53+
dq dynsz ; sh_size
54+
dd 0 ; sh_link
55+
dd 0 ; sh_info
56+
dq 8 ; sh_addralign
57+
dq 7 ; sh_entsize
58+
shentsize equ $ - shdr
59+
dd 0 ; sh_name
60+
dd 3 ; sh_type = SHT_STRTAB
61+
dq 0 ; sh_flags
62+
dq strtab ; sh_addr
63+
dq strtab ; sh_offset
64+
dq strtabsz ; sh_size
65+
dd 0 ; sh_link
66+
dd 0 ; sh_info
67+
dq 0 ; sh_addralign
68+
dq 0 ; sh_entsize
69+
70+
dynsection:
71+
; DT_INIT
72+
dq 0x0c
73+
dq _start
74+
; DT_STRTAB
75+
dq 0x05
76+
dq strtab
77+
; DT_SYMTAB
78+
dq 0x06
79+
dq strtab
80+
; DT_STRSZ
81+
dq 0x0a
82+
dq 0
83+
; DT_SYMENT
84+
dq 0x0b
85+
dq 0
86+
; DT_NULL
87+
dq 0x00
88+
dq 0
89+
90+
dynsz equ $ - dynsection
91+
92+
strtab:
93+
db 0
94+
db 0
95+
strtabsz equ $ - strtab
96+
97+
align 16
98+
global _start
99+
_start:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; build with:
2+
; nasm elf_riscv32le_template.s -f bin -o template_riscv32le_linux.bin
3+
4+
BITS 32
5+
6+
org 0x00010000
7+
8+
ehdr: ; Elf32_Ehdr
9+
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident
10+
db 0, 0, 0, 0, 0, 0, 0, 0 ;
11+
dw 2 ; e_type = ET_EXEC for an executable
12+
dw 0xF3 ; e_machine = RISCV
13+
dd 1 ; e_version
14+
dd _start ; e_entry
15+
dd phdr - $$ ; e_phoff
16+
dd 0 ; e_shoff
17+
dd 0 ; e_flags
18+
dw ehdrsize ; e_ehsize
19+
dw phdrsize ; e_phentsize
20+
dw 1 ; e_phnum
21+
dw 0 ; e_shentsize
22+
dw 0 ; e_shnum
23+
dw 0 ; e_shstrndx
24+
25+
ehdrsize equ $ - ehdr
26+
27+
phdr: ; Elf32_Phdr
28+
dd 1 ; p_type = PT_LOAD
29+
dd 0 ; p_offset
30+
dd $$ ; p_vaddr
31+
dd $$ ; p_paddr
32+
dd 0xDEADBEEF ; p_filesz
33+
dd 0xDEADBEEF ; p_memsz
34+
dd 7 ; p_flags = rwx
35+
dd 0x1000 ; p_align
36+
37+
phdrsize equ $ - phdr
38+
39+
global _start
40+
41+
_start:
42+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; build with:
2+
; nasm elf_riscv64le_template.s -f bin -o template_riscv64le_linux.bin
3+
4+
BITS 64
5+
6+
org 0x00400000
7+
8+
ehdr: ; Elf32_Ehdr
9+
db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident
10+
db 0, 0, 0, 0, 0, 0, 0, 0 ;
11+
dw 2 ; e_type = ET_EXEC for an executable
12+
dw 0xF3 ; e_machine = RISCV
13+
dd 1 ; e_version
14+
dq _start ; e_entry
15+
dq phdr - $$ ; e_phoff
16+
dq 0 ; e_shoff
17+
dd 0 ; e_flags
18+
dw ehdrsize ; e_ehsize
19+
dw phdrsize ; e_phentsize
20+
dw 1 ; e_phnum
21+
dw 0 ; e_shentsize
22+
dw 0 ; e_shnum
23+
dw 0 ; e_shstrndx
24+
25+
ehdrsize equ $ - ehdr
26+
27+
phdr: ; Elf32_Phdr
28+
dd 1 ; p_type = PT_LOAD
29+
dd 7 ; p_flags = rwx
30+
dq 0 ; p_offset
31+
dq $$ ; p_vaddr
32+
dq $$ ; p_paddr
33+
dq 0xDEADBEEF ; p_filesz
34+
dq 0xDEADBEEF ; p_memsz
35+
dq 0x1000 ; p_align
36+
37+
phdrsize equ $ - phdr
38+
39+
global _start
40+
41+
_start:
42+
84 Bytes
Binary file not shown.
246 Bytes
Binary file not shown.
120 Bytes
Binary file not shown.
416 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)