Hello all,
I need to know what do I need to know to implement threads support for my OS in C or in ASM .
At this moment, malloc and free aren't implemented on my kernel, and I don't have a File System for my OS yet...
How to run two or more threads on the same time ? for example I want to run theses two threads : printf("Thread 1"); and printf("Thread 2"); .
Some links to very simple multi-tasking howto's would be nice .
The only thing I do understand yet is if there are two threads runing at the same time, the instructions sequence will be :
[1st instruction from Thread 1] Saving ESP, EIP ... and switching to Thread 2
[1st instruction from Thread 2] Saving ESP, EIP ... and switching to Thread 1
[2nd instruction from Thread 1] Saving ESP, EIP ... and switching to Thread 2
[2nd instruction from Thread 2] Saving ESP, EIP ... and switching to Thread 1
[3rd instruction from Thread 1] Saving ESP, EIP ... and switching to Thread 2
[3rd instruction from Thread 2] Saving ESP, EIP ... and switching to Thread 1
Thanks for help .
Threads ... ?
-
- Member
- Posts: 89
- Joined: Sun Mar 23, 2008 2:23 pm
- Location: [0x8:0x1000]
I can't help you, but you may want to look at JamesM's tutorial:
http://jamesmolloy.co.uk/tutorial_html/ ... sking.html
Cheers,
Lee
http://jamesmolloy.co.uk/tutorial_html/ ... sking.html
Cheers,
Lee
Hi,
For a general overview, see Context Switching. In your example, you switch after every instruction, which would make for a very slow system. Generally, you will set up a time source (PIT? Local APIC Timer?) to cause an IRQ every, say, 10ms. The pseudo code is somthing like this:
The fact that you are have already fired an IRQ means that EFLAGS, EIP and CS are already on the stack, and the IRET automatically pops the new values for these registers. Once this works for ring 0, you then need to worry about a TSS for ring3 -> ring 0 transitions.
Hope that helps get you started!
Cheers,
Adam
For a general overview, see Context Switching. In your example, you switch after every instruction, which would make for a very slow system. Generally, you will set up a time source (PIT? Local APIC Timer?) to cause an IRQ every, say, 10ms. The pseudo code is somthing like this:
Code: Select all
pusha ;or 64 bit equivalent which will be a macro
push ds, es, fs and gs
mov eax, esp
push esp ;for 32 bit GCC, this passes esp to the scheduler
call scheduler
mov esp, eax ;for 32 bit GCC, this takes the scheduler return val (esp for incoming task)
pop gs, fs, es and ds
popa
iret
Hope that helps get you started!
Cheers,
Adam
-
- Member
- Posts: 89
- Joined: Sun Mar 23, 2008 2:23 pm
- Location: [0x8:0x1000]