Lock on all processors for AP startup sequence on x86

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.
Post Reply
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Lock on all processors for AP startup sequence on x86

Post by max »

Hi :)

I've implemented the SMP startup sequence for the AP's in my kernel. Now inside my AP startup code, I need to have a section that is locked across all processors, so I can assign a different stack for each AP. There is only one instance of this code (in lower memory at 0x1000), so I tried to implement the lock like this:

Code: Select all

 ; Inter-core synchronization
interlock:
    dd 0x00000000

acquireLock:
    lock bts [interlock], 0
    jc acquireLock
    ret

releaseLock:
    lock btr [interlock], 0
    ret

The problem is that NASM tells me that I have an invalid combination of opcode and operands at both of the locked instructions. What is the problem here?

Thank you!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Lock on all processors for AP startup sequence on x86

Post by Brendan »

Hi,
max wrote:The problem is that NASM tells me that I have an invalid combination of opcode and operands at both of the locked instructions. What is the problem here?
The problem is that NASM can't figure out the operand size you want. To fix it either do "lock bts dword [interlock], 0" or "lock bts word [interlock], 0".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Lock on all processors for AP startup sequence on x86

Post by max »

Thanks Brendan, that fixed it. That message is a little misleading because normally NASM will complain with operation size not specified instead of this.

Thank you!
Post Reply