MIT License
http://opensource.org/licenses/mit-license.php
- Copyright (C) 2013-2014 VaneOS Project. All rights reserved.
Copyright (C) 2013-2014 VOSystems. All rights reserved.
- Copyright (C) 2013 odeeeen. All rights reserved.
*/
#include<multiboot.h>
#include<System.h>
#include<Env.h>
#include<tools.h>
-#include<time.h>
/*PROTOTYPE*/
void outPortByte( unsigned short address, unsigned char value );
char cmd[100]={0};
struct MEMMAN *memman=(struct MEMMAN*)MEMMAN_ADDR;
multiboot_info_t *mbi;
- int aaa;
+
mbi = (multiboot_info_t *) addr;
vga_text_init();
/*Start Set Main Code*/
printVersion();
- cr();
+ putchar('\n');
+
+ /*Setting IDT*/
+ printTASK("Setting IDT.....");
+ setupInterruptGate(DEF_IDT_INT_NUM_IRQ1,KeyBoard_Interrupt_asm);//Register Keyboard interrupt handler
+ setupInterruptGate(DEF_IDT_INT_NUM_IRQ0,Timer_Interrupt_asm);//Register Timer interrupt handler
+ idtr.size = NUM_IDT * sizeof( GATE_DESCRIPTOR );
+ idtr.base = ( GATE_DESCRIPTOR *)idt;
+
+ load_idt();
+ printOK("Setting IDT.....");
/*Setting GDT*/
printTASK("Setting GDT.....");
load_gdt();
printOK("Setting GDT.....");
- while(1);
- /*Setting IDT*/
- printTASK("Setting IDT.....");
- setupInterruptGate(DEF_IDT_INT_NUM_IRQ1,KeyBoard_Interrupt_asm);//Register Keyboard interrupt handler
- setupInterruptGate(DEF_IDT_INT_NUM_IRQ0,Timer_Interrupt_asm);//Register Timer interrupt handler
- idtr.size = NUM_IDT * sizeof( GATE_DESCRIPTOR );
- idtr.base = ( GATE_DESCRIPTOR *)idt;
-
- load_idt();
- printOK("Setting IDT.....");
printTASK("Init PIC.....");
-
initPIC();
printOK("Init PIC.....");
printtime();
cr();cr();
- ShowPrompt();getchar();
- scan_str(cmd,sizeof(cmd)/sizeof(cmd[0]));
- printf("SSS-%s",cmd);
- while(1);
- task_switch(memman);
-
do{
- ShowPrompt();
+ ShowPrompt();//puts("\nKernelShell/Root/>");
scan_str(cmd,sizeof(cmd)/sizeof(cmd[0]));
if(strcmp("time",cmd)==0){
putchar('\r');
printtime();
if(kbhit()=='q')break;
- Sleep(50);
+ io_hlt();
+ io_hlt();
+ io_hlt();
+ io_hlt();
+ io_hlt();
}
cr();cr();
}else if(strcmp("cls",cmd)==0 || strcmp("clear",cmd)==0){
ClearScreen();
+ }else if(strcmp("switch",cmd)==0){
+ task_switch(memman);
+
}else{
if(strcmp("exit",cmd)==0)break;
printFAIL("Unknown this command");
cr();
}
-
+ //init_char_arrey(cmd,100);
}while(strcmp(cmd,"exit")!=0);
while(1)io_hlt();
return;
void initPIC( void )
{
-
disable();
outPortByte( PORT_MASTER_PIC_COMMAND, PIC_ICW1 );
outPortByte( PORT_MASTER_PIC_IMR, (~PIC_IMR_MASK_IRQ0) & (~PIC_IMR_MASK_IRQ2 ) );
outPortByte( PORT_SLAVE_PIC_IMR, PIC_IMR_MASK_IRQ_ALL );
- outPortByte( PORT_MASTER_PIC_IMR, ( ~PIC_IMR_MASK_IRQ0 )
+ outPortByte( PORT_MASTER_PIC_IMR, ( ~PIC_IMR_MASK_IRQ0 )
& ( ~PIC_IMR_MASK_IRQ1 ) & ( ~PIC_IMR_MASK_IRQ2 ) );
- outPortByte( PORT_SLAVE_PIC_IMR, PIC_IMR_MASK_IRQ_ALL );
+ outPortByte( PORT_SLAVE_PIC_IMR, PIC_IMR_MASK_IRQ_ALL );
- enable();/*
- io_out8(PIC0_IMR,0xff);
- io_out8(PIC1_IMR,0xff);
-
- io_out8(PIC0_ICW1,0x11);
- io_out8(PIC0_ICW2,0x20);
- io_out8(PIC0_ICW3,1<<2);
- io_out8(PIC0_ICW4,0x01);
-
- io_out8(PIC1_ICW1,0x11);
- io_out8(PIC1_ICW2,0x28);
- io_out8(PIC1_ICW3,2);
- io_out8(PIC1_ICW4,0x01);
-
- io_out8(PIC0_IMR,0xfb);
- io_out8(PIC1_IMR,0xff);*/
- return;
+ enable();
}
int setPitCounter( int freq, unsigned char counter, unsigned char mode )
while(1)io_hlt();
}
+void setupSegmentDescriptor(int num,unsigned short limit,unsigned int base,unsigned short flags)
+{
+ if(num==1 || num==2 || num==3 || num>=NUM_GDT)return;
+ gdt[num].limitLo=limit;
+ gdt[num].baseLo=base & 0xffff;
+ gdt[num].baseMid=(base >> 16) & 0xff;
+ gdt[num].flags=flags;
+ gdt[num].baseHi=(base >> 24) & 0xff;
+}
+
void task_switch(struct MEMMAN* memman)
{
struct tss a,b;
b.ldtr=0;
b.iomap=0x40000000;
- setupSegmentDescriptor(3,103,(int)&a,AR_TSS32);
- setupSegmentDescriptor(4,103,(int)&b,AR_TSS32);
+ setupSegmentDescriptor(3,103,(int)&a,DEF_GDT_CODE_FLAGS);
+ setupSegmentDescriptor(4,103,(int)&b,DEF_GDT_CODE_FLAGS);
int task_b_esp;
task_b_esp=memman_alloc_4k(memman,64*1024)+64*1024;
b.ds=1*8;
b.fs=1*8;
b.gs=1*8;
+ load_tr(3*8);
taskswitch();
}