OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:34 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: GPF on interrupt (stub calls another entry after handler
PostPosted: Wed Jun 09, 2021 10:59 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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:
.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:
.text
1: movl (%esp), %eax
  ret

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

.data
1: .long -1

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: GPF on interrupt (stub calls another entry after handler
PostPosted: Thu Jun 10, 2021 11:28 am 
Offline

Joined: Thu May 13, 2021 4:40 pm
Posts: 9
Quote:
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:
asm volatile(...
"ljmp $0x8, $fake_gdt_jump%=;\n\t"
"fake_gdt_jump%=: ;"
...
: "ax", "memory");


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], SemrushBot [Bot] and 74 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group