I had been explicitly warned against making a GUI program in assembly, but (as I'm sure all of you already know,) I'm stubborn and thought it would make a fun exercise to make a simple window. I looked into how an X server works and read that you're supposed to establish a socket connection, so I looked up sockets and found this nice reference: http://www.cs.rpi.edu/~moorthy/Courses/ ... ocket.html
Since the program using the X Server should be a client, I saw that the only system calls I should have to use (other than "write" once I establish a connection) are "socket" and "connect". The socket syscall was simple enough to figure out; unless I'm understanding this incorrectly, this is all that has to be done:
Then, just like the "open" syscall, it returns a file descriptor in rax that you need to use for "connect" (and of course "write"). However, as lame as this is, I'm stuck at what the "socket address" (the structure pointed by rdi) is supposed to be in the "connect" syscall. I found this article https://www.ibm.com/support/knowledgece ... xsock.html that at least tells me what the address is supposed to look like (a unix filename) but I have no idea what it's supposed to be the filename of; the X Server itself?
This page I found goes over the X Window System protocol, but unsurprisingly, it expects that you already have a connection established. https://www.x.org/releases/X11R7.7/doc/ ... tion_Close
I get the feeling no one really does this stuff without using libraries... It's become apparent to me that there's really not much at all to be gained by using assembly over C here either; half of what I've been doing is just moving immediate values into registers, which a compiler will do just as well. Of course, that holds true for most programming now a days.
Since the program using the X Server should be a client, I saw that the only system calls I should have to use (other than "write" once I establish a connection) are "socket" and "connect". The socket syscall was simple enough to figure out; unless I'm understanding this incorrectly, this is all that has to be done:
Code:
mov rdi, 0 ;domain AF_UNIX
mov rsi, 1 ;type SOCK_STREAM
mov rdx, 0 ;use default protocol (TCP)
mov rax, 41 ;syscall number for socket
syscall
mov rsi, 1 ;type SOCK_STREAM
mov rdx, 0 ;use default protocol (TCP)
mov rax, 41 ;syscall number for socket
syscall
Then, just like the "open" syscall, it returns a file descriptor in rax that you need to use for "connect" (and of course "write"). However, as lame as this is, I'm stuck at what the "socket address" (the structure pointed by rdi) is supposed to be in the "connect" syscall. I found this article https://www.ibm.com/support/knowledgece ... xsock.html that at least tells me what the address is supposed to look like (a unix filename) but I have no idea what it's supposed to be the filename of; the X Server itself?
This page I found goes over the X Window System protocol, but unsurprisingly, it expects that you already have a connection established. https://www.x.org/releases/X11R7.7/doc/ ... tion_Close
I get the feeling no one really does this stuff without using libraries... It's become apparent to me that there's really not much at all to be gained by using assembly over C here either; half of what I've been doing is just moving immediate values into registers, which a compiler will do just as well. Of course, that holds true for most programming now a days.