GPF on interrupt (stub calls another entry after handler)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

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

Post 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
Carpe diem!
cart
Posts: 9
Joined: Thu May 13, 2021 4:40 pm

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

Post 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");
Post Reply