ARM Integrator-CP ITPTMME Phase2: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
m Bot: Replace deprecated source tag with syntaxhighlight
m Bot: Replace deprecated source tag with syntaxhighlight
Line 71: Line 71:
=== Separate Scheduler Function ===
=== Separate Scheduler Function ===
I have added support for sleeping threads, and a wake up flag. This is by no means a correct design, but rather just a demonstration of how you could put threads to sleep and wake them up. It also supports a timeout which allows a thread to not only wake up with an external signal but also after a specified amount of time.
I have added support for sleeping threads, and a wake up flag. This is by no means a correct design, but rather just a demonstration of how you could put threads to sleep and wake them up. It also supports a timeout which allows a thread to not only wake up with an external signal but also after a specified amount of time.
<source lang="c">
<syntaxhighlight lang="c">
void ksched() {
void ksched() {
KSTATE *ks;
KSTATE *ks;
Line 251: Line 251:
}
}
}
}
</syntaxhighlight>
</source>
Here we have the basic save thread state and load thread state blocks. These possibly could be implemented in a much faster way, but I choose to avoid premature optimization for the sake of being straight forward. In the middle between the save and load state blocks you have the code to choose the next thread. In it's simplest form it simply grabs the next thread in the current process, and if no thread left it grabs the next process and the first thread. It continues this until it has a thread to run. In the form above it does the exact same except it checks if the thread is sleeping, then it checks the ''timeout'' (minimum time to sleep for) and if it is expired it sets the thread as awake and runs it. It also checks if any signal has been asserted to the thread and if so (and only if) then the thread is woken if it is sleeping. You might be wondering why I remove the wake signal (bit) only if the thread is sleeping. This has to do with my future design of the IPC for the system.
Here we have the basic save thread state and load thread state blocks. These possibly could be implemented in a much faster way, but I choose to avoid premature optimization for the sake of being straight forward. In the middle between the save and load state blocks you have the code to choose the next thread. In it's simplest form it simply grabs the next thread in the current process, and if no thread left it grabs the next process and the first thread. It continues this until it has a thread to run. In the form above it does the exact same except it checks if the thread is sleeping, then it checks the ''timeout'' (minimum time to sleep for) and if it is expired it sets the thread as awake and runs it. It also checks if any signal has been asserted to the thread and if so (and only if) then the thread is woken if it is sleeping. You might be wondering why I remove the wake signal (bit) only if the thread is sleeping. This has to do with my future design of the IPC for the system.


Line 320: Line 320:


=== New Exception Handlers ===
=== New Exception Handlers ===
<source lang="c">
<syntaxhighlight lang="c">
void k_exphandler(uint32 lr, uint32 type) {
void k_exphandler(uint32 lr, uint32 type) {
uint32 *t0mmio;
uint32 *t0mmio;
Line 443: Line 443:
return;
return;
}
}
</syntaxhighlight>
</source>
The biggest difference here is the addition of systems call and the termination of a thread when it has an exception.
The biggest difference here is the addition of systems call and the termination of a thread when it has an exception.


Line 449: Line 449:
=== Added memset ===
=== Added memset ===
I added a useful utility function ''memset''.
I added a useful utility function ''memset''.
<source lang="c">
<syntaxhighlight lang="c">
void memset(void *p, uint8 v, uintptr sz) {
void memset(void *p, uint8 v, uintptr sz) {
uint8 *_p;
uint8 *_p;
Line 460: Line 460:
}
}
}
}
</syntaxhighlight>
</source>


=== Changes In kelfload ===
=== Changes In kelfload ===
<source lang="c">
<syntaxhighlight lang="c">
int kelfload(KPROCESS *proc, uintptr addr, uintptr sz) {
int kelfload(KPROCESS *proc, uintptr addr, uintptr sz) {
ELF32_EHDR *ehdr;
ELF32_EHDR *ehdr;
Line 540: Line 540:
asm("mcr p15, #0, r0, c8, c7, #0");
asm("mcr p15, #0, r0, c8, c7, #0");
}
}
</syntaxhighlight>
</source>
Here we simple allocate memory for the sections and then copy them into memory. I switch address spaces and flush the TLB to make this easier to perform. It could be faster just to map the memory into kernel space and copy to it in certain situations, but I decided that this method was the simplest.
Here we simple allocate memory for the sections and then copy them into memory. I switch address spaces and flush the TLB to make this easier to perform. It could be faster just to map the memory into kernel space and copy to it in certain situations, but I decided that this method was the simplest.


Line 645: Line 645:


=== Second Module Added ===
=== Second Module Added ===
<source lang="c">
<syntaxhighlight lang="c">
int _start(unsigned int *smmio) {
int _start(unsigned int *smmio) {
int x;
int x;
Line 658: Line 658:
return 0;
return 0;
}
}
</syntaxhighlight>
</source>


=== First Module ===
=== First Module ===