aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_bsdsetsid.S131
-rw-r--r--src/e_err.S111
-rw-r--r--src/u_hexdec.S72
-rw-r--r--src/u_print.S67
-rw-r--r--src/u_strlen.S61
-rw-r--r--src/u_strncmp.S81
6 files changed, 0 insertions, 523 deletions
diff --git a/src/c_bsdsetsid.S b/src/c_bsdsetsid.S
deleted file mode 100644
index 5b71669..0000000
--- a/src/c_bsdsetsid.S
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ========================
- * ===== ===============
- * ====== ================
- * ====== ================
- * ====== ==== ==== ==
- * ====== === == = =
- * ====== === = == =
- * = === === = == ====
- * = === === = == = =
- * == ===== ==== ==
- * ========================
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2020 Joe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the organization nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * bsdsetsid: src/c_bsdsetsid.S
- * 2020-11-21 18:47
- * Joe
- *
- * This is the entrypoint of the program.
- */
-
-.data
-status: .space 4, 0x0
-ref_w_opt: .asciz "-w"
-
-.text
-.globl main
-
-c_parent_old:
- mov %rax, %rdi
- lea status, %rsi
- xor %rdx, %rdx
- xor %rcx, %rcx
- xor %rax, %rax
- movb $0x7, %al /* SYS_wait4 */
- syscall
- movq (%rsi), %rax
- and $0xff00, %rax
- shr $0x8, %rax
- push %rax
- jmp u_hexdec
-c_parent_next:
- pop %rdi
- movb $0x7, %al
- xor %rax, %rax
- movb $0x1, %al /* SYS_exit */
- syscall
-
-c_w_opt:
- mov $0x1, %r15
- pop %rdi
- mov %rdi, %r8
- push %rdi
- cmp $0x2, %r8
- jle e_noarg
- jmp .c.main_next
-
-main:
- cmpb $0x1, %dil
- jle e_noarg
- xor %r15, %r15
- push %rdx
- push %rsi
- push %rdi
- lea ref_w_opt, %rdi
- mov $0x3, %rdx
- call u_strncmp
- cmp $0x0, %rax
- je c_w_opt
-.c.main_next:
- xor %rax, %rax
- movb $0x2, %al /* SYS_fork */
- syscall
- test %rax, %rax
- js e_fork
- jz c_child
-
-c_parent:
-# jmp c_exit
- jmp c_parent_old
-
-c_child:
- xor %rax, %rax
- movb $0x93, %al /* SYS_setsid */
- syscall
- test %rax, %rax
- js e_setsid
- xor %rax, %rax
- pop %rdi
- pop %rsi
- pop %rdx
- mov $0x1, %rcx
- mov (%rsi, %rcx, 8), %rdi
- lea 0(%rsi, %rcx, 8), %rsi
-# movb $0x3b, %al /* SYS_execve */
-# syscall
- callq execve
- test %rax, %rax
- js e_execve
-
-c_exit:
- xor %rdi, %rdi
- xor %rax, %rax
- movb $0x1, %al /* SYS_exit */
- syscall
diff --git a/src/e_err.S b/src/e_err.S
deleted file mode 100644
index c8528f7..0000000
--- a/src/e_err.S
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * ========================
- * ===== ===============
- * ====== ================
- * ====== ================
- * ====== ==== ==== ==
- * ====== === == = =
- * ====== === = == =
- * = === === = == ====
- * = === === = == = =
- * == ===== ==== ==
- * ========================
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2020 Joe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the organization nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * bsdsetsid: src/e_err.S
- * 2020-11-22 17:09
- * Joe
- *
- * General error handling happen here.
- */
-
-.data
-nl: .asciz "\n"
-e_setsid_str: .asciz "bsdsetsid: setsid: "
-e_execve_str: .asciz "bsdsetsid: execve: "
-e_fork_str: .asciz "bsdsetsid: fork: "
-e_noarg_str: .asciz "bsdsetsid: no command specified\n"
-
-.text
-.extern strerror
-.globl e_execve
-.globl e_fork
-.globl e_noarg
-.globl e_setsid
-
-e_noarg:
- lea e_noarg_str, %rdi
- call u_perr
- mov $0x1, %rdi
- jmp e_exit
-
-e_fork:
- push %rax
- lea e_fork_str, %rdi
- call u_perr
- pop %rax
- mov %rax, %rdi
- call strerror
- mov %rax, %rdi
- call u_perr
- mov $0x2, %rdi
- jmp e_exit
-
-e_setsid:
- push %rax
- lea e_setsid_str, %rdi
- call u_perr
- pop %rax
- mov %rax, %rdi
- call strerror
- mov %rax, %rdi
- call u_perr
- lea nl, %rdi
- call u_perr
- mov $0x3, %rdi
- jmp e_exit
-
-e_execve:
- push %rax
- lea e_execve_str, %rdi
- call u_perr
- pop %rax
- mov %rax, %rdi
- call strerror
- mov %rax, %rdi
- call u_perr
- lea nl, %rdi
- call u_perr
- mov $0x4, %rdi
- jmp e_exit
-
-e_exit:
- xor %rax, %rax
- movb $0x1, %al /* SYS_exit */
- syscall
diff --git a/src/u_hexdec.S b/src/u_hexdec.S
deleted file mode 100644
index 5e0f019..0000000
--- a/src/u_hexdec.S
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ========================
- * ===== ===============
- * ====== ================
- * ====== ================
- * ====== ==== ==== ==
- * ====== === == = =
- * ====== === = == =
- * = === === = == ====
- * = === === = == = =
- * == ===== ==== ==
- * ========================
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2020 Joe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the organization nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * bsdsetsid: src/u_hexdec.S
- * 2020-11-21 14:00
- * Joe
- *
- * General error handling happen here.
- */
-
-.text
-.globl u_hexdec
-
-u_hexdec:
- xor %r10, %r10
- xor %r9, %r9
- xor %r8, %r8
- mov $0xa, %rbx
- clc
-.u.repeat:
- xor %rdx, %rdx
- idiv %rbx
- or $0x0, %dl
- mov $0x8, %rcx
-.u.shift:
- rcrb $0x1, %dl
- rcr $0x1, %r10
- rcr $0x1, %r9
- rcr $0x1, %r8
- dec %rcx
- and %rcx, %rcx
- jnz .u.shift
- and %rax, %rax
- jnz .u.repeat
- ret
diff --git a/src/u_print.S b/src/u_print.S
deleted file mode 100644
index 36fca6d..0000000
--- a/src/u_print.S
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ========================
- * ===== ===============
- * ====== ================
- * ====== ================
- * ====== ==== ==== ==
- * ====== === == = =
- * ====== === = == =
- * = === === = == ====
- * = === === = == = =
- * == ===== ==== ==
- * ========================
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2020 Joe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the organization nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * bsdsetsid: src/u_print.S
- * 2020-11-19 13:27
- * Joe
- *
- * Util functions to print to standard out or standard error.
- */
-
-.text
-.globl u_pout
-.globl u_perr
-
-u_pout:
- mov $0x1, %r11 /* stdout */
- jmp u_print
-
-u_perr:
- mov $0x2, %r11 /* stderr */
- jmp u_print
-
-u_print:
- call u_strlen
- mov %rax, %rdx
- mov %rdi, %rsi
- mov %r11, %rdi
- mov $0x4, %rax /* SYS_write */
- syscall
- ret
diff --git a/src/u_strlen.S b/src/u_strlen.S
deleted file mode 100644
index aaa6c02..0000000
--- a/src/u_strlen.S
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ========================
- * ===== ===============
- * ====== ================
- * ====== ================
- * ====== ==== ==== ==
- * ====== === == = =
- * ====== === = == =
- * = === === = == ====
- * = === === = == = =
- * == ===== ==== ==
- * ========================
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2020 Joe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the organization nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * bsdsetsid: src/u_strlen.S
- * 2020-11-20 19:25
- * Joe
- *
- * Simple implementation of strlen.
- */
-
-.text
-.globl u_strlen
-
-u_strlen:
- mov %rdi, %rcx
-.u.loop:
- cmpb $0x0, (%rcx)
- je .u.ret
- inc %rcx
- jmp .u.loop
-.u.ret:
- sub %rdi, %rcx
- mov %rcx, %rax
- ret
diff --git a/src/u_strncmp.S b/src/u_strncmp.S
deleted file mode 100644
index 694ae0f..0000000
--- a/src/u_strncmp.S
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ========================
- * ===== ===============
- * ====== ================
- * ====== ================
- * ====== ==== ==== ==
- * ====== === == = =
- * ====== === = == =
- * = === === = == ====
- * = === === = == = =
- * == ===== ==== ==
- * ========================
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2020 Joe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the organization nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * bsdsetsid: src/u_strncmp.S
- * 2020-11-21 18:47
- * Joe
- *
- * General error handling happen here.
- */
-
-.text
-.globl u_strncmp
-
-u_strncmp:
- xor %rcx, %rcx
- dec %rdx
-.u.loop:
- xor %r8, %r8
- xor %r9, %r9
- movb (%rdi, %rcx), %r8b
- movb (%rsi, %rcx), %r9b
- cmpb %r8b, %r9b
- jne .u.retdiff
- cmp %rdx, %rcx
- jge .u.retdiff
- cmpb $0x0, (%rdi, %rcx)
- jne .u.inc
- cmpb $0x0, (%rsi, %rcx)
- je .u.retzer
-.u.inc:
- inc %rcx
- jmp .u.loop
-.u.retdiff:
- xor %r8, %r8
- xor %r9, %r9
- movb (%rdi, %rcx), %r8b
- movb (%rsi, %rcx), %r9b
- sub %r9, %r8
- xor %rax, %rax
- movl %r8d, %eax
- ret
-.u.retzer:
- xor %rax, %rax
- ret