📄 main.c
字号:
/*
* main.c
*
* kernel main function
* You can see whole progress.
* 1 boot.bin (boot.asm)
* |
* V
* 2 setup.bin (setup.asm)
* |
* V
* 3 system.bin
* system.bin is the kernel...
*/
#include "def.h"
#include "time.h"
#include "sched.h"
#include "system.h"
#define BCD_TO_BIN(val) ((val)=((val)&0xf)+((val)>>4)*10)
void init(); /*task0 */
void task1(); /*task1 */
void task2(); /*task2 */
static long startup_time=0; /*sign the system time */
/*
* Initialize system time,the time will be
* saved in startup_time.
*/
static void time_init(void)
{
struct t_time time;
do{
time.tm_sec=CMOS_READ(0);
time.tm_min=CMOS_READ(2);
time.tm_hour=CMOS_READ(4);
time.tm_day=CMOS_READ(7);
time.tm_mon=CMOS_READ(8);
time.tm_year=CMOS_READ(9);
}while(time.tm_sec!=CMOS_READ(0));
BCD_TO_BIN(time.tm_sec);
BCD_TO_BIN(time.tm_min);
BCD_TO_BIN(time.tm_hour);
BCD_TO_BIN(time.tm_day);
BCD_TO_BIN(time.tm_mon);
BCD_TO_BIN(time.tm_year);
time.tm_mon--;
startup_time=getStartTime(&time);
}
/*
* Main function.
* From here,we programme in c language.
* 1. Clear screen.
* 2. Print tip message.
* 3. Initilize task 0 and global task struct arrays.
* 4. Initilize char device.
* 5. Open the timer interupt.
* 6. Set interrupt flag bit.
* 7. Entry user mode.(ring0->ring3)
* 7. Initilize task 1 and 2.
* 8. Loop,task 0,1 and 2 will alternative run.
*/
int main()
{
clrscr(); /* clear screen */
printk("------MINIOS is running------\n");
sched_init(); /* initialize task 0 and global task struct arrays */
char_drv_init(); /* initialize char device,fill keyboard interrupt vector */
outportb(0x21,inportb(0x21)&0xfe);
sti(); /* open timer interrupt and set interrupt flag bit */
move_to_user_mode(); /* entry user mode.From here,system will run in ring3 */
//printf("Very well.%x Minios is startting...\n",255);
task_init(task1);
task_init(task2); /* initialize task 1 and 2 */
while(1){ /* wait for new task,if there have no any new task,
task0 will run forever */
init();
}
return 0;
}
/*
* Initialize task 0 and global task struct arrays.
* Set task 0 tss descriptor and ldt descriptor.
* Load task0's tr and ldtr.
*/
void sched_init()
{
int i;
for (i=0; i<NR_TASK; i++) /* Initialize global task struct arrays */
{
task[i].pid = -1; /* pid=-1 repersent that the task struct is available. */
task[i].priority = -1;
task[i].counter = -1;
task[i].ldt_sel = -1;
task[i].tss_sel = -1;
}
process_id = 1;
p_current = NULL;
p_current = NULL;
p_previous = NULL;
p_ready = NULL;
p_head = NULL;
set_tss_desc(0, _tss0);
set_ldt_desc(0, _ldt0);
cl_nt(); /* prapre for move to user mode. */
lldt(0); /* load task 0 ldtr */
ltr(0); /* load task 0 tr */
}
/*
* Task 0
* Only print a char '0'.
*/
void init()
{
unsigned long i;
while(1)
{
putchar('0');
for (i=0; i<0x3fff; i++);
}
}
/*
* Task 1
* print a char 'A',keep it simply...
*/
void task1()
{
unsigned long i;
while(1)
{
putchar('A');
for (i=0; i<0x3fff; i++);
}
}
/*
* Task2
* print a char 'B',also simply...
*/
void task2()
{
unsigned long i;
while(1)
{
putchar('B');
for (i=0; i<0x3fff; i++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -