aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <JozanLeClerc@noemail.net>2020-11-19 19:40:03 +0000
committerJozanLeClerc <JozanLeClerc@noemail.net>2020-11-19 19:40:03 +0000
commit6126cb3f4173ae8e440b35e02e166a5c86378db0 (patch)
tree61d2c6def8a4e7e34236fe18e804e728e2cdea3a
parentPretty cool (diff)
downloadbsdsetsid-6126cb3f4173ae8e440b35e02e166a5c86378db0.tar.gz
bsdsetsid-6126cb3f4173ae8e440b35e02e166a5c86378db0.tar.bz2
bsdsetsid-6126cb3f4173ae8e440b35e02e166a5c86378db0.tar.xz
bsdsetsid-6126cb3f4173ae8e440b35e02e166a5c86378db0.tar.zst
bsdsetsid-6126cb3f4173ae8e440b35e02e166a5c86378db0.zip
In progress
FossilOrigin-Name: 0e3af2b7fdaa117d45dd21f15813cadbb0a59c81
-rw-r--r--Makefile7
-rw-r--r--src/c_bsdsetsid.S49
-rw-r--r--src/u_print.S28
-rw-r--r--src/u_strlen.S16
4 files changed, 80 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index bbd0931..67a99cc 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ PREFIX := /usr/local/
DESTDIR :=
SRCS := ${SRCS_DIR}c_bsdsetsid.S
+SRCS += ${SRCS_DIR}u_print.S
SRCS += ${SRCS_DIR}u_strlen.S
OBJS = ${SRCS:.S=.o}
@@ -75,3 +76,9 @@ clean:
${RM} ${OBJS} ${NAME}
.PHONY: all clean
+
+
+# Files prefixes index
+# --------------------
+# c_ -> core program related
+# u_ -> utils related
diff --git a/src/c_bsdsetsid.S b/src/c_bsdsetsid.S
index 73ab582..810fe8c 100644
--- a/src/c_bsdsetsid.S
+++ b/src/c_bsdsetsid.S
@@ -1,28 +1,37 @@
.text
-.extern u_strlen
-.globl main
+.extern u_strlen
+.extern u_pout
+.extern u_perr
+.globl main
main:
xorq %rcx, %rcx
- movq (%rsi, %rcx, 8), %rsi
- movq %rsi, %rdi
- callq u_strlen
- movq $0x1, %rdi
- movq %rax, %rdx
- xorq %rax, %rax
- movb $0x4, %al
- syscall
- movq $0x1, %rdi
- leaq nl, %rsi
- movq $0x1, %rdx
- xorq %rax, %rax
- movq $0x4, %rax
- syscall
- xorq %rax, %rax
- xorq %rax, %rax
+ callq c_push
+ movq (%rsi, %rcx, 8), %rdi
+ callq u_pout
+ callq c_pop
+ inc %rcx
+ callq c_push
+ movq (%rsi, %rcx, 8), %rdi
+ callq u_pout
+ callq c_pop
xorq %rdi, %rdi
- movb $0x1, %al
+ xorq %rax, %rax
+ movb $0x1, %al # SYS_exit
syscall
+c_push:
+ movq %rdx, %r8
+ movq %rsi, %r9
+ movq %rdi, %r10
+ retq
+
+c_pop:
+ movq %r8, %rdi
+ movq %r9, %rsi
+ movq %r10, %rdx
+ retq
+
.data
- nl: .asciz "\n"
+nl: .asciz "\n"
+asd: .asciz "hey\n"
diff --git a/src/u_print.S b/src/u_print.S
new file mode 100644
index 0000000..3866868
--- /dev/null
+++ b/src/u_print.S
@@ -0,0 +1,28 @@
+.text
+.extern u_strlen
+.globl u_pout
+.globl u_perr
+
+u_pout:
+ movq $0x1, %r11 # stdout
+ jmp u_print
+
+u_perr:
+ movq $0x2, %r11 # stderr
+ jmp u_print
+
+u_print:
+ callq u_strlen
+ movq %rax, %rdx
+ movq %rdi, %rsi
+ movq %r11, %rdi
+ movq $0x4, %rax # SYS_write
+ syscall
+ leaq nl, %rsi
+ movq $0x1, %rdx
+ movq $0x4, %rax # SYS_write
+ syscall
+ retq
+
+.data
+nl: .asciz "\n"
diff --git a/src/u_strlen.S b/src/u_strlen.S
new file mode 100644
index 0000000..27d9663
--- /dev/null
+++ b/src/u_strlen.S
@@ -0,0 +1,16 @@
+.text
+.globl u_strlen
+
+u_strlen:
+ movq %rdi, %rcx
+
+u_loop:
+ cmpb $0x0, (%rcx)
+ je u_ret
+ inc %rcx
+ jmp u_loop
+
+u_ret:
+ sub %rdi, %rcx
+ movq %rcx, %rax
+ retq