aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2021-02-10 17:39:59 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2021-02-10 17:39:59 +0100
commita0983938dd66c3ff67bc87279ebe05f14bc692f2 (patch)
tree7560e44b2a71214dbe18b2bdf46d6d24f3afd6e3
parentRewriting (diff)
downloadlowbat-bsd-a0983938dd66c3ff67bc87279ebe05f14bc692f2.tar.gz
lowbat-bsd-a0983938dd66c3ff67bc87279ebe05f14bc692f2.tar.bz2
lowbat-bsd-a0983938dd66c3ff67bc87279ebe05f14bc692f2.tar.xz
lowbat-bsd-a0983938dd66c3ff67bc87279ebe05f14bc692f2.tar.zst
lowbat-bsd-a0983938dd66c3ff67bc87279ebe05f14bc692f2.zip
Translating, added rc script
-rw-r--r--Makefile10
-rw-r--r--asm/r_loop.asm82
-rw-r--r--asm/r_lowbat.asm27
-rw-r--r--src/n_notify.c2
-rw-r--r--src/n_speak.c2
5 files changed, 29 insertions, 94 deletions
diff --git a/Makefile b/Makefile
index 4a2b3b1..cf76bb6 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ A_SRCS += ${A_SRCS_DIR}/f_percent.asm
A_OBJS = ${A_SRCS:.asm=.o}
-CC = clang
+CC = cc
CFLAGS += -std=c89
CFLAGS += -Wall
CFLAGS += -Wextra
@@ -45,7 +45,6 @@ CFLAGS += -pedantic
# CFLAGS += -O0 -glldb
# CFLAGS += -fsanitize=address
-CINCS = -Isrc/
CINCS += -I/usr/local/include
CINCS += -I/usr/local/include/glib-2.0
CINCS += -I/usr/local/lib/glib-2.0/include
@@ -115,3 +114,10 @@ clean:
re: clean all
.PHONY: all clean fclean re depend install uninstall
+
+# Files prefixes
+# --------------
+# f: fetch
+# n: notify
+# r: run
+# c: check
diff --git a/asm/r_loop.asm b/asm/r_loop.asm
index b85fabe..a3a9126 100644
--- a/asm/r_loop.asm
+++ b/asm/r_loop.asm
@@ -28,7 +28,7 @@ r_loop:
pushq %rbp
pushq %rbx
movq %rsi, %rbx
- movq %edi, %ebp
+ movl %edi, %ebp
jmp bigloop
bigloop:
@@ -54,7 +54,10 @@ bigloop:
speak:
cmp $0x1, %ebp
jne sleepabit
- movq (%rbx,0x8,0x2), %rdi
+ pushq %rcx
+ movq $0x8, %rcx
+ movq (%rbx,%rcx,0x2), %rdi
+ popq %rcx
callq n_speak
sleepabit:
@@ -73,80 +76,13 @@ return:
err:
movq $0x2, %rdi /* stderr */
- leaq (rel $errmsg), %rsi
- movq $errlen, %rdx
+ movq $errmsg, %rsi
+ movq $0x25, %rdx
movq $0x4, %rax
syscall /* write error message on stderr */
xorq %rax, %rax
retq
-;; section .text
-;; extern sleep
-;; extern jo_f_percent
-;; extern jo_f_status
-;; extern jo_n_speak
-;; extern jo_n_notify
-;; extern jo_r_cpyhead
-;; global jo_r_loop
-
-;; jo_r_loop:
-;; push rbp
-;; push rbx
-;; mov rbx, rsi
-;; mov ebp, edi
-;; jmp bigloop
-
-;; bigloop:
-;; call jo_f_status ; check the status
-;; cmp rax, 0xfe ; in case we couldn't read
-;; je err
-;; cmp rax, 0x3
-;; je sleepalot
-;; call jo_f_percent ; check the capacity
-;; cmp rax, 0xfe ; in case we couldn't read
-;; je err
-;; cmp rax, 0xf
-;; jge sleepalot
-;; mov rdi, rax
-;; call jo_r_cpyhead
-;; mov rdi, rax
- ;; mov rsi, n_body ; notification body
- ;; mov rdx, 0x3 ; ciritcal notification
- ;; mov rcx, 0x3a98 ; 15000ms notification timeout
- ;; call jo_n_notify ; jo_n_notify(head: rdi, body: rsi,
- ;; ; urgency: rdx, timeout: rcx)
-
-;; speak:
-;; cmp ebp, 0x1
-;; jne sleepabit
-;; mov rdi, [rbx + 0x8 * 0x2]
-;; call jo_n_speak
-
-;; sleepabit:
-;; mov rdi, 0x14
-;; call sleep ; sleep 20 seconds before next check/notification
-;; jmp bigloop
-
-;; sleepalot:
-;; mov rdi, 0xf0
-;; call sleep ; sleep 240s (4m) if it's fine
-;; jmp bigloop
-
-;; return:
-;; xor rax, rax
-;; retq
-
-;; err:
-;; mov rdi, 0x2 ; stderr
-;; lea rsi, [rel errmsg]
-;; mov rdx, errlen
-;; mov rax, 0x4
-;; syscall ; write error message on stderr
-;; xor rax, rax
-;; retq
-
.data
- n_body: .asciz "Please plug in computer"
- fmt: .asciz "%s", 0xa
- errmsg: .asciz "Failed to read battery informations", 0xa
- errlen: equ $ - errmsg
+ n_body: .asciz "Please plug in computer"
+ errmsg: .asciz "Failed to read battery informations\n"
diff --git a/asm/r_lowbat.asm b/asm/r_lowbat.asm
index 217efc3..a1da30b 100644
--- a/asm/r_lowbat.asm
+++ b/asm/r_lowbat.asm
@@ -10,24 +10,17 @@
/* */
/****************************************************************************************/
-;; Files prefixes
-;; --------------
-;; f: fetch
-;; n: notify
-;; r: run
-;; c: check
-
-section .text
- extern jo_c_args
- extern jo_r_loop
- global main
+.text
+.extern c_args
+.extern r_loop
+.globl main
main:
- call jo_c_args
- mov rdi, rax
- call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[])
+ callq c_args
+ movq %rax, %rdi
+ callq r_loop /* jo_r_loop(speak: 0-1, *argv[]) */
- xor rax, rax
- xor rdi, rdi
- mov rax, 0x1
+ xorq %rax, %rax
+ xorq %rdi, %rdi
+ mov $0x1, %rax
syscall
diff --git a/src/n_notify.c b/src/n_notify.c
index 3798986..f88f6b5 100644
--- a/src/n_notify.c
+++ b/src/n_notify.c
@@ -10,7 +10,7 @@
/* */
/****************************************************************************************/
-#include <jo_n_notify.h>
+#include "n_notify.h"
void
n_notify
diff --git a/src/n_speak.c b/src/n_speak.c
index a1266c7..53bcdd0 100644
--- a/src/n_speak.c
+++ b/src/n_speak.c
@@ -10,7 +10,7 @@
/* */
/****************************************************************************************/
-#include <jo_n_speak.h>
+#include "n_speak.h"
void
n_speak(const char *msg)