commit 23416d957f1b1b85d64f7a290b467d58f586a863
parent b2a79a4dc7a83cc55b05156df4796725fb0cd776
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Mon, 9 Jun 2025 23:54:42 +0100
Combine syscall/start assembly
Diffstat:
| M | gen.sh | | | 2 | +- |
| D | start.s | | | 13 | ------------- |
| D | syscall.s | | | 102 | ------------------------------------------------------------------------------- |
| A | x86_64.s | | | 114 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 115 insertions(+), 116 deletions(-)
diff --git a/gen.sh b/gen.sh
@@ -2,4 +2,4 @@
ARCH=`uname -m`
-echo ": foreach {objs} | $ARCH.ld obj/start.o obj/syscall.o |> cc "'$(LDFLAGS)'" -o %o -T $ARCH.ld obj/start.o obj/syscall.o %f |> %B"
+echo ": foreach {objs} | $ARCH.ld obj/$ARCH.o |> cc "'$(LDFLAGS)'" -o %o -T $ARCH.ld obj/$ARCH.o %f |> %B"
diff --git a/start.s b/start.s
@@ -1,13 +0,0 @@
-.intel_syntax noprefix
-
-.global start
-
-.text
-
-start: # start is the entry point known to the linker
- mov edi, [rsp] # get argc from the stack
- lea rsi, [rsp+8] # take the address of argv from the stack
- lea rdx, [rsp+16] # take the address of envp from the stack
- call main # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main
- mov rdi, rax
- jmp exit
diff --git a/syscall.s b/syscall.s
@@ -1,102 +0,0 @@
-.intel_syntax noprefix
-
-.macro syscall3, num, name
-.global \name
-.section .text.\name
-\name:
- push r11
- push rcx
- mov rax, \num
- syscall
- pop rcx
- pop r11
- ret
-.endm
-
-.macro syscall6, num, name
-.global \name
-.section .text.\name
-\name:
- push r11
- mov rax, \num
- mov r10, rcx
- syscall
- pop r11
- ret
-.endm
-
-.text
-.global exit
-
-syscall3 0 read
-syscall3 1 write
-syscall3 2 open
-syscall3 3 close
-syscall3 4 stat
-syscall3 5 fstat
-syscall3 6 lstat
-syscall3 7 poll
-syscall3 8 lseek
-syscall6 9 mmap
-syscall3 10 mprotect
-syscall3 11 munmap
-syscall3 12 brk
-syscall6 13 rt_sigaction
-syscall6 14 rt_sigprocmask
-syscall3 15 rt_sigreturn
-syscall3 16 ioctl
-syscall6 17 pread64
-syscall6 18 pwrite64
-syscall3 19 readv
-syscall3 20 writev
-syscall3 21 access
-syscall3 22 pipe
-syscall6 23 select
-syscall3 24 yield
-syscall6 25 mremap
-syscall3 26 msync
-syscall3 27 mincore
-syscall3 28 madvise
-syscall3 29 shmget
-syscall3 30 shmat
-syscall3 31 shmctl
-syscall3 32 dup
-syscall3 33 dup2
-syscall3 34 pause
-syscall3 35 nanosleep
-syscall3 36 getitimer
-syscall3 37 alarm
-syscall3 38 setitimer
-syscall3 39 getpid
-syscall6 40 sendfile
-syscall3 41 socket
-syscall3 42 connect
-syscall3 43 accept
-syscall6 44 sendto
-syscall6 45 recvfrom
-syscall3 46 sendmsg
-syscall3 47 recvmsg
-syscall3 48 shutdown
-syscall3 49 bind
-syscall3 50 listen
-syscall3 51 getsockname
-syscall3 52 getpeername
-syscall3 53 socketpair
-syscall6 54 setsockopt
-syscall6 55 getsockopt
-syscall3 56 clone
-syscall3 57 fork
-syscall3 58 vfork
-syscall3 59 execve
-
-.section .text.exit
-exit: mov rax, 60
- syscall
-
-syscall6 61 wait4
-syscall3 62 kill
-syscall3 63 uname
-syscall3 64 semget
-syscall3 65 semop
-
-syscall3 77 ftruncate
diff --git a/x86_64.s b/x86_64.s
@@ -0,0 +1,114 @@
+.intel_syntax noprefix
+
+.global start
+
+.text
+
+start: # start is the entry point known to the linker
+ mov edi, [rsp] # get argc from the stack
+ lea rsi, [rsp+8] # take the address of argv from the stack
+ lea rdx, [rsp+16] # take the address of envp from the stack
+ call main # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main
+ mov rdi, rax
+ jmp exit
+
+.macro syscall3, num, name
+.global \name
+.section .text.\name
+\name:
+ push r11
+ push rcx
+ mov rax, \num
+ syscall
+ pop rcx
+ pop r11
+ ret
+.endm
+
+.macro syscall6, num, name
+.global \name
+.section .text.\name
+\name:
+ push r11
+ mov rax, \num
+ mov r10, rcx
+ syscall
+ pop r11
+ ret
+.endm
+
+.text
+.global exit
+
+syscall3 0 read
+syscall3 1 write
+syscall3 2 open
+syscall3 3 close
+syscall3 4 stat
+syscall3 5 fstat
+syscall3 6 lstat
+syscall3 7 poll
+syscall3 8 lseek
+syscall6 9 mmap
+syscall3 10 mprotect
+syscall3 11 munmap
+syscall3 12 brk
+syscall6 13 rt_sigaction
+syscall6 14 rt_sigprocmask
+syscall3 15 rt_sigreturn
+syscall3 16 ioctl
+syscall6 17 pread64
+syscall6 18 pwrite64
+syscall3 19 readv
+syscall3 20 writev
+syscall3 21 access
+syscall3 22 pipe
+syscall6 23 select
+syscall3 24 yield
+syscall6 25 mremap
+syscall3 26 msync
+syscall3 27 mincore
+syscall3 28 madvise
+syscall3 29 shmget
+syscall3 30 shmat
+syscall3 31 shmctl
+syscall3 32 dup
+syscall3 33 dup2
+syscall3 34 pause
+syscall3 35 nanosleep
+syscall3 36 getitimer
+syscall3 37 alarm
+syscall3 38 setitimer
+syscall3 39 getpid
+syscall6 40 sendfile
+syscall3 41 socket
+syscall3 42 connect
+syscall3 43 accept
+syscall6 44 sendto
+syscall6 45 recvfrom
+syscall3 46 sendmsg
+syscall3 47 recvmsg
+syscall3 48 shutdown
+syscall3 49 bind
+syscall3 50 listen
+syscall3 51 getsockname
+syscall3 52 getpeername
+syscall3 53 socketpair
+syscall6 54 setsockopt
+syscall6 55 getsockopt
+syscall3 56 clone
+syscall3 57 fork
+syscall3 58 vfork
+syscall3 59 execve
+
+.section .text.exit
+exit: mov rax, 60
+ syscall
+
+syscall6 61 wait4
+syscall3 62 kill
+syscall3 63 uname
+syscall3 64 semget
+syscall3 65 semop
+
+syscall3 77 ftruncate