diff --git a/errors.S b/errors.S new file mode 100644 index 0000000..0a89993 --- /dev/null +++ b/errors.S @@ -0,0 +1,4 @@ + +.equ ENOENT, 0xFFFFFFFE +.equ ENOTDIR, 0xFFFFFFEC + diff --git a/main.S b/main.S index 0ca144d..d22b079 100644 --- a/main.S +++ b/main.S @@ -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 diff --git a/syscalls.S b/syscalls.S new file mode 100644 index 0000000..4b8f466 --- /dev/null +++ b/syscalls.S @@ -0,0 +1,8 @@ + +.equ SYS_EXIT, 0x01 +.equ SYS_READ, 0x03 +.equ SYS_WRITE, 0x04 +.equ SYS_OPEN, 0x05 +.equ SYS_FSTAT, 0x6C +.equ SYS_GETDENTS, 0x8D +