From 7e831a1495736e3997502de43962d617b7218179 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 16 Apr 2020 18:44:48 +0200 Subject: Read function is good --- Makefile | 23 +++++++++++++-------- asm/jo_f_status.asm | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lowbat | Bin 0 -> 14512 bytes src/jo_lowbat.h | 23 +++++++++++++++++++++ src/jo_main.c | 29 ++++++++++++++++++++++++-- src/jo_main.h | 17 +++++++++++++++- src/jo_printf.c | 9 --------- src/jo_printf.h | 6 ------ 8 files changed, 138 insertions(+), 26 deletions(-) create mode 100644 asm/jo_f_status.asm create mode 100755 lowbat create mode 100644 src/jo_lowbat.h delete mode 100644 src/jo_printf.c delete mode 100644 src/jo_printf.h diff --git a/Makefile b/Makefile index 4002515..06dddc7 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,12 @@ C_SRCS_DIR = src A_SRCS_DIR = asm # =========================================== FILES ============================================== # C_SRCS = ${C_SRCS_DIR}/jo_main.c -C_SRCS += ${C_SRCS_DIR}/jo_printf.c # ------------------------------------------------------------------------------------------------ # C_OBJS = ${C_SRCS:.c=.o} +# ------------------------------------------------------------------------------------------------ # +A_SRCS = ${A_SRCS_DIR}/jo_f_status.asm +# ------------------------------------------------------------------------------------------------ # +A_OBJS = ${A_SRCS:.asm=.o} # ========================================== COMPILER ============================================ # CC = clang # ------------------------------------------------------------------------------------------------ # @@ -23,11 +26,13 @@ CFLAGS += ${DEBUG} OPTI = -O2 -pipe DEBUG = -glldb # ------------------------------------------------------------------------------------------------ # +LINK = -lc +# ------------------------------------------------------------------------------------------------ # TARGET = lowbat # ========================================== ASSEMBLER =========================================== # ASM = nasm ASMFLAGS = -f -ASMARCH = elf64_fbsd +ASMARCH = elf64 # ============================================ UNIX ============================================== # RM = rm -f MKDIR = mkdir -p @@ -36,13 +41,16 @@ MV = mv SED = sed # ============================================ RULES ============================================= # -.SUFFIXES: .c .o +.SUFFIXES: .asm .c .o + +.asm.o: + ${ASM} ${ASMFLAGS} ${ASMARCH} -o ${.TARGET} ${.IMPSRC} .c.o: - ${CC} -c ${CFLAGS} -I${C_SRCS_DIR} ${.IMPSRC} -o ${.TARGET} + ${CC} -c ${CFLAGS} -I${C_SRCS_DIR} -o ${.TARGET} ${.IMPSRC} -${TARGET}: ${C_OBJS} - ${CC} ${CFLAGS} -I${C_SRCS_DIR} -o ${.TARGET} ${.ALLSRC} +${TARGET}: ${A_OBJS} ${C_OBJS} + ${CC} ${CFLAGS} -I${C_SRCS_DIR} -o ${.TARGET} ${.ALLSRC} ${LINK} depend: ${CC} -I${C_SRCS_DIR} -E -MM ${C_SRCS} > .depend @@ -53,6 +61,7 @@ all: depend ${TARGET} clean: ${RM} ${C_OBJS} + ${RM} ${A_OBJS} ${RM} ${TARGET}.core ${RM} .depend ${RM} .depend.tmp @@ -63,5 +72,3 @@ fclean: clean re: fclean all .PHONY: all clean fclean re depend - --include "./.depend" diff --git a/asm/jo_f_status.asm b/asm/jo_f_status.asm new file mode 100644 index 0000000..cc1deb2 --- /dev/null +++ b/asm/jo_f_status.asm @@ -0,0 +1,57 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; File : jo_f_status.asm /_________/ ;; +;; Author : Joe | ;; +;; Date : 04/2020 | ;; +;; Info : gets batt status | ;; +;; / | ;; +;; \ / ;; +;; \_____/ ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +section .text + extern system + extern malloc + extern printf + 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 + push rax + mov rdi, 0x5 + call malloc + cmp rax, 0x0 + je err + mov rsi, rax + pop rax + mov rdi, rax + mov rdx, 0x4 + push rax + mov rax, 0x3 + syscall + jc err + pop rax + mov rdi, rax + mov rax, 0x6 + syscall + mov byte [rsi + 0x4], 0x0 + mov rax, rsi + retq + +err: + mov rax, 0x0 + retq + +section .data + f_cmd: db "apm | grep Status | awk -F ' ' '{print $3}' > /tmp/lowbat.status", 0x0 + st_file: db "/tmp/lowbat.status", 0x0 + + ;; charging + ;; discharg diff --git a/lowbat b/lowbat new file mode 100755 index 0000000..5de9a67 Binary files /dev/null and b/lowbat differ diff --git a/src/jo_lowbat.h b/src/jo_lowbat.h new file mode 100644 index 0000000..ddc6679 --- /dev/null +++ b/src/jo_lowbat.h @@ -0,0 +1,23 @@ +/****************************************************************************************/ +/* */ +/* File : jo_lowbat.h /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : The general header | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + +#ifndef JO_LOWBAT_H +#define JO_LOWBAT_H + +enum +{ + JO_RET_FINE, + JO_RET_RD_FAILED +}; +char *jo_f_status(void); + +#endif diff --git a/src/jo_main.c b/src/jo_main.c index ee3c400..2d19ab8 100644 --- a/src/jo_main.c +++ b/src/jo_main.c @@ -1,8 +1,33 @@ +/****************************************************************************************/ +/* */ +/* File : jo_main.c /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : The main | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + #include +/* +** Files prefixes +** -------------- +** f: fetch +*/ + int main(void) { - jo_printf(); - return (0); + char *status; + + if (!(status = jo_f_status())) { + return (JO_RET_RD_FAILED); + } + printf("status: %s\n", status); + free(status); + status = NULL; + return (JO_RET_FINE); } diff --git a/src/jo_main.h b/src/jo_main.h index 3a3359c..8feabe9 100644 --- a/src/jo_main.h +++ b/src/jo_main.h @@ -1,6 +1,21 @@ +/****************************************************************************************/ +/* */ +/* File : jo_main.h /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + #ifndef JO_MAIN_H #define JO_MAIN_H -#include +#include +#include +#include +#include #endif diff --git a/src/jo_printf.c b/src/jo_printf.c deleted file mode 100644 index 066712b..0000000 --- a/src/jo_printf.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -void -jo_printf(void) -{ - - printf("Hey!\n"); -} diff --git a/src/jo_printf.h b/src/jo_printf.h deleted file mode 100644 index 60fdc99..0000000 --- a/src/jo_printf.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef JO_PRINTF_H -#define JO_PRINTF_H - -void jo_printf(void); - -#endif -- cgit v1.2.3