commit 7ac4531dbfa5c1733aaca52b202767810da9b6e8
Author: afify <hassan@afify.dev>
Date: Wed, 4 Nov 2020 02:57:46 +0300
initial commit
Diffstat:
A | LICENSE | | | 29 | +++++++++++++++++++++++++++++ |
A | Makefile | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | README.md | | | 32 | ++++++++++++++++++++++++++++++++ |
A | azan-nasm.1 | | | 15 | +++++++++++++++ |
A | azan-nasm.s | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | config.mk | | | 16 | ++++++++++++++++ |
A | macros.s | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | syscalls.s | | | 16 | ++++++++++++++++ |
8 files changed, 279 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+© 2020 Hassan Afify <hassan at afify dot dev>
+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 copyright holder 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,51 @@
+# azan-nasm
+# See LICENSE file for copyright and license details.
+
+include config.mk
+
+BIN = azan-nasm
+SRC = ${BIN}.s
+OBJ = ${SRC:.s=.o}
+
+all: options ${BIN}
+
+options:
+ @echo ${BIN} build options:
+ @echo "AFLAGS = ${AFLAGS}"
+ @echo "LFLAGS = ${LFLAGS}"
+ @echo "ASM = ${ASM}"
+ @echo "LNK = ${LNK}"
+
+.s.o:
+ ${ASM} ${AFLAGS} $<
+
+${OBJ}: config.mk
+
+${BIN}: ${OBJ}
+ ${LNK} ${LFLAGS} -o $@ ${OBJ}
+
+clean:
+ rm -rf ${OBJ} ${BIN} ${BIN}-${VERSION}.tar.gz
+
+dist: clean
+ mkdir -p ${BIN}-${VERSION}
+ cp -R LICENSE Makefile README.md config.mk\
+ ${BIN}.1 ${SRC} ${BIN}-${VERSION}
+ tar -cf ${BIN}-${VERSION}.tar ${BIN}-${VERSION}
+ gzip ${BIN}-${VERSION}.tar
+ rm -rf ${BIN}-${VERSION}
+
+install: ${BIN}
+ mkdir -p ${DESTDIR}${PREFIX}/bin
+ cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
+ chmod 755 ${DESTDIR}${PREFIX}/bin/${BIN}
+ mkdir -p ${DESTDIR}${MANPREFIX}/man1
+ sed "s/VERSION/${VERSION}/g" < ${BIN}.1 > \
+ ${DESTDIR}${MANPREFIX}/man1/${BIN}.1
+ chmod 644 ${DESTDIR}${MANPREFIX}/man1/${BIN}.1
+
+uninstall:
+ rm -f ${DESTDIR}${PREFIX}/bin/${BIN}\
+ ${DESTDIR}${MANPREFIX}/man1/${BIN}.1
+
+.PHONY: all options clean dist install uninstall
diff --git a/README.md b/README.md
@@ -0,0 +1,32 @@
+azan-nasm
+=========
+
+azan-nasm is nasm azan implementation
+
+Installation
+------------
+**current**
+```sh
+git clone https://github.com/afify/azan-nasm.git
+cd azan-nasm/
+make
+make install
+```
+**latest release**
+```sh
+wget --content-disposition $(curl -s https://api.github.com/repos/afify/azan-nasm/releases/latest | tr -d '",' | awk '/tag_name/ {print "https://github.com/afify/azan-nasm/archive/"$2".tar.gz"}')
+tar -xzf azan-nasm-*.tar.gz && cd azan-nasm-*/
+make
+make install
+```
+Run
+---
+```sh
+$ azan-nasm
+```
+Options
+-------
+```sh
+$ azan-nasm
+$ man azan-nasm
+```
diff --git a/azan-nasm.1 b/azan-nasm.1
@@ -0,0 +1,15 @@
+.TH AZAN 1 azan\-VERSION
+.SH NAME
+azan \- simple muslim prayers calculator
+.SH SYNOPSIS
+.B azan
+.SH DESCRIPTION
+azan is a simple muslim prayers calculator for unix-like systems. Show prayers time.
+.SH USAGE
+.TP
+.B azan
+print next prayer left duration.
+.SH AUTHORS
+See the LICENSE file for the authors.
+.SH LICENSE
+See the LICENSE file for the terms of redistribution.
diff --git a/azan-nasm.s b/azan-nasm.s
@@ -0,0 +1,68 @@
+; See LICENSE file for copyright and license details.
+; azan-nasm is simple muslim prayers calculator.
+; print next prayer left duration or today's all prayers.
+
+BITS 64
+%include "syscalls.s"
+%include "macros.s"
+CHECK_OPENBSD
+
+section .bss
+ digitSpace: resb 100
+ digitSpacePos: resb 8
+ current_time: resb 12
+
+section .text
+ global _start
+
+_start:
+ mov rax, SYS_gettimeofday
+ mov rdi, current_time
+ mov rsi, rsi
+ syscall
+
+ mov rax, [current_time]
+
+ call _printRAX
+ EEXIT EXIT_SUCCESS
+
+_printRAX:
+ mov rcx, digitSpace
+ mov rbx, 10
+ mov [rcx], rbx
+ inc rcx
+ mov [digitSpacePos], rcx
+
+_printRAXLoop:
+ mov rdx, 0
+ mov rbx, 10
+ div rbx
+ push rax
+ add rdx, 48
+
+ mov rcx, [digitSpacePos]
+ mov [rcx], dl
+ inc rcx
+ mov [digitSpacePos], rcx
+
+ pop rax
+ cmp rax, 0
+ jne _printRAXLoop
+
+_printRAXLoop2:
+ mov rcx, [digitSpacePos]
+
+ mov rax, 1
+ mov rdi, 1
+ mov rsi, rcx
+ mov rdx, 1
+ syscall
+
+ mov rcx, [digitSpacePos]
+ dec rcx
+ mov [digitSpacePos], rcx
+
+ cmp rcx, digitSpace
+ jge _printRAXLoop2
+
+ ret
diff --git a/config.mk b/config.mk
@@ -0,0 +1,16 @@
+# azan-nasm version
+VERSION = 0.1
+
+# Customize below to fit your system
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+# flags
+AFLAGS = -f elf64 -w+all -D$$(uname)
+LFLAGS = -m elf_x86_64 -no-pie
+
+# compiler and linker
+ASM = nasm
+LNK = ld
diff --git a/macros.s b/macros.s
@@ -0,0 +1,52 @@
+; See LICENSE file for copyright and license details.
+
+%ifndef MACROS_S
+%define MACROS_S
+
+%define EXIT_SUCCESS 0
+%define EXIT_FAILURE 1
+%define STDOUT 1
+%define STDERR 2
+
+section .rodata
+ failure_msg: db 0x5b, 0x1b, 0x5b, 0x33, 0x31, 0x6d, 0x46\
+ 0x41, 0x49, 0x4c, 0x45, 0x44, 0x1b, 0x5b\
+ 0x30, 0x6d, 0x5d, 0x20, 0x00
+ failure_msglen: equ $ - failure_msg
+ julian_msg: db "Julian must be greader than offset.", 10, 0
+ julian_msglen: equ $ - julian_msg
+
+%macro CHECK_OPENBSD 0
+%ifdef OpenBSD
+section .note.openbsd.ident note
+ dd 8, 4, 1
+ db "OpenBSD", 0
+ dd 0
+%endif
+%endmacro
+
+%macro EEXIT 1
+ mov rax, SYS_exit
+ mov rdi, %1
+ syscall
+%endmacro
+
+%macro FAIL_MSG 0
+ mov rax, SYS_write
+ mov rdi, STDERR
+ mov rsi, failure_msg
+ mov rdx, failure_msglen
+ syscall
+%endmacro
+
+%macro FAILJULIAN 0
+ FAIL_MSG
+ mov rax, SYS_write
+ mov rdi, STDERR
+ mov rsi, julian_msg
+ mov rdx, julian_msglen
+ syscall
+ EEXIT EXIT_FAILURE
+%endmacro
+
+%endif ;MACROS_S
diff --git a/syscalls.s b/syscalls.s
@@ -0,0 +1,16 @@
+; See LICENSE file for copyright and license details.
+
+%ifndef SYSCALLS_S
+%define SYSCALLS_S
+
+%ifdef Linux
+ %define SYS_exit 60
+ %define SYS_write 1
+ %define SYS_gettimeofday 96
+%elif OpenBSD
+ %define SYS_exit 1
+ %define SYS_write 4
+ %define SYS_gettimeofday 67
+%endif
+
+%endif ;SYSCALLS_S