diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-16 18:44:48 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-16 18:44:48 +0200 |
commit | 7e831a1495736e3997502de43962d617b7218179 (patch) | |
tree | b61da68e5e24f54523fecf68be0cce789a3c2a8c | |
parent | Create LICENSE (diff) | |
download | lowbat-bsd-7e831a1495736e3997502de43962d617b7218179.tar.gz lowbat-bsd-7e831a1495736e3997502de43962d617b7218179.tar.bz2 lowbat-bsd-7e831a1495736e3997502de43962d617b7218179.tar.xz lowbat-bsd-7e831a1495736e3997502de43962d617b7218179.tar.zst lowbat-bsd-7e831a1495736e3997502de43962d617b7218179.zip |
Read function is good
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | asm/jo_f_status.asm | 57 | ||||
-rwxr-xr-x | lowbat | bin | 0 -> 14512 bytes | |||
-rw-r--r-- | src/jo_lowbat.h | 23 | ||||
-rw-r--r-- | src/jo_main.c | 29 | ||||
-rw-r--r-- | src/jo_main.h | 17 | ||||
-rw-r--r-- | src/jo_printf.c | 9 | ||||
-rw-r--r-- | src/jo_printf.h | 6 |
8 files changed, 138 insertions, 26 deletions
@@ -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 Binary files differdiff --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 <jo_main.h> +/* +** 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 <jo_printf.h> +#include <jo_lowbat.h> +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> #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 <stdio.h> -#include <jo_printf.h> - -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 |