From owner-freebsd-questions@freebsd.org Mon Jul 31 20:00:00 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8D665DBC532 for ; Mon, 31 Jul 2017 20:00:00 +0000 (UTC) (envelope-from makketronics@gmail.com) Received: from mail-qk0-x22f.google.com (mail-qk0-x22f.google.com [IPv6:2607:f8b0:400d:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49058664EA for ; Mon, 31 Jul 2017 20:00:00 +0000 (UTC) (envelope-from makketronics@gmail.com) Received: by mail-qk0-x22f.google.com with SMTP id u139so92407594qka.1 for ; Mon, 31 Jul 2017 13:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=+lJ4GpUTFkVRy11Q0aq8f4yXoiVSQSqbbi9aWFoDr+Q=; b=FQMPtr7dEV8WRovXNJcGnRB0/5QACXcwpgbBb5j+MkEehTPacV+4CFEfSB/Y8ewRme W7T1Eb2b00nz/DL5EzpLkR4JjJza9dW8/VmDJCHG8+IQTboWW1RBuWqLeJQ8S/TzrLsE ZNvEEXq9mQQlUMjEUHwCOT8jIkEufC9fBa4EJsJTFw0F1dTwqJluVtyAo1JvUmCNeWeR 9gmpIx6HWOXLyr+QE7dVpoq5bfiriMObrg9adgulSA8Vw4H5yhEjUPaf0rl8FzXSOnX1 CgSwUOXmRfdw9J69gqJBFuB5uej9+ate1gHh0Z1p5vb6k8yX/de8/X3d75icyN1MloP/ JR7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=+lJ4GpUTFkVRy11Q0aq8f4yXoiVSQSqbbi9aWFoDr+Q=; b=tSUpR9EWS9p622GbcHIcdXubp5LMtaakSy3DQB+5xldJGcg6NYwEBX/tgYNK7NbovP vx9Wj5Mmid9ntzp0vowiOOgBOjAqIuCThIuZlz9DEy9GWNGVqZ+cMYIRaXLr4PqYU2G8 XyOxE546cmGx9/yNJwfO1Zxygp7PvpYYVke/wiJuKG8Ivy512SMe33CMI8UF/Q9TL4Tv NjVJY4RqiRQopH30V27jvKIIaBKGJCnps/K/cPs3XdHb+Y/wurUrI3z3zpp9+R7AScIX wKT62GQdAsfsbwgPdviSvxs4qLbNtRDCbmEOSrUbweeyiEZHQun0t6hrGOODZ69BgfNI mxpQ== X-Gm-Message-State: AIVw113xkJbLB5xX56eqhnFCCMrBUxzGknsVUI/IC7eNWhm52PnAfbX0 J+BqFe1Wc0u9+B9JXf0j9c3n3i2Mb+Zt X-Received: by 10.55.122.196 with SMTP id v187mr21162126qkc.273.1501531198956; Mon, 31 Jul 2017 12:59:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.89.10 with HTTP; Mon, 31 Jul 2017 12:59:58 -0700 (PDT) From: Makketron Date: Mon, 31 Jul 2017 15:59:58 -0400 Message-ID: Subject: FreeBSD System Calls in Assembly To: freebsd-questions@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jul 2017 20:00:00 -0000 Hello, It seems that the documentation here doesn't apply for 64-bits. https://www.freebsd.org/doc/en/books/developers-handbook/x86.html I asked a question on stackoverflow. I thought I should ask it here too https://stackoverflow.com/questions/45423987/freebsd-64bits-convention-call-documentation I am running FreeBSD 11.0. The following from the FreeBSD manual does NOT print the "Hello, World!" message: section .text hello db 'Hello, World!, 0Ah hbytes equ $-hello _syscall: int 80h ret global _start _start: push dword hbytes push dword hello push dword 1 ; stdout mov rax, 4 ; write syscall call _syscall add rsp, byte 24 ; restore stack push word 0 ; return 0 mov rax, 1 ; exit call call _syscall But this works: section .text hello db 'Hello, World!, 0Ah hbytes equ $-hello _syscall: int 80h ret global _start _start: mov rdi, 1 mov rsi, hello ; appears to be magic mov rdx, hbytes ; appears to be magic mov rax, 4 ; write syscall call _syscall push word 0 ; return 0 mov rax, 1 ; exit call call _syscall This raises couple questions: 1) Why doesn't the first approach work? The UNIX calling convention is push data on the stack. Program does not crash. I just don't get any output, and the program terminates. I am compiling and linking fine. 2) How are we supposed to know about what registers to load, and with what values? If I was pushing on the stack, it is easy. I look up the C functions and then I know how to push data. In this case, it works like magic. 3) Where is the documentation for FreeBSD for similar system calls (not utilizing stack)??! Thank you.