aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-27 01:02:18 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-27 01:02:18 +0200
commitea0eca4f717d7f4408273613a566f3550d27085b (patch)
treeb1c1fa062823bb36bbd8bb9dab6437c83c229eec
parentMakefile change (diff)
downloadlowbat-bsd-ea0eca4f717d7f4408273613a566f3550d27085b.tar.gz
lowbat-bsd-ea0eca4f717d7f4408273613a566f3550d27085b.tar.bz2
lowbat-bsd-ea0eca4f717d7f4408273613a566f3550d27085b.tar.xz
lowbat-bsd-ea0eca4f717d7f4408273613a566f3550d27085b.tar.zst
lowbat-bsd-ea0eca4f717d7f4408273613a566f3550d27085b.zip
Rewrite started
-rw-r--r--Makefile45
-rw-r--r--README.org2
-rw-r--r--asm/c_args.asm47
-rw-r--r--asm/f_percent.asm47
-rw-r--r--asm/f_status.asm51
-rw-r--r--asm/jo_c_args.asm47
-rw-r--r--asm/jo_f_percent.asm47
-rw-r--r--asm/jo_f_status.asm51
-rw-r--r--asm/jo_r_cpyhead.asm40
-rw-r--r--asm/jo_r_lowbat.asm33
-rw-r--r--asm/r_cpyhead.asm40
-rw-r--r--asm/r_loop.asm (renamed from asm/jo_r_loop.asm)22
-rw-r--r--asm/r_lowbat.asm33
-rw-r--r--src/n_notify.c (renamed from src/jo_n_notify.c)6
-rw-r--r--src/n_notify.h (renamed from src/jo_n_notify.h)6
-rw-r--r--src/n_speak.c (renamed from src/jo_n_speak.c)6
-rw-r--r--src/n_speak.h (renamed from src/jo_n_speak.h)6
17 files changed, 265 insertions, 264 deletions
diff --git a/Makefile b/Makefile
index 99e2e0b..4a2b3b1 100644
--- a/Makefile
+++ b/Makefile
@@ -12,25 +12,25 @@
default: all
-C_SRCS_DIR = src
-A_SRCS_DIR = asm
+C_SRCS_DIR = src
+A_SRCS_DIR = asm
PREFIX ?= /usr/local
BINPREFIX ?= ${PREFIX}/bin
MANPREFIX ?= ${PREFIX}/share/man
-C_SRCS += ${C_SRCS_DIR}/jo_n_speak.c
-C_SRCS += ${C_SRCS_DIR}/jo_n_notify.c
+C_SRCS += ${C_SRCS_DIR}/n_speak.c
+C_SRCS += ${C_SRCS_DIR}/n_notify.c
-C_OBJS = ${C_SRCS:.c=.o}
+C_OBJS = ${C_SRCS:.c=.o}
-A_SRCS = ${A_SRCS_DIR}/jo_r_lowbat.asm
-A_SRCS += ${A_SRCS_DIR}/jo_r_loop.asm
-A_SRCS += ${A_SRCS_DIR}/jo_r_cpyhead.asm
-A_SRCS += ${A_SRCS_DIR}/jo_c_args.asm
-A_SRCS += ${A_SRCS_DIR}/jo_f_status.asm
-A_SRCS += ${A_SRCS_DIR}/jo_f_percent.asm
+A_SRCS = ${A_SRCS_DIR}/r_lowbat.asm
+A_SRCS += ${A_SRCS_DIR}/r_loop.asm
+A_SRCS += ${A_SRCS_DIR}/r_cpyhead.asm
+A_SRCS += ${A_SRCS_DIR}/c_args.asm
+A_SRCS += ${A_SRCS_DIR}/f_status.asm
+A_SRCS += ${A_SRCS_DIR}/f_percent.asm
-A_OBJS = ${A_SRCS:.asm=.o}
+A_OBJS = ${A_SRCS:.asm=.o}
CC = clang
CFLAGS += -std=c89
@@ -59,11 +59,12 @@ LDLIBS += -lnotify
LDLIBS += -lespeak
LDLIBS += -lc
-TARGET = lowbat
+TARGET = lowbat
-ASM = nasm
-# ASMFLAGS = -g
-ASMARCH = -f elf64
+ASM = yasm
+ASMFLAGS = -f elf64
+ASMFLAGS += -p gas
+# ASMFLAGS += -g
LDFLAGS ?=
LDLIBS = ${LDFLAGS}
@@ -72,16 +73,16 @@ LDLIBS += -lnotify
LDLIBS += -lespeak
SHELL := /bin/sh
-RM = rm -f
-MKDIR = mkdir -p
-CP = cp -pf
-MV = mv
-SED = sed
+RM = rm -f
+MKDIR = mkdir -p
+CP = cp -pf
+MV = mv
+SED = sed
.SUFFIXES: .asm .c .o
.asm.o:
- ${ASM} ${ASMFLAGS} ${ASMARCH} -o ${.TARGET} ${.IMPSRC}
+ ${ASM} ${ASMFLAGS} -o ${.TARGET} ${.IMPSRC}
.c.o:
${CC} -c ${CFLAGS} ${CINCS} -o ${.TARGET} ${.IMPSRC}
diff --git a/README.org b/README.org
index ed8486c..da6d27b 100644
--- a/README.org
+++ b/README.org
@@ -7,7 +7,7 @@ This version will only run on 64-bits BSD systems. It was only tested on FreeBSD
- ~libnotify~
- ~espeak~
- ~BSD make~
-- ~nasm~
+- ~yasm~
- ~clang/llvm~
** Installation
diff --git a/asm/c_args.asm b/asm/c_args.asm
new file mode 100644
index 0000000..dcca5d3
--- /dev/null
+++ b/asm/c_args.asm
@@ -0,0 +1,47 @@
+/* ************************************************************************************ */
+/* */
+/* File : c_args.asm /_________/ */
+/* Author : Joe | */
+/* Date : 04/2020 | */
+/* Info : Check args | */
+/* / | */
+/* \ / */
+/* \_____/ */
+/* */
+/* ************************************************************************************ */
+
+;; jo_c_args(argc: rdi, *argv[]: rsi)
+;; ----------------------------------
+;; returns 0 if args are invalid
+;; returns 1 if args are valid
+
+section .text
+ extern strncmp
+ global jo_c_args
+
+jo_c_args:
+ cmp rdi, 0x2
+ jle no_args
+ mov rax, [rsi + 0x8 * 0x2]
+ cmp byte [rax + 0x0], 0x0
+ je no_args
+ push rdi
+ mov rdi, [rsi + 0x8 * 0x1]
+ push rsi
+ mov rsi, reference
+ mov rdx, reflen
+ call strncmp
+ pop rsi
+ pop rdi
+ cmp rax, 0x0
+ jne no_args
+ mov rax, 0x1
+ retq
+
+no_args:
+ xor rax, rax
+ retq
+
+section .data
+ reference: db "--say", 0x0
+ reflen: equ $ - reference
diff --git a/asm/f_percent.asm b/asm/f_percent.asm
new file mode 100644
index 0000000..3a5c1c8
--- /dev/null
+++ b/asm/f_percent.asm
@@ -0,0 +1,47 @@
+/* ************************************************************************************ */
+/* */
+/* File : f_percent.asm /_________/ */
+/* Author : Joe | */
+/* Date : 04/2020 | */
+/* Info : Gets batt remaining capacity | */
+/* / | */
+/* \ / */
+/* \_____/ */
+/* */
+/* ************************************************************************************ */
+
+section .text
+ extern system
+ extern atoi
+ global jo_f_percent
+
+jo_f_percent:
+ mov rdi, f_cmd
+ call system
+ mov rdi, pr_file
+ mov rsi, 0x0
+ mov rax, 0x5
+ syscall
+ jc err
+ mov rdi, rax
+ mov rsi, buff
+ mov rdx, 0x3
+ mov rax, 0x3
+ syscall
+ jc err
+ mov rax, 0x6
+ syscall
+ xor rax, rax
+ mov rdi, rsi
+ call atoi
+ retq
+
+err:
+ mov rax, 0xfe
+ retq
+
+
+section .data
+ f_cmd: db "apm -l > /tmp/lowbat.percent", 0x0
+ pr_file: db "/tmp/lowbat.percent", 0x0
+ buff: db 0x0, 0x0, 0x0, 0x0
diff --git a/asm/f_status.asm b/asm/f_status.asm
new file mode 100644
index 0000000..81ff3d8
--- /dev/null
+++ b/asm/f_status.asm
@@ -0,0 +1,51 @@
+/* ************************************************************************************ */
+/* */
+/* File : f_status.asm /_________/ */
+/* Author : Joe | */
+/* Date : 04/2020 | */
+/* Info : Gets batt status | */
+/* / | */
+/* \ / */
+/* \_____/ */
+/* */
+/* ************************************************************************************ */
+
+;; apm status
+;; ----------
+;; 0: high
+;; 1: low
+;; 2: critical
+;; 3: charging
+
+section .text
+ extern system
+ global jo_f_status
+
+jo_f_status:
+ mov rdi, f_cmd
+ call system
+ mov rdi, st_file
+ mov rsi, 0x0
+ mov rax, 0x5
+ syscall
+ jc err
+ mov rdi, rax
+ mov rsi, buff
+ mov rdx, 0x1
+ mov rax, 0x3
+ syscall
+ jc err
+ mov rax, 0x6
+ syscall
+ movsx rax, byte [rsi + 0x0]
+ sub rax, 0x30
+ retq
+
+err:
+ mov rax, 0xfe
+ retq
+
+section .data
+ f_cmd: db "apm -b > /tmp/lowbat.status", 0x0
+ st_file: db "/tmp/lowbat.status", 0x0
+ buff: db 0x0, 0x0
diff --git a/asm/jo_c_args.asm b/asm/jo_c_args.asm
deleted file mode 100644
index 67a83c8..0000000
--- a/asm/jo_c_args.asm
+++ /dev/null
@@ -1,47 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; ;;
-;; File : jo_c_args.asm /_________/ ;;
-;; Author : Joe | ;;
-;; Date : 04/2020 | ;;
-;; Info : Check args | ;;
-;; / | ;;
-;; \ / ;;
-;; \_____/ ;;
-;; ;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;; jo_c_args(argc: rdi, *argv[]: rsi)
-;; ----------------------------------
-;; returns 0 if args are invalid
-;; returns 1 if args are valid
-
-section .text
- extern strncmp
- global jo_c_args
-
-jo_c_args:
- cmp rdi, 0x2
- jle no_args
- mov rax, [rsi + 0x8 * 0x2]
- cmp byte [rax + 0x0], 0x0
- je no_args
- push rdi
- mov rdi, [rsi + 0x8 * 0x1]
- push rsi
- mov rsi, reference
- mov rdx, reflen
- call strncmp
- pop rsi
- pop rdi
- cmp rax, 0x0
- jne no_args
- mov rax, 0x1
- retq
-
-no_args:
- xor rax, rax
- retq
-
-section .data
- reference: db "--say", 0x0
- reflen: equ $ - reference
diff --git a/asm/jo_f_percent.asm b/asm/jo_f_percent.asm
deleted file mode 100644
index 6a41c2f..0000000
--- a/asm/jo_f_percent.asm
+++ /dev/null
@@ -1,47 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; ;;
-;; File : jo_f_percent.asm /_________/ ;;
-;; Author : Joe | ;;
-;; Date : 04/2020 | ;;
-;; Info : Gets batt remaining capacity | ;;
-;; / | ;;
-;; \ / ;;
-;; \_____/ ;;
-;; ;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-section .text
- extern system
- extern atoi
- global jo_f_percent
-
-jo_f_percent:
- mov rdi, f_cmd
- call system
- mov rdi, pr_file
- mov rsi, 0x0
- mov rax, 0x5
- syscall
- jc err
- mov rdi, rax
- mov rsi, buff
- mov rdx, 0x3
- mov rax, 0x3
- syscall
- jc err
- mov rax, 0x6
- syscall
- xor rax, rax
- mov rdi, rsi
- call atoi
- retq
-
-err:
- mov rax, 0xfe
- retq
-
-
-section .data
- f_cmd: db "apm -l > /tmp/lowbat.percent", 0x0
- pr_file: db "/tmp/lowbat.percent", 0x0
- buff: db 0x0, 0x0, 0x0, 0x0
diff --git a/asm/jo_f_status.asm b/asm/jo_f_status.asm
deleted file mode 100644
index 0c1c39f..0000000
--- a/asm/jo_f_status.asm
+++ /dev/null
@@ -1,51 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; ;;
-;; File : jo_f_status.asm /_________/ ;;
-;; Author : Joe | ;;
-;; Date : 04/2020 | ;;
-;; Info : Gets batt status | ;;
-;; / | ;;
-;; \ / ;;
-;; \_____/ ;;
-;; ;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;; apm status
-;; ----------
-;; 0: high
-;; 1: low
-;; 2: critical
-;; 3: charging
-
-section .text
- extern system
- global jo_f_status
-
-jo_f_status:
- mov rdi, f_cmd
- call system
- mov rdi, st_file
- mov rsi, 0x0
- mov rax, 0x5
- syscall
- jc err
- mov rdi, rax
- mov rsi, buff
- mov rdx, 0x1
- mov rax, 0x3
- syscall
- jc err
- mov rax, 0x6
- syscall
- movsx rax, byte [rsi + 0x0]
- sub rax, 0x30
- retq
-
-err:
- mov rax, 0xfe
- retq
-
-section .data
- f_cmd: db "apm -b > /tmp/lowbat.status", 0x0
- st_file: db "/tmp/lowbat.status", 0x0
- buff: db 0x0, 0x0
diff --git a/asm/jo_r_cpyhead.asm b/asm/jo_r_cpyhead.asm
deleted file mode 100644
index 4b51542..0000000
--- a/asm/jo_r_cpyhead.asm
+++ /dev/null
@@ -1,40 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; ;;
-;; File : jo_r_cpyhead.asm /_________/ ;;
-;; Author : Joe | ;;
-;; Date : 04/2020 | ;;
-;; Info : Formats and returns notification head title | ;;
-;; / | ;;
-;; \ / ;;
-;; \_____/ ;;
-;; ;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-section .text
- extern memset
- extern sprintf
- global jo_r_cpyhead
-
-jo_r_cpyhead: ; jo_r_cpyhead(percent: rdi)
- push rdi
- mov rdi, buff
- mov rsi, 0x0
- mov rdx, 0x11
- call memset ; memset 0 notification head
- lea rsi, [rel n_head]
- pop rdi
- mov rdx, rdi
- mov rdi, rax
- xor rax, rax
- mov al, 0x1
- push rdi
- call sprintf
- pop rdi
- mov rax, rdi
- retq
-
-section .data
- n_head: db "Low battery: %d%%", 0x0
-
-section .bss
- buff: resb 0x11
diff --git a/asm/jo_r_lowbat.asm b/asm/jo_r_lowbat.asm
deleted file mode 100644
index 4bc6126..0000000
--- a/asm/jo_r_lowbat.asm
+++ /dev/null
@@ -1,33 +0,0 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; ;;
-;; File : jo_r_lowbat.asm /_________/ ;;
-;; Author : Joe | ;;
-;; Date : 04/2020 | ;;
-;; Info : The main program | ;;
-;; / | ;;
-;; \ / ;;
-;; \_____/ ;;
-;; ;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;; Files prefixes
-;; --------------
-;; f: fetch
-;; n: notify
-;; r: run
-;; c: check
-
-section .text
- extern jo_c_args
- extern jo_r_loop
- global main
-
-main:
- call jo_c_args
- mov rdi, rax
- call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[])
-
- xor rax, rax
- xor rdi, rdi
- mov rax, 0x1
- syscall
diff --git a/asm/r_cpyhead.asm b/asm/r_cpyhead.asm
new file mode 100644
index 0000000..15b0d9e
--- /dev/null
+++ b/asm/r_cpyhead.asm
@@ -0,0 +1,40 @@
+/* ************************************************************************************ */
+/* */
+/* File : r_cpyhead.asm /_________/ */
+/* Author : Joe | */
+/* Date : 04/2020 | */
+/* Info : Formats and returns notification head title | */
+/* / | */
+/* \ / */
+/* \_____/ */
+/* */
+/* ************************************************************************************ */
+
+section .text
+ extern memset
+ extern sprintf
+ global jo_r_cpyhead
+
+jo_r_cpyhead: ; jo_r_cpyhead(percent: rdi)
+ push rdi
+ mov rdi, buff
+ mov rsi, 0x0
+ mov rdx, 0x11
+ call memset ; memset 0 notification head
+ lea rsi, [rel n_head]
+ pop rdi
+ mov rdx, rdi
+ mov rdi, rax
+ xor rax, rax
+ mov al, 0x1
+ push rdi
+ call sprintf
+ pop rdi
+ mov rax, rdi
+ retq
+
+section .data
+ n_head: db "Low battery: %d%%", 0x0
+
+section .bss
+ buff: resb 0x11
diff --git a/asm/jo_r_loop.asm b/asm/r_loop.asm
index 987f68f..308a9f4 100644
--- a/asm/jo_r_loop.asm
+++ b/asm/r_loop.asm
@@ -1,14 +1,14 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; ;;
-;; File : jo_r_loop.asm /_________/ ;;
-;; Author : Joe | ;;
-;; Date : 04/2020 | ;;
-;; Info : The main loop | ;;
-;; / | ;;
-;; \ / ;;
-;; \_____/ ;;
-;; ;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+/* ************************************************************************************ */
+/* */
+/* File : r_loop.asm /_________/ */
+/* Author : Joe | */
+/* Date : 04/2020 | */
+/* Info : The main loop | */
+/* / | */
+/* \ / */
+/* \_____/ */
+/* */
+/* ************************************************************************************ */
;; jo_r_loop(speak (0-1), *argv[])
;; -------------------------------
diff --git a/asm/r_lowbat.asm b/asm/r_lowbat.asm
new file mode 100644
index 0000000..f721867
--- /dev/null
+++ b/asm/r_lowbat.asm
@@ -0,0 +1,33 @@
+/* ************************************************************************************ */
+/* */
+/* File : r_lowbat.asm /_________/ */
+/* Author : Joe | */
+/* Date : 04/2020 | */
+/* Info : The main program | */
+/* / | */
+/* \ / */
+/* \_____/ */
+/* */
+/* ************************************************************************************ */
+
+;; Files prefixes
+;; --------------
+;; f: fetch
+;; n: notify
+;; r: run
+;; c: check
+
+section .text
+ extern jo_c_args
+ extern jo_r_loop
+ global main
+
+main:
+ call jo_c_args
+ mov rdi, rax
+ call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[])
+
+ xor rax, rax
+ xor rdi, rdi
+ mov rax, 0x1
+ syscall
diff --git a/src/jo_n_notify.c b/src/n_notify.c
index f98ea1d..3ed6d40 100644
--- a/src/jo_n_notify.c
+++ b/src/n_notify.c
@@ -1,6 +1,6 @@
-/****************************************************************************************/
+/* ************************************************************************************ */
/* */
-/* File : jo_n_notify.c /_________/ */
+/* File : n_notify.c /_________/ */
/* Author : Joe | */
/* Date : 04/2020 | */
/* Info : Uses libnotify lib to notify | */
@@ -8,7 +8,7 @@
/* \ / */
/* \_____/ */
/* */
-/****************************************************************************************/
+/* ************************************************************************************ */
#include <jo_n_notify.h>
diff --git a/src/jo_n_notify.h b/src/n_notify.h
index a72395a..0c69fa7 100644
--- a/src/jo_n_notify.h
+++ b/src/n_notify.h
@@ -1,6 +1,6 @@
-/****************************************************************************************/
+/* ************************************************************************************ */
/* */
-/* File : jo_n_notify.h /_________/ */
+/* File : n_notify.h /_________/ */
/* Author : Joe | */
/* Date : 04/2020 | */
/* Info : Uses libnotify lib to notify | */
@@ -8,7 +8,7 @@
/* \ / */
/* \_____/ */
/* */
-/****************************************************************************************/
+/* ************************************************************************************ */
#ifndef JO_N_NOTIFY_H
#define JO_N_NOTIFY_H
diff --git a/src/jo_n_speak.c b/src/n_speak.c
index 48fcbaa..c6d46f0 100644
--- a/src/jo_n_speak.c
+++ b/src/n_speak.c
@@ -1,6 +1,6 @@
-/****************************************************************************************/
+/* ************************************************************************************ */
/* */
-/* File : jo_n_speak.c /_________/ */
+/* File : n_speak.c /_________/ */
/* Author : Joe | */
/* Date : 04/2020 | */
/* Info : Uses espeak lib to speak | */
@@ -8,7 +8,7 @@
/* \ / */
/* \_____/ */
/* */
-/****************************************************************************************/
+/* ************************************************************************************ */
#include <jo_n_speak.h>
diff --git a/src/jo_n_speak.h b/src/n_speak.h
index 79ca683..dd65b7e 100644
--- a/src/jo_n_speak.h
+++ b/src/n_speak.h
@@ -1,6 +1,6 @@
-/****************************************************************************************/
+/* ************************************************************************************ */
/* */
-/* File : jo_n_speak.h /_________/ */
+/* File : n_speak.h /_________/ */
/* Author : Joe | */
/* Date : 04/2020 | */
/* Info : Use espeak lib to speak | */
@@ -8,7 +8,7 @@
/* \ / */
/* \_____/ */
/* */
-/****************************************************************************************/
+/* ************************************************************************************ */
#ifndef JO_N_SPEAK_H
#define JO_N_SPEAK_H