spartserv

Log

Files

Refs

README

syscall.asm (3046B)

     1 sys_open_directory:;rdi = path, rax = ret ( fd )
     2     stackpush
     3     mov rsi, OPEN_DIRECTORY | OPEN_RDONLY ;flags
     4     mov rax, SYS_OPEN
     5     syscall
     6     stackpop
     7     ret
     8 
     9 sys_create_tcp_socket:
    10     stackpush
    11     mov rdi, AF_INET
    12     mov rsi, SOCK_STREAM
    13     mov rdx, PROTO_TCP
    14     mov rax, SYS_SOCKET
    15     syscall
    16     stackpop
    17     ret
    18 
    19 sys_reuse:;rdi - socket
    20     stackpush
    21     mov r8, 8        ;sizeof int
    22     mov r10, one_constant      ;pointer to 1
    23     mov rsi, LEVEL_SOL_TCP
    24     mov rdx, SOCKOPT_TCP_REUSEADDR
    25     mov rax, SYS_SETSOCKOPT
    26     syscall
    27     stackpop
    28     ret
    29 
    30 sys_bind_server:
    31     stackpush
    32 
    33     mov rsi, [listen_port]
    34     mov [sa + sin_port], rsi
    35 
    36     mov rdi, [listen_socket]
    37     mov rsi, sa
    38     mov rdx, 16
    39     mov rax, SYS_BIND
    40     syscall
    41     stackpop
    42     ret
    43 
    44 sys_listen:
    45     stackpush
    46     mov rdi, [listen_socket]
    47     mov rsi, 100000000;backlog
    48     mov rax, SYS_LISTEN
    49     syscall
    50     stackpop
    51     ret
    52 
    53 sys_mmap_mem:
    54     stackpush
    55     mov rsi, rdi                                                    ;Size
    56     xor rdi, rdi                                                    ;Preferred address (don't care)
    57     mov rdx, MMAP_PROT_READ | MMAP_PROT_WRITE                       ;Protection Flags
    58     mov r10, MMAP_MAP_PRIVATE | MMAP_MAP_ANON                       ;Flags
    59     xor r8, r8
    60     dec r8                                                          ;-1 fd because of MMAP_MAP_ANON
    61     xor r9, r9                                                      ;Offset
    62     mov rax, SYS_MMAP
    63     syscall
    64     stackpop
    65     ret
    66 
    67 sys_accept:
    68     stackpush
    69     mov rdi, [listen_socket]
    70     xor rsi, rsi
    71     xor rdx, rdx
    72     mov rax, SYS_ACCEPT
    73     syscall
    74     stackpop
    75     ret
    76 
    77 sys_cork:;rdi - socket
    78     stackpush
    79     mov r10, one_constant ;pointer to 1
    80     mov r8, 8        ;sizeof int
    81     mov rsi, LEVEL_IPPROTO_TCP
    82     mov rdx, SOCKOPT_TCP_CORK
    83     mov rax, SYS_SETSOCKOPT
    84     syscall
    85     stackpop
    86     ret
    87 
    88 sys_uncork:;rdi - socket
    89     stackpush
    90     mov r10, one_constant ;pointer to 1
    91     mov r8, 8        ;sizeof int
    92     mov rsi, LEVEL_IPPROTO_TCP
    93     mov rdx, SOCKOPT_TCP_CORK
    94     mov rax, SYS_SETSOCKOPT
    95     syscall
    96     stackpop
    97     ret
    98 
    99 sys_sendfile: ;rdi - outfd, rsi - infd, rdx - file size
   100     stackpush
   101     mov r10, rdx
   102     xor rdx, rdx
   103     mov rax, SYS_SENDFILE
   104     syscall
   105     stackpop
   106     ret
   107 
   108 sys_open:
   109     stackpush
   110     mov rsi, OPEN_RDONLY ;flags
   111     mov rax, SYS_OPEN
   112     syscall
   113     stackpop
   114     ret
   115 
   116 sys_close:
   117     stackpush
   118     mov rax, SYS_CLOSE
   119     syscall
   120     stackpop
   121     ret
   122 
   123 sys_write:
   124     stackpush
   125     mov rdx, rsi ;length
   126     mov rsi, rdi ;buffer
   127     mov rdi, FD_STDOUT
   128     mov rax, SYS_WRITE
   129     syscall
   130     stackpop
   131     ret
   132 
   133 sys_send:
   134     stackpush
   135     xor r10, r10
   136     xor r8, r8
   137     xor r9, r9
   138     mov rax, SYS_SENDTO
   139     syscall
   140     stackpop
   141     ret
   142 
   143 sys_recv:
   144     stackpush
   145     xor r10, r10 ; flags
   146     xor r8, r8
   147     xor r9, r9
   148     mov rax, SYS_RECVFROM
   149     syscall
   150     stackpop
   151     ret
   152 
   153 sys_lseek:; rdi - fd, rsi - offset, rdx - flag
   154     stackpush
   155     mov rax, SYS_LSEEK
   156     syscall
   157     stackpop
   158     ret
   159