OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 1:09 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 4:10 am 
Offline

Joined: Tue Apr 11, 2017 3:19 am
Posts: 12
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


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 8:53 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

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?


How was the CPU "stopped"?

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.


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 9:00 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
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


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 10:54 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

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)


A function like "int wakeupnextcpu(unsigned short new_eip)" would need to depend on:
  • 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)"

None of this is really portable.


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.


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 10:57 am 
Offline
Member
Member
User avatar

Joined: Mon Jul 28, 2008 9:46 am
Posts: 325
Location: Ontario, Canada
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

_________________
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 11:05 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
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)

_________________
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 11:10 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
IanSeyler: thankyou for hints, i will watch them too

_________________
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 11:23 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
is it possible that its really just simple to wake up the second cpu?

http://stackoverflow.com/questions/9809 ... -look-like

Code:
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


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Wed Apr 12, 2017 12:11 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

Geri wrote:
is it possible that its really just simple to wake up the second cpu?


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.

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.


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Thu Apr 13, 2017 12:09 am 
Offline
Member
Member

Joined: Wed Sep 19, 2012 3:43 am
Posts: 91
Location: The Netherlands
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.


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Thu Apr 13, 2017 3:50 am 
Offline

Joined: Tue Apr 11, 2017 3:19 am
Posts: 12
Brendan wrote:
Hi,

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?


How was the CPU "stopped"?

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


If it was stopped using through CLI/HLT, than when will done INIT-SIPI-SIPI it will from Real mode and etc?


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Thu Apr 13, 2017 3:53 am 
Offline

Joined: Tue Apr 11, 2017 3:19 am
Posts: 12
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


I did grep by b_smp_set and seems thah there is no such call.
Are U sure about name?


Top
 Profile  
 
 Post subject: Re: SMP (on intel) set address of code
PostPosted: Thu Apr 13, 2017 4:25 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

coldfire wrote:
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


I did grep by b_smp_set and seems thah there is no such call.
Are U sure about name?


I'm sure of the name - it's on line 96 of "src/x86-64/syscalls/smp.asm".


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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 85 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