Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not restoring DS in specific for loops #143

Open
asiekierka opened this issue Sep 5, 2023 · 0 comments
Open

Not restoring DS in specific for loops #143

asiekierka opened this issue Sep 5, 2023 · 0 comments

Comments

@asiekierka
Copy link

Same code as #142 - but the near SwanOffset pointer has been replaced with a far one, and the bitfield access bug has been worked around by using a manually combined uint16_t write.

https://asie.pl/files/gcc-ia16-20230905-193655.i

When compiling the above file with ia16-elf-gcc -O2 -mcmodel=medium -c -o main.o gcc-ia16-20230905-193655.i, the following ASM sequence gets emitted:

  76:	89 f3                	mov    %si,%bx
  78:	d1 e3                	shl    %bx
  7a:	81 c3 00 00          	add    $0x0,%bx
			7c: R_386_16	SwanOffset
  7e:	8e 5e fe             	mov    -0x2(%bp),%ds
  81:	8b 07                	mov    (%bx),%ax

This is code to access SwanOffset[%si] and write it to %ax, which works well, except at no point is the value of %ds restored, causing issues later down the chain.

The -O0 variant of the code likewise does not restore %ds, but it seemingly avoids triggering this issue by overzealously using %ss: prefixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant