SMP (on intel) set address of code
SMP (on intel) set address of code
Hello!
I have 2 CPUs, each are working not in real time mode. Than I stop one of them.
After this I copy some code to 0x3000000 and want that stopped CPU continue his work from this address ( 0x3000000 ).
How it can be done? Is it some tutorial/code-example?
With best regards,
Oleksii
I have 2 CPUs, each are working not in real time mode. Than I stop one of them.
After this I copy some code to 0x3000000 and want that stopped CPU continue his work from this address ( 0x3000000 ).
How it can be done? Is it some tutorial/code-example?
With best regards,
Oleksii
Re: SMP (on intel) set address of code
Hi,
The easiest way would be to make the CPU poll a flag in memory, and jump to the address ( 0x3000000 ) when some other CPU sets the flag.
"Less easy" ways would include doing the whole "INIT-SIPI-SIPI" thing again (if the CPU was stopped using "CLI" and "HLT" loop); or setting up interrupts and using an IPI to interrupt the CPU and make it execute the new code (if the CPU was stopped using a "STI" and "HLT" loop).
Cheers,
Brendan
How was the CPU "stopped"?coldfire wrote:I have 2 CPUs, each are working not in real time mode. Than I stop one of them.
After this I copy some code to 0x3000000 and want that stopped CPU continue his work from this address ( 0x3000000 ).
How it can be done? Is it some tutorial/code-example?
The easiest way would be to make the CPU poll a flag in memory, and jump to the address ( 0x3000000 ) when some other CPU sets the flag.
"Less easy" ways would include doing the whole "INIT-SIPI-SIPI" thing again (if the CPU was stopped using "CLI" and "HLT" loop); or setting up interrupts and using an IPI to interrupt the CPU and make it execute the new code (if the CPU was stopped using a "STI" and "HLT" loop).
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.
Re: SMP (on intel) set address of code
a bit irrelevant question to this topic - is there some free and easy code snippet that initializes the multiple cpu cores WITHOUT requiring of the full understanding of the underlying process? at the end i would like to have a function with inline assemblys like int wakeupnextcpu(unsigned short new_eip) (1 on success, 0 on failure)
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
http://users.atw.hu/gerigeri/DawnOS/download.html
Re: SMP (on intel) set address of code
Hi,
Cheers,
Brendan
A function like "int wakeupnextcpu(unsigned short new_eip)" would need to depend on:Geri wrote:a bit irrelevant question to this topic - is there some free and easy code snippet that initializes the multiple cpu cores WITHOUT requiring of the full understanding of the underlying process? at the end i would like to have a function with inline assemblys like int wakeupnextcpu(unsigned short new_eip) (1 on success, 0 on failure)
- Code to find and parse ACPI's MADT/APIC table (if present) and maybe also to find and parse MultiProcessor Spec. tables (as a fall-back on old computers if there's no ACPI)
- That the local APIC can be accessed somehow (e.g. mapped into the virtual address space)
- Access to a time source (for both time delays and time-outs)
- The ability to obtain (allocate) memory to use for the AP CPU startup trampoline
- The ability to obtain (allocate) memory to use for the new CPU's stack
- Details of how the OS expects things like GDT, IDT and paging to be configured
- The ability to return "no more CPUs to start", and information to allow error messages like "CPU #3 is faulty (time-out when trying to start)"
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.
Re: SMP (on intel) set address of code
BareMetal-kernel has this via the b_smp_set call. The kernel keeps a table in memory of code to execute and then you wake up a CPU to execute it.
-Ian
-Ian
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
Re: SMP (on intel) set address of code
thanks for the info. pure real mode will be fine. thats the reason of the short int. i dont need any special functionality from the MP executer code, just to have the next core crawling on the specified place.
(which is below 64k, and where i previously place assembly code to switch unreal mode, and do the main loop written in assembly)
(which is below 64k, and where i previously place assembly code to switch unreal mode, and do the main loop written in assembly)
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
http://users.atw.hu/gerigeri/DawnOS/download.html
Re: SMP (on intel) set address of code
IanSeyler: thankyou for hints, i will watch them too
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
http://users.atw.hu/gerigeri/DawnOS/download.html
Re: SMP (on intel) set address of code
is it possible that its really just simple to wake up the second cpu?
http://stackoverflow.com/questions/9809 ... -look-like
http://stackoverflow.com/questions/9809 ... -look-like
Code: Select all
MOV ESI, ICR_LOW ; Load address of ICR low dword into ESI.
MOV EAX, 000C4500H ; Load ICR encoding for broadcast INIT IPI
; to all APs into EAX.
MOV [ESI], EAX ; Broadcast INIT IPI to all APs
; 10-millisecond delay loop.
MOV EAX, 000C46XXH ; Load ICR encoding for broadcast SIPI IP
; to all APs into EAX, where xx is the vector computed in step 10.
MOV [ESI], EAX ; Broadcast SIPI IPI to all APs
; 200-microsecond delay loop
MOV [ESI], EAX ; Broadcast second SIPI IPI to all APs
; Waits for the timer interrupt until the timer expires
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
http://users.atw.hu/gerigeri/DawnOS/download.html
Re: SMP (on intel) set address of code
Hi,
Sadly, Intel's manual has some example code that is intended to be used by firmware (when a computer is first turned on) where broadcasting the INIT-SIPI-SIPI makes sense; and people see Intel's example code and make the mistake of thinking it's suitable for an OS when it's not. This has led to a lot of clueless beginners perpetuating the same "extremely bad/broken/stupid code".
Cheers,
Brendan
Extremely bad/broken/stupid code is often much simpler than code that is actually worth using. Broadcasting the INIT-SIPI-SIPI sequence (and starting all CPUs at once) is extremely bad/broken/stupid because it starts CPUs that should not be started (either because they were disabled by the user or disabled by the firmware because they are faulty), makes it impossible to determine if a CPU that should have started has failed to start, makes it impossible to pre-allocate memory for the CPUs to use for stack space, etc.Geri wrote:is it possible that its really just simple to wake up the second cpu?
Sadly, Intel's manual has some example code that is intended to be used by firmware (when a computer is first turned on) where broadcasting the INIT-SIPI-SIPI makes sense; and people see Intel's example code and make the mistake of thinking it's suitable for an OS when it's not. This has led to a lot of clueless beginners perpetuating the same "extremely bad/broken/stupid code".
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.
Re: SMP (on intel) set address of code
Adding to the point Brendan made (which is completely valid), _DO NOT_ use sewage overflow as a resource for OSdev, or any programming problem/question for that matter.
While you'll probably get the answer you're looking for, it's most likely not the answer you need.
While you'll probably get the answer you're looking for, it's most likely not the answer you need.
Re: SMP (on intel) set address of code
If it was stopped using through CLI/HLT, than when will done INIT-SIPI-SIPI it will from Real mode and etc?Brendan wrote:Hi,
How was the CPU "stopped"?coldfire wrote:I have 2 CPUs, each are working not in real time mode. Than I stop one of them.
After this I copy some code to 0x3000000 and want that stopped CPU continue his work from this address ( 0x3000000 ).
How it can be done? Is it some tutorial/code-example?
The easiest way would be to make the CPU poll a flag in memory, and jump to the address ( 0x3000000 ) when some other CPU sets the flag.
"Less easy" ways would include doing the whole "INIT-SIPI-SIPI" thing again (if the CPU was stopped using "CLI" and "HLT" loop); or setting up interrupts and using an IPI to interrupt the CPU and make it execute the new code (if the CPU was stopped using a "STI" and "HLT" loop).
Cheers,
Brendan
Re: SMP (on intel) set address of code
I did grep by b_smp_set and seems thah there is no such call.IanSeyler wrote:BareMetal-kernel has this via the b_smp_set call. The kernel keeps a table in memory of code to execute and then you wake up a CPU to execute it.
-Ian
Are U sure about name?
Re: SMP (on intel) set address of code
Hi,
Cheers,
Brendan
I'm sure of the name - it's on line 96 of "src/x86-64/syscalls/smp.asm".coldfire wrote:I did grep by b_smp_set and seems thah there is no such call.IanSeyler wrote:BareMetal-kernel has this via the b_smp_set call. The kernel keeps a table in memory of code to execute and then you wake up a CPU to execute it.
-Ian
Are U sure about name?
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.