aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-17 18:14:42 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-17 18:14:42 +0200
commit9f46f4559625d62bd8d289e9ac75dc6369d7e7ed (patch)
tree4342a73e97ba98504a806645aea81de1336b862d
parentStarting the main program, bus error somehow (diff)
downloadlowbat-bsd-9f46f4559625d62bd8d289e9ac75dc6369d7e7ed.tar.gz
lowbat-bsd-9f46f4559625d62bd8d289e9ac75dc6369d7e7ed.tar.bz2
lowbat-bsd-9f46f4559625d62bd8d289e9ac75dc6369d7e7ed.tar.xz
lowbat-bsd-9f46f4559625d62bd8d289e9ac75dc6369d7e7ed.tar.zst
lowbat-bsd-9f46f4559625d62bd8d289e9ac75dc6369d7e7ed.zip
Still bus error, it's not willing to print
-rw-r--r--Makefile5
-rw-r--r--asm/jo_c_args.asm39
-rw-r--r--asm/jo_r_lowbat.asm31
-rw-r--r--src/jo_lowbat.c10
-rw-r--r--src/jo_lowbat.h2
5 files changed, 72 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index c0aae9a..e4a5f76 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@ C_SRCS += ${C_SRCS_DIR}/jo_n_notify.c
C_OBJS = ${C_SRCS:.c=.o}
# -------------------------------------------------------------------------------------- #
A_SRCS = ${A_SRCS_DIR}/jo_r_lowbat.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
# -------------------------------------------------------------------------------------- #
@@ -89,7 +90,9 @@ depend:
${SED} 's/^/${C_SRCS_DIR}\//' .depend > .depend.tmp
${MV} .depend.tmp .depend
# -------------------------------------------------------------------------------------- #
-all: depend ${TARGET}
+all:
+ ${MAKE} depend
+ ${MAKE} ${TARGET}
# -------------------------------------------------------------------------------------- #
clean:
${RM} ${C_OBJS} ${A_OBJS} ${TARGET}.core .depend .depend.tmp ${TARGET}
diff --git a/asm/jo_c_args.asm b/asm/jo_c_args.asm
new file mode 100644
index 0000000..47a2032
--- /dev/null
+++ b/asm/jo_c_args.asm
@@ -0,0 +1,39 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; ;;
+;; File : jo_c_args.asm /_________/ ;;
+;; Author : Joe | ;;
+;; Date : 04/2020 | ;;
+;; Info : Check args | ;;
+;; / | ;;
+;; \ / ;;
+;; \_____/ ;;
+;; ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+section .text
+ extern strncmp
+ global jo_c_args
+
+jo_c_args: ; jo_c_args(argc: rdi, *argv[]: rdi)
+ cmp rdi, 0x2
+ jle no_args
+ push rdi
+ mov rdi, [rsi + 4 * 0]
+ push rsi
+ mov rsi, reference
+ mov rdx, len
+ call strncmp
+ pop rsi
+ pop rdi
+ cmp rax, 0x0
+ jne no_args
+ mov rax, [rsi + 4 * 0]
+ retq
+
+no_args:
+ xor rax, rax
+ retq
+
+section .data
+ reference: db "--say", 0x0
+ len: equ $ - reference ; reference len
diff --git a/asm/jo_r_lowbat.asm b/asm/jo_r_lowbat.asm
index 42863b4..5c9b2b7 100644
--- a/asm/jo_r_lowbat.asm
+++ b/asm/jo_r_lowbat.asm
@@ -10,18 +10,41 @@
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Files prefixes
+;; --------------
+;; f: fetch
+;; n: notify
+;; r: run
+;; c: check
+
section .text
- extern sleep
+ extern printf
extern jo_n_speak
+ extern jo_c_args
global jo_r_lowbat
jo_r_lowbat:
- mov rdi, 0x2
- call sleep
+ call jo_c_args
+ cmp rax, 0x0
+ jne joprint
+ push rdi
mov rdi, msg
call jo_n_speak
+ pop rdi
xor rax, rax
+ mov rax, rdi
+ retq
+
+joprint:
+ push rdi
+ push rsi
+ mov rdi, fmt
+ mov rsi, rax
+ call printf
+ pop rsi
+ pop rdi
retq
section .data
- msg: db "Welcome back, partner", 0x0
+ msg: db "Welcome back, partner!", 0x0
+ fmt: db "argv[2]: %s\n", 0x0
diff --git a/src/jo_lowbat.c b/src/jo_lowbat.c
index b6ee68c..1963b26 100644
--- a/src/jo_lowbat.c
+++ b/src/jo_lowbat.c
@@ -13,18 +13,10 @@
#include <jo_lowbat.h>
#include <libnotify/notify.h>
-/*
-** Files prefixes
-** --------------
-** f: fetch
-** n: notify
-** r: run
-*/
-
int
main(
int argc,
- char *argv[]
+ const char *argv[]
)
{
return (jo_r_lowbat(argc, argv));
diff --git a/src/jo_lowbat.h b/src/jo_lowbat.h
index c4f3c37..b19fa28 100644
--- a/src/jo_lowbat.h
+++ b/src/jo_lowbat.h
@@ -29,7 +29,7 @@ enum
int8_t jo_r_lowbat(
int,
- char**
+ const char**
);
int8_t jo_f_status(void);
int8_t jo_f_percent(void);