Skip to content

Commit

Permalink
refactor: simplify a few variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ErrorNoInternet committed Aug 20, 2024
1 parent eca3c41 commit d10a0e3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 32 deletions.
14 changes: 8 additions & 6 deletions asmfetch.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.intel_syntax noprefix

.lcomm number_buf, 10

.include "atoi.S"
.include "constants.S"
.include "copy.S"
Expand Down Expand Up @@ -32,12 +34,12 @@

_start:
mov r15, [rsp + 32]
call populate_envs
call populate_release
call populate_sysinfo
call populate_utsname
call populate_meminfo
call populate_statfs
call parse_envs
call parse_release
call sysinfo
call uname
call parse_meminfo
call statfs

mov rsi, offset LOGO_0
mov rcx, LOGO_1 - LOGO_0
Expand Down
12 changes: 6 additions & 6 deletions env.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,42 @@ env_session: .ascii "XDG_SESSION_TYPE"

.lcomm target, 65

populate_envs:
parse_envs:
mov rcx, 4
mov rsi, offset env_username
mov rdi, offset target
call copy_count
mov rdi, offset username
call populate_env
call parse_env
mov username_length, rcx

mov rcx, 5
mov rsi, offset env_shell
mov rdi, offset target
call copy_count
mov rdi, offset shell_path
call populate_env
call parse_env
mov shell_path_length, rcx

mov rcx, 19
mov rsi, offset env_desktop
mov rdi, offset target
call copy_count
mov rdi, offset desktop
call populate_env
call parse_env
mov desktop_length, rcx

mov rcx, 16
mov rsi, offset env_session
mov rdi, offset target
call copy_count
mov rdi, offset session
call populate_env
call parse_env
mov session_length, rcx

ret

populate_env:
parse_env:
mov rax, r15
xor r8, r8
xor r9, r9
Expand Down
7 changes: 3 additions & 4 deletions meminfo.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ meminfo_file: .asciz "/proc/meminfo"

.lcomm memavailable, 8

.lcomm memavailable_buf, 10
.lcomm meminfo_buf, 128

populate_meminfo:
parse_meminfo:
mov rax, SYS_OPEN
mov rdi, offset meminfo_file
xor rsi, rsi
Expand Down Expand Up @@ -42,7 +41,7 @@ meminfo_available_skip_space:
je meminfo_available_skip_space

meminfo_available_parse:
mov [memavailable_buf + r11], bl
mov [number_buf + r11], bl
inc r11

mov bl, [meminfo_buf + r8]
Expand All @@ -54,7 +53,7 @@ meminfo_available_parse:
jmp meminfo_available_parse

meminfo_done:
mov rsi, offset memavailable_buf
mov rsi, offset number_buf
call atoi
mov memavailable, rax

Expand Down
10 changes: 4 additions & 6 deletions memory.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
memory_label: .ascii "Memory "

.lcomm data_number_buf, 10

print_memory:
mov rsi, offset memory_symbol
mov rcx, 6
Expand Down Expand Up @@ -45,10 +43,10 @@ print_memory:
xor rdx, rdx
div rbx
mov rbx, 10
mov rdi, offset data_number_buf
mov rdi, offset number_buf
call itoa

add rsi, offset data_number_buf
add rsi, offset number_buf
call print

mov bl, '%'
Expand All @@ -70,10 +68,10 @@ print_memory_number:
xor rdx, rdx
div rbx
mov rbx, 10
mov rdi, offset data_number_buf
mov rdi, offset number_buf
call itoa

add rsi, offset data_number_buf
add rsi, offset number_buf
sub rcx, 3
cmp rcx, 1
jl print_memory_zero
Expand Down
2 changes: 1 addition & 1 deletion release.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var_pretty_name: .ascii "PRETTY_NAME"

.lcomm os_release_buf, 512

populate_release:
parse_release:
mov rax, SYS_OPEN
mov rdi, offset os_release_file
xor rsi, rsi
Expand Down
2 changes: 1 addition & 1 deletion statfs.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ statfs_path: .asciz "/"

.lcomm statfs_buf, 128

populate_statfs:
statfs:
mov rax, SYS_STATFS
mov rdi, offset statfs_path
mov rsi, offset statfs_buf
Expand Down
10 changes: 4 additions & 6 deletions storage.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
storage_label: .ascii "Storage "

.lcomm storage_number_buf, 10

print_storage:
mov rsi, offset storage_symbol
mov rcx, 6
Expand Down Expand Up @@ -45,10 +43,10 @@ print_storage:
xor rdx, rdx
div rbx
mov rbx, 10
mov rdi, offset data_number_buf
mov rdi, offset number_buf
call itoa

add rsi, offset data_number_buf
add rsi, offset number_buf
call print

mov bl, '%'
Expand All @@ -71,10 +69,10 @@ print_storage_number:
xor rdx, rdx
div rbx
mov rbx, 10
mov rdi, offset storage_number_buf
mov rdi, offset number_buf
call itoa

add rsi, offset storage_number_buf
add rsi, offset number_buf
sub rcx, 3
cmp rcx, 1
jl print_storage_zero
Expand Down
2 changes: 1 addition & 1 deletion sysinfo.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.lcomm sysinfo_buf, 128

populate_sysinfo:
sysinfo:
mov rax, SYS_SYSINFO
mov rdi, offset sysinfo_buf
syscall
Expand Down
2 changes: 1 addition & 1 deletion uname.S
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

.lcomm utsname, UTSNAME_SIZE * 6

populate_utsname:
uname:
mov rax, SYS_UNAME
mov rdi, offset utsname
syscall
Expand Down

0 comments on commit d10a0e3

Please sign in to comment.