When learning OS, the task switch for multi-tasking operating systems has been unable to understand: What is the control right back to the scheduler? I remember to describe this when describing the task switch: Try the current process if the current process is a user process running more than 100 milliseconds. If so, call the scheduler to see if there is another user process waiting for CPU, ...
I will give an example here: I wrote a program with C: HelloWorld. code show as below:
#code_startvoid main (void) {PUTS ("Hello World First."); PUTS ("Hello World Second.");} # code_end
I am using the code under Minix. When the program runs to PUTS ("Hello World First.", He prints Hello World First on the screen. One thing can be sure, the CPU is now under the control of my program . But when it is ingenious, this time the scheduler discovers that another program requires the CPU, so it immediately puts the CPU back from my HelloWorld and handed over to another program.
If the entrance address of the scheduler is: Scheduler. So, there should always be a JMP Scheduler in my HelloWorld. In this way, you can jump to the Scheduler.
Of course, watching the source code of minix is the best way, but the knowledge I have now mastered can also play the Scheduler. I just thought of it, so I immediately wrote it.
It is very simple to implement this feature.
At every second, the interrupt 0x1c is called 18.2 times, and this interrupt can be rewritten:
#code_startvoid new_int_1c (void) {volatile static int count = 0; if (count > 17) {count = 0; _ASM JMP Scheduler; // Scheduler is the scheduling program}} # code_end
So, about one second, the control will return to the scheduler, and then determine the control of the CPU by scheduling.
Of course, use 0x1c just to write code, the real OS is directly programmed for 5253/8254.