This commit is contained in:
2025-08-20 18:24:41 +02:00
parent 2b037241d1
commit a1455660e2
3 changed files with 25 additions and 21 deletions
+13 -21
View File
@@ -1,3 +1,6 @@
.include "syscalls.S"
.include "errors.S"
.global _start
exit: @ r0 should have the status code to exit with
@@ -12,7 +15,7 @@ print: @ r1 => buffer to print. r2 => how many bytes to print. clobbers r0
bx lr @ return to caller
open_fail:
push {r0} @ push the result of open() onto the stack before calling print()
push {r0}
ldr r1, =OPEN_FAIL
mov r2, #31
bl print
@@ -21,7 +24,7 @@ open_fail:
bl exit
dir_read_fail:
push {r0} @ save the result of open() because print() clobbers r0
push {r0}
ldr r1, =DIR_READ_FAIL
mov r2, #29
bl print
@@ -111,6 +114,7 @@ direntry_loop:
b direntry_loop
@ TODO: alphabetically sort the directory entries before printing them.
_start:
ldr r0, [sp]
cmp r0, #1
@@ -151,26 +155,14 @@ _start:
bl exit
.data
FILE: .asciz "/home/illusion/asm.txt"
FALLBACK_DIR: .asciz "."
OPEN_FAIL: .ascii "Failed to open file descriptor"
DIR_READ_FAIL: .ascii "Failed to read the directory\n"
FD_NOT_DIR: .ascii "File is not a directory\n"
FD_NOT_FOUND: .ascii "Failed to open file descriptor: No such file or directory\n"
NEWLINE: .ascii "\n"
.equ SYS_EXIT, 0x01
.equ SYS_READ, 0x03
.equ SYS_WRITE, 0x04
.equ SYS_OPEN, 0x05
.equ SYS_FSTAT, 0x6C
.equ SYS_GETDENTS, 0x8D
.equ ENOENT, 0xFFFFFFFE
.equ ENOTDIR, 0xFFFFFFEC
FILE: .asciz "/home/illusion/asm.txt"
FALLBACK_DIR: .asciz "."
OPEN_FAIL: .ascii "Failed to open file descriptor"
DIR_READ_FAIL: .ascii "Failed to read the directory\n"
FD_NOT_DIR: .ascii "File is not a directory\n"
FD_NOT_FOUND: .ascii "Failed to open file descriptor: No such file or directory\n"
NEWLINE: .ascii "\n"
.bss
buffer:
.skip 16384
name:
.skip 256