/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / About multithreading

Username:     
Password:     
             

Forum

# 1   2010-04-29 10:44:35 About multithreading

ali_zarrouk
New member
From: Tunisia
Registered: 2010-02-16
Posts: 8

About multithreading

Hi ,

I'm working on making a multithreading library for circle os . I got some little problems , sure due to the fact that I'm new to circle os .

I'd like to know :

1) When I func is executed and have an argument input , is that argument placed in R0 ?
2) How can I know the starting point of a routine ( to set the PC of a thread ) ?
3) When there's multiple calls ( subroutines ) , where is placed the LR stack ?

Offline

 

# 2   2010-04-29 12:29:30 About multithreading

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: About multithreading

1) Some info about calling convention could be found in wikipedia:
http://en.wikipedia.org/wiki/Calling_convention#ARM

2) Starting point of function is the same as the value of it's C pointer. Use BX #reg assembler routine to jump to certain address instead of seting PC directly (see STM32F10xxx Cortex-M3 programming manual // section 3.8.5)

3) LR is saved in begining of every function that calls another function. In functions that do no call any other functions LR is kept in register. During interrupt LR is saved in stack with other values (see Cortex™-M3 Technical Reference Manual // section 5.5) and replaced with special interrupt return value.

Offline

 

# 3   2010-04-30 14:00:39 About multithreading

ali_zarrouk
New member
From: Tunisia
Registered: 2010-02-16
Posts: 8

Re: About multithreading

Hi , thanks for the answers ntrf.zns

1 ) Clear

2 ) The start routine is the second argument so the branching adress is r1 ---> Clear

3 ) Not that clear this time , I know how LR is manipulated but I wanna know if the current value of LR is saved in the used stack when a subroutine is called ? or another place ? If yes , then the adress where to save is decremented by 4 every time we make a "call"
Is what I said right ?

Offline

 

# 4   2010-04-30 15:58:50 About multithreading

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: About multithreading

LR is not saved on function call by processor. Functions which are calling other functions need to save it in stack or elsewhere manualy. Sometimes LR is saved with some other registers nedded for local variables. In this case LR is not necessary located at the begining of stack frame.

Offline

 

# 5   2010-05-01 05:15:46 About multithreading

ali_zarrouk
New member
From: Tunisia
Registered: 2010-02-16
Posts: 8

Re: About multithreading

Thank you , that's clear , it will help me a lot .

Now there's another thing I'd like to know please , due to the fact that circle os is monotask , any variable created is associated to an adress is unique , i.e. if thread A creates 2 variables i and j and that thread B uses i and j , it will use the variables created by thread A .

What I need to have , is a memory region for each thread , where every thread can have its own set of variables independently from other threads.
Dispatcher have to set a memory region to each task where it creates its own variables.
Let's say the threads I will create will not use more than 60 Bytes for creating multiple variables , 60 bytes ( a memory region of 60 Bytes in RW state ) + region code associated to the thread ( Read only ).

Well .. It could have been simple if an MPU was present , unfortunately it isn't the case and so I will have to implement a mechanism acting the same .

What I need to know is :

1) When a variable is created , what is done ? What assembly code is invoked ?

2) Some ideas about the memory choice for putting a association between a var name and an adress value ?

3) Where is placed the association "variable_name , type <---> adress in memory"

Offline

 

# 6   2010-05-01 16:13:23 About multithreading

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: About multithreading

I already answered you in different topic - it's not posible on STM32F.

All other multitask OS'es i saw was created for single address space. Normaly this is ok, because you are building a multitasking OS as part of single program. This results in single HEX file with single address space.

If you want to separate local variables in function the solution is simple - use multiple stacks and switch them. If you want sparated global variables - you want be able to it.

One posible solution would be to implement Debug Monitor and use inexisting address space when building apps. Then you can redirect variable access to different memory region. But it can be too slow and too complex to work correctly all the time.


1) All global variables are split into two regions: .data where all initialized variables can be found and .bss where all zero-filled variables would be. .data section is saved in flash and will be restored on application startup. Only size of .bss section is known and it's filled by zeroes at startup. Position of both sections in RAM declared in linkage file. You can find the C startup code in Application_startup.c file in CircleOS sources.

2) What? Variables are accesed by address, not by name. Linker is responsible for generating those.

3) In compilers internal data and debug info. It's never used in program itself.

Last edited by ntrf.zns (2010-05-01 16:14:42)

Offline

 

Board footer