flat assembler
Message board for the users of flat assembler.
Index
> Linux > Thanks to all Goto page Previous 1, 2, 3 Next |
Author |
|
FlierMate1 27 Jun 2022, 17:03
Thanks @revolution for the detailed explanation.
|
|||
27 Jun 2022, 17:03 |
|
revolution 27 Jun 2022, 19:02
I expect that your ExposureMask is not correct.
Try a value like 2 instead of 0. Edit: X.h defines ExposureMask = 0x8000 Code: #define NoEventMask 0L #define KeyPressMask (1L<<0) #define KeyReleaseMask (1L<<1) #define ButtonPressMask (1L<<2) #define ButtonReleaseMask (1L<<3) #define EnterWindowMask (1L<<4) #define LeaveWindowMask (1L<<5) #define PointerMotionMask (1L<<6) #define PointerMotionHintMask (1L<<7) #define Button1MotionMask (1L<<8) #define Button2MotionMask (1L<<9) #define Button3MotionMask (1L<<10) #define Button4MotionMask (1L<<11) #define Button5MotionMask (1L<<12) #define ButtonMotionMask (1L<<13) #define KeymapStateMask (1L<<14) #define ExposureMask (1L<<15) #define VisibilityChangeMask (1L<<16) #define StructureNotifyMask (1L<<17) #define ResizeRedirectMask (1L<<18) #define SubstructureNotifyMask (1L<<19) #define SubstructureRedirectMask (1L<<20) #define FocusChangeMask (1L<<21) #define PropertyChangeMask (1L<<22) #define ColormapChangeMask (1L<<23) #define OwnerGrabButtonMask (1L<<24) |
|||
27 Jun 2022, 19:02 |
|
revolution 27 Jun 2022, 19:33
Note that your code never restores the stack. It just keeps pushing more values!
Eventually your could run out of stack and it will crash. For the simple loop above I guess it will be fine, but once you make it more complex and have other stuff, then problems can begin to appear. |
|||
27 Jun 2022, 19:33 |
|
bitRAKE 28 Jun 2022, 02:00
FlierMate1 wrote: why hello.cpp can show "Hello World" while hello.asm is still "empty window"? _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
28 Jun 2022, 02:00 |
|
FlierMate1 28 Jun 2022, 06:12
revolution wrote: I expect that your ExposureMask is not correct. I tried to set EDX to 2, but it is still the same. revolution wrote: Note that your code never restores the stack. It just keeps pushing more values! I am not good in anything related to stack handling, perhaps someone can show me how. bitRAKE wrote: The C++ code is clearly calling XDrawString within the WHILE loop. Nice catch. I tried placing XDrawString in the WHILE loop, but it is still the same, empty window. |
|||
28 Jun 2022, 06:12 |
|
I 28 Jun 2022, 07:36
Missing ExposureMask in XSelectInput.
mov edx, 1 shl 15 |
|||
28 Jun 2022, 07:36 |
|
FlierMate1 28 Jun 2022, 08:56
I wrote: Missing ExposureMask in XSelectInput. Brilliant, man! revolution wrote:
It was @revolution who found it first, but @I suggested a correct value.
|
||||||||||
28 Jun 2022, 08:56 |
|
FlierMate1 28 Jun 2022, 09:08
I am attaching the source modified from ProMiNick's example to display processor name in a GUI window.
Yes, the XDrawString must be in WHILE loop, thanks @bitRAKE for that.
|
||||||||||||||||||||
28 Jun 2022, 09:08 |
|
revolution 28 Jun 2022, 12:39
FlierMate1 wrote: It was @revolution who found it first, but @I suggested a correct value. Code: #define ExposureMask (1L<<15) |
|||
28 Jun 2022, 12:39 |
|
FlierMate1 28 Jun 2022, 12:44
revolution wrote:
I could have solved it earlier if I didn't overlook your "ExposureMask = 0x8000". Sorry, after I reread it I fully understand. |
|||
28 Jun 2022, 12:44 |
|
I 29 Jun 2022, 02:17
Cool, thanks for the code. I wouldn't have known where to start, now I do.
I cheated a bit and used cutter on the compiled C++, see below. Hope I have commented correctly (green). Cutter is work in progress but have found it handy for Linux and even learnt a little about Linux Arm ASM too. Runs on Win, Linux, Mach although I haven't tried the Mach version. The strings don't need zero termination, just the length of the text. That's why those dashed boxes appear at the end. Interestingly the g++ compiler didn't call a couple of functions but parsed the structures instead. Like XDefaultGC instead gets gc from the screen structure which is pointed to from the disp structure. Something like Code: mov rax,[disp.Screen] mov rax [rax+default_gc] mov [gc], rax
|
||||||||||
29 Jun 2022, 02:17 |
|
bitRAKE 29 Jun 2022, 03:03
The disassembly also makes clear the stack alignment and correction needed for XDrawString, within the event loop. I've not read the related documentation/code, but I'm assuming the calling convention.
The C code here also shows event loop exit and program termination - which is probably a good idea. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
29 Jun 2022, 03:03 |
|
revolution 29 Jun 2022, 03:48
bitRAKE wrote: The disassembly also makes clear the stack alignment and correction needed for XDrawString, within the event loop. I've not read the related documentation/code, but I'm assuming the calling convention. |
|||
29 Jun 2022, 03:48 |
|
I 29 Jun 2022, 04:55
@bitRAKE thanks for the link.
Yes, I was wondering about the alignment, seems to push for 16byte alignment (forgive the pun) as seen with the question marked sub rsp,8 before a single push. Does seem to work without it IIRC. Also a bit puzzled by the zealous use of rcx and rax by g++. Checking Agner Fog's article on Alignment chapter 5 it states Quote: The 64 bit systems keep the stack aligned by 16. The stack word size is 8 bytes, but the stack must be aligned by 16 before any call instruction. Consequently, the value of the stack pointer is always 8 modulo 16 at the entry of a procedure. A procedure must subtract an odd multiple of 8 from the stack pointer before any call instruction. A procedure can rely on these rules when storing XMM data that require 16-byte alignment. This applies to all 64 bit systems (Windows, Linux, BSD). Or maybe I've misunderstood it? |
|||
29 Jun 2022, 04:55 |
|
bitRAKE 29 Jun 2022, 05:24
I was wrong about correct window termination - an explicit message needs to be relayed to exit without error:
Code: #include <X11/Xlib.h> #include <string.h> int main(int, char**) { Display *display = XOpenDisplay(0); GC gc = DefaultGC(display, 0); Font font = XLoadFont(display, "fixed"); XSetFont(display, gc, font); Window root = DefaultRootWindow(display); Window window = XCreateSimpleWindow( display, root, 0, 0, 256, 256, 0, 0, 0xffffff); Atom wmDeleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", False); XSetWMProtocols(display, window, &wmDeleteMessage, 1); XSelectInput(display, window, ExposureMask | StructureNotifyMask); XMapRaised(display, window); while (1) { XEvent event; XNextEvent(display, &event); if (event.type == Expose) { const char *msg = "Hello World"; XDrawString(display, window, gc, 16, 16, msg, (int) strlen(msg)); } else if (event.type == ClientMessage) { if (event.xclient.data.l[0] == wmDeleteMessage) { XDestroyWindow(display, window); XCloseDisplay(display); break; } } } return 0; } _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup Last edited by bitRAKE on 29 Jun 2022, 05:31; edited 1 time in total |
|||
29 Jun 2022, 05:24 |
|
revolution 29 Jun 2022, 05:30
I wrote: Checking Agner Fog's article on Alignment chapter 5 it states Perhaps the alignment is for "speed"? |
|||
29 Jun 2022, 05:30 |
|
I 29 Jun 2022, 07:52
@revolution maybe that's it then, how can we guarantee that instruction isn't in a library function, now or sometime in the future.
https://board.flatassembler.net/topic.php?t=22256&start=14 Your smaller second clod64 1k code for me on Fedora x64 34 and 36 [alex@fedora bw]$ ./clod64 Segmentation fault (core dumped) The first clod64 code you posted worked fine, nice work BTW. If I change the stack alignment as so Code: start: sub rsp,0x8 invoke SDL_Init,SDL_INIT_VIDEO test rax,rax mov ebp,1 jnz .err mov rbx,SDL_OPENGL cmp qword[rsp],1 ;full screen? jbe .set_mode ; mov rbx,SDL_OPENGL or SDL_FULLSCREEN ; invoke SDL_ShowCursor,0 .set_mode: invoke SDL_SetVideoMode,x_res,y_res,0,rbx |
|||
29 Jun 2022, 07:52 |
|
revolution 29 Jun 2022, 08:47
You changed rbx, so the call to SDL_SetVideoMode is not correct. The change you made doesn't affect the stack, all the parameters are passed in registers.
|
|||
29 Jun 2022, 08:47 |
|
revolution 29 Jun 2022, 08:49
I wrote: @revolution maybe that's it then, how can we guarantee that instruction isn't in a library function, now or sometime in the future. I had another thread discussing the Windows RSP, and many there seem unconvinced also. A lot of superstition over RSP usage. |
|||
29 Jun 2022, 08:49 |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.