Lecture: system calls

preparation

labs & questions

overview

exceptions

device interrupts

software interrupts

#include <sys/syscall.h>
#include <unistd.h>
// syscall number: %eax
// syscall parameters %ebx, %ecx, %edx, %esi, %edi, %ebp
void _start(void)
{
        int fd = 1;
        char buf[] = "hello world!\n";
        size_t count = sizeof(buf) - 1;
        asm volatile ("int $0x80"
                : /* ignore output */
                : "a"(__NR_write), "b"(fd), "c"(buf), "d"(count)
                : "cc", "edi", "esi", "memory"
        );
        asm volatile ("int $0x80"
                : /* no output */
                : "a"(__NR_exit), "b"(0)
        );
}