Page 2 of 2

Re: GPF on interrupt (stub calls another entry after handler

Posted: Wed Jun 09, 2021 10:59 pm
by nullplan
cart wrote:I may be mistaken/misusing but I thought numeric labels, with "f/b", were supposed to be local and unique.
No they are not unique. That's the important part. You can reuse them. They were meant to be used in macros so they would be duplicated all over the place. You can only ever refer to two numeric labels with the same number (namely the next one and the previous one). It is because they are not unique that you need the f and b suffixes. Once I saw someone get the address of a static variable in a position independent way, without actually using position independent relocations:

Code: Select all

.text
function:
  call 1f
1: popl %eax
  addl $(1f-1b), %eax
[...]

.data
1: .long -1
And except for the part where it misaligns the return address cache, I found that really clever. And it shows you can reuse these labels, and even use them in the same instruction. Actually, put that way, you can reuse the label even more and get rid of the flaw I mentioned:

Code: Select all

.text
1: movl (%esp), %eax
  ret

function:
  call 1b
1: addl $(1f-1b), %eax
[...]

.data
1: .long -1

Re: GPF on interrupt (stub calls another entry after handler

Posted: Thu Jun 10, 2021 11:28 am
by cart
No they are not unique. That's the important part. You can reuse them. They were meant to be used in macros so they would be duplicated all over the place.
Thank you for the in-depth explanation.

I took the feedback you both gave, and looked up on how to generate unique labels. As @Octocontrabass said, inline asm is tricky to get right.
If I didn't mess up again, it seems to be done either with asm goto and a c label, or with "%=", so I updated the previous code to:

Code: Select all

asm volatile(...
"ljmp $0x8, $fake_gdt_jump%=;\n\t"
"fake_gdt_jump%=: ;"
...
: "ax", "memory");