Skip to content

Commit

Permalink
added nasm
Browse files Browse the repository at this point in the history
added root directory, binary, and libraries for nasm to the dynamic-apps that can be run in bincompat mode.

Signed-off-by: Sina Mahdavi <[email protected]>
  • Loading branch information
sinamhdv committed Sep 24, 2023
1 parent b56aba6 commit 69bde25
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
43 changes: 43 additions & 0 deletions nasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Netwide Assembler

This is the (Nasm) Netwide assembler and it is meant to be used in the binary compatibility mode of Unikraft.

## Content

- `sample_code.s`: a sample assembly code file that can be assembled using Nasm
- `usr/bin/nasm`: the Nasm binary
- `lib/` & `lib64/`: the required libraries for Nasm

## Extract Dynamic Libraries

```console
../extract.sh usr/bin/nasm
```

output:

```
Copying /lib/x86_64-linux-gnu/libc.so.6 ...
Copying /lib64/ld-linux-x86-64.so.2 ...
```

## Run on Linux

```console
nasm sample_code.s
```

## Run on Unikraft

```console
./run.sh -r ../dynamic-apps/nasm/ usr/bin/nasm sample_code.s
```

This should generate the output file `sample_code` which is the assembled machine code generated by Nasm.

We can use this command to check that everything worked properly:

```console
objdump -D -b binary -m i386 -M intel,x86-64 sample_code
```

Binary file added nasm/lib/x86_64-linux-gnu/libc.so.6
Binary file not shown.
Binary file added nasm/lib64/ld-linux-x86-64.so.2
Binary file not shown.
31 changes: 31 additions & 0 deletions nasm/sample_code.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
BITS 64

xor rax, rax
test rdi, rdi
jz end

loop:
cmp byte [rdi], 0
jz end

xor rbx, rbx
mov bl, byte [rdi]
cmp bl, 0x5a
ja loop_end

push rax
push rdi
mov rdi, rbx
mov rax, 0x403000
call rax
pop rdi
mov byte [rdi], al
pop rax
inc rax

loop_end:
inc rdi
jmp loop

end:
ret
Binary file added nasm/usr/bin/nasm
Binary file not shown.

0 comments on commit 69bde25

Please sign in to comment.