VaneOSのメインGitリポジトリです。
リビジョン | de6f6ce043b2fd111f02fa1e97f3bfbdd108b28e (tree) |
---|---|
日時 | 2014-11-02 00:09:37 |
作者 | ![]() |
コミッター | vosystems |
Change Task Switch
@@ -46,9 +46,10 @@ SCAN_C=scan.c | ||
46 | 46 | ENV_C=Env.c |
47 | 47 | TOOLS_C=tools.c |
48 | 48 | CMD_C=cmd_shell.c |
49 | +TASK_S=Task.S | |
49 | 50 | |
50 | 51 | #オブジェクト |
51 | -BOOT_OBJ=${BOOT_S:.S=.o} ${BOOT_C:.c=.o} ${VANE_S:.S=.o} ${KEYBOARD_C:.c=.o} ${STDIO_C:.c=.o} ${GDT_IDT_C:.c=.o} ${INTERRUPT_C:.c=.o} ${STRING_C:.c=.o} ${ASM_INTERRUPT_S:.S=.o} ${SCANCODE_C:.c=.o} ${MEMMAN_C:.c=.o} ${FAT_C:.c=.o} ${GRAPHIC_C:.c=.o} ${SYSTEM_C:.c=.o} ${MESSAGE_C:.c=.o} ${TIMER_C:.c=.o} ${TASK_C:.c=.o} ${TIME_C:.c=.o} ${SCAN_C:.c=.o} ${ENV_C:.c=.o} ${TOOLS_C:.c=.o} ${CMD_C:.c=.o} | |
52 | +BOOT_OBJ=${BOOT_S:.S=.o} ${BOOT_C:.c=.o} ${VANE_S:.S=.o} ${KEYBOARD_C:.c=.o} ${STDIO_C:.c=.o} ${GDT_IDT_C:.c=.o} ${INTERRUPT_C:.c=.o} ${STRING_C:.c=.o} ${ASM_INTERRUPT_S:.S=.o} ${SCANCODE_C:.c=.o} ${MEMMAN_C:.c=.o} ${FAT_C:.c=.o} ${GRAPHIC_C:.c=.o} ${SYSTEM_C:.c=.o} ${MESSAGE_C:.c=.o} ${TIMER_C:.c=.o} ${TASK_C:.c=.o} ${TIME_C:.c=.o} ${SCAN_C:.c=.o} ${ENV_C:.c=.o} ${TOOLS_C:.c=.o} ${CMD_C:.c=.o} ${TASK_S:.S=.o} | |
52 | 53 | |
53 | 54 | kernel: ${BOOT_OBJ} |
54 | 55 | ${LD} ${TARGET} ${BOOT_OBJ} |
@@ -0,0 +1,97 @@ | ||
1 | +.file "Task.S" | |
2 | +.code32 | |
3 | +.text | |
4 | +.intel_syntax noprefix | |
5 | + | |
6 | +.global task_switch,switch_task,switch_task_2,toswitch | |
7 | + | |
8 | +task_switch: | |
9 | + ljmp 5*8:0x0 | |
10 | + RET | |
11 | + | |
12 | + | |
13 | +# switch_task( src, dst ) | |
14 | +switch_task: | |
15 | + pushad | |
16 | + mov ebx, [esp+36] # src | |
17 | + | |
18 | + # Copy to previous task. | |
19 | + mov eax, [esp+32] | |
20 | + mov [ebx+40], eax # eax | |
21 | + mov eax, [esp+28] | |
22 | + mov [ebx+44], eax # ecx | |
23 | + mov eax, [esp+24] | |
24 | + mov [ebx+48], eax # edx | |
25 | + mov eax, [esp+20] | |
26 | + mov [ebx+52], eax # ebx | |
27 | + mov eax, [esp+16] | |
28 | + mov [ebx+56], eax # esp | |
29 | + mov eax, [esp+12] | |
30 | + mov [ebx+60], eax # ebp | |
31 | + mov eax, [esp+8] | |
32 | + mov [ebx+64], eax # esi | |
33 | + mov eax, [esp+4] | |
34 | + mov [ebx+68], eax # edi | |
35 | + mov [ebx+72], es # es | |
36 | + mov [ebx+76], cs # cs | |
37 | + mov [ebx+80], ss # ss | |
38 | + mov [ebx+84], ds # ds | |
39 | + mov [ebx+88], fs # fs | |
40 | + mov [ebx+92], gs # gs | |
41 | + | |
42 | + popad | |
43 | + | |
44 | + # Move to destination task. | |
45 | + mov ebx, [esp+8] | |
46 | + mov ecx, [ebx+44] # ecx | |
47 | + mov edx, [ebx+48] # edx | |
48 | + mov esp, [ebx+56] # esp | |
49 | + mov ebp, [ebx+60] # ebp | |
50 | + mov esi, [ebx+64] # esi | |
51 | + mov edi, [ebx+68] # edi | |
52 | + mov fs, [ebx+88] # fs | |
53 | + mov gs, [ebx+92] # gs | |
54 | + mov eax, [ebx+40] # eax | |
55 | + | |
56 | + push [ebx+80] # push ss | |
57 | + push [ebx+56] # push esp | |
58 | + push [ebx+36] # push eflags | |
59 | + push [ebx+76] # push cs | |
60 | + push [ebx+32] # push eip | |
61 | + push [ebx+52] # push ebx | |
62 | + mov es, [ebx+72] # es | |
63 | + mov ds, [ebx+84] # ds | |
64 | + pop ebx | |
65 | + iretd | |
66 | +back: | |
67 | + ret | |
68 | + | |
69 | +switch_task_2: | |
70 | + # Save | |
71 | + pushad | |
72 | + pushfd | |
73 | + mov eax, cs | |
74 | + push eax | |
75 | + mov eax, ss | |
76 | + push eax | |
77 | + mov ebx, [esp+48] | |
78 | + | |
79 | + mov [ebx+56], esp # ESP | |
80 | +.att_syntax noprefix | |
81 | + movl $toswitch, %eax# 0x435 | |
82 | +.intel_syntax noprefix | |
83 | + sub eax, 0x280000 | |
84 | +# hlt | |
85 | + mov [ebx+32], eax # EIP | |
86 | + # Restore | |
87 | + mov ebx, [esp+52] | |
88 | + mov esp, [ebx+56] | |
89 | + jmp [ebx+32] | |
90 | + | |
91 | +toswitch: | |
92 | + pop eax | |
93 | + mov ss, eax | |
94 | + pop eax | |
95 | + popfd | |
96 | + popad | |
97 | + ret |
@@ -7,11 +7,7 @@ | ||
7 | 7 | .global io_hlt,io_cli,io_sti,io_stihlt |
8 | 8 | .global io_in8,io_in16,io_in32,io_out8,io_out16,io_out32 |
9 | 9 | .global io_load_eflags,io_store_eflags,load_cr0,store_cr0,load_tr |
10 | -.global farjmp,taskswitch | |
11 | - | |
12 | -taskswitch: | |
13 | - JMP 4*8:0 | |
14 | - RET | |
10 | +.global farjmp | |
15 | 11 | |
16 | 12 | farjmp: |
17 | 13 | JMP FAR [ESP+4] |
@@ -27,6 +27,8 @@ | ||
27 | 27 | #include<System.h> |
28 | 28 | #include<Env.h> |
29 | 29 | #include<tools.h> |
30 | +#include<cmd.h> | |
31 | +#include<task.h> | |
30 | 32 | |
31 | 33 | /*PROTOTYPE*/ |
32 | 34 | void outPortByte( unsigned short address, unsigned char value ); |
@@ -37,6 +39,8 @@ void initPit( void ); | ||
37 | 39 | void clear_state(void); |
38 | 40 | void hlt(void); |
39 | 41 | |
42 | +unsigned char stack[ 2 ][ 2048 ]; | |
43 | + | |
40 | 44 | /*! |
41 | 45 | load.S call this function |
42 | 46 |
@@ -50,7 +54,7 @@ void cstart(unsigned long magic, unsigned long addr) | ||
50 | 54 | { |
51 | 55 | /*Common Settings*/ |
52 | 56 | char cmd[100]={0}; |
53 | - struct MEMMAN *memman=(struct MEMMAN*)MEMMAN_ADDR; | |
57 | + memmgr *memman=(memmgr*)MEMMAN_ADDR; | |
54 | 58 | multiboot_info_t *mbi; |
55 | 59 | |
56 | 60 | mbi = (multiboot_info_t *) addr; |
@@ -122,9 +126,9 @@ void cstart(unsigned long magic, unsigned long addr) | ||
122 | 126 | printOK("Init PIT....."); |
123 | 127 | |
124 | 128 | printTASK("Starting Memory Manager....."); |
125 | - memman_init(memman); | |
126 | - memman_free(memman,0x00001000,0x0009e000); | |
127 | - memman_free(memman,0x00400000,((mbi->mem_lower+mbi->mem_upper)*1024)-0x00400000); | |
129 | + k_minit(memman); | |
130 | + k_mfree_src(memman,0x00001000,0x0009e000); | |
131 | + k_mfree_src(memman,0x00400000,((mbi->mem_lower+mbi->mem_upper)*1024)-0x00400000); | |
128 | 132 | printOK("Starting Memory Manager....."); |
129 | 133 | |
130 | 134 | printTASK("Loading Memory Info....."); |
@@ -136,12 +140,16 @@ void cstart(unsigned long magic, unsigned long addr) | ||
136 | 140 | printINFO("TotalMemory = "); |
137 | 141 | printf("%d MiB\n",(mbi->mem_lower+mbi->mem_upper+1024)/1024); |
138 | 142 | printINFO("Free Memory = "); |
139 | - printf("%d MiB\n",memman_total(memman)/(1024*1024)); | |
143 | + printf("%d MiB\n",k_mtotal(memman)/(1024*1024)); | |
140 | 144 | } |
141 | 145 | printINFO("Boot Time and Day = "); |
142 | 146 | printtime(); |
143 | 147 | cr();cr(); |
144 | 148 | |
149 | + ChangeDir("VaneRoot/"); | |
150 | + | |
151 | + init_task(); | |
152 | + | |
145 | 153 | do{ |
146 | 154 | ShowPrompt();//puts("\nKernelShell/Root/>"); |
147 | 155 | scan_str(cmd,sizeof(cmd)/sizeof(cmd[0])); |
@@ -152,11 +160,7 @@ void cstart(unsigned long magic, unsigned long addr) | ||
152 | 160 | putchar('\r'); |
153 | 161 | printtime(); |
154 | 162 | if(kbhit()=='q')break; |
155 | - io_hlt(); | |
156 | - io_hlt(); | |
157 | - io_hlt(); | |
158 | - io_hlt(); | |
159 | - io_hlt(); | |
163 | + Sleep(100); | |
160 | 164 | } |
161 | 165 | cr();cr(); |
162 | 166 |
@@ -176,7 +180,19 @@ void cstart(unsigned long magic, unsigned long addr) | ||
176 | 180 | ClearScreen(); |
177 | 181 | |
178 | 182 | }else if(strcmp("switch",cmd)==0){ |
179 | - task_switch(memman); | |
183 | + //task_switch(memman); | |
184 | + k_mktask( 1, task_a,memman); | |
185 | + k_mktask( 2, task_b,memman); | |
186 | + switch_task_2( TASK_INFO_ADDR, TASK_INFO_ADDR + sizeof( TaskInfo ) ); | |
187 | + | |
188 | + }else if(strcmp("root",cmd)==0){ | |
189 | + if(admin_flag==0){ | |
190 | + admin_flag=1; | |
191 | + | |
192 | + }else{ | |
193 | + admin_flag=0; | |
194 | + | |
195 | + } | |
180 | 196 | |
181 | 197 | }else{ |
182 | 198 | if(strcmp("exit",cmd)==0)break; |
@@ -184,7 +200,6 @@ void cstart(unsigned long magic, unsigned long addr) | ||
184 | 200 | cr(); |
185 | 201 | |
186 | 202 | } |
187 | - //init_char_arrey(cmd,100); | |
188 | 203 | }while(strcmp(cmd,"exit")!=0); |
189 | 204 | while(1)io_hlt(); |
190 | 205 | return; |
@@ -6,12 +6,25 @@ | ||
6 | 6 | #include<stdio.h> |
7 | 7 | #include<Env.h> |
8 | 8 | |
9 | +char dir[1000]; | |
10 | + | |
9 | 11 | inline void ShowPrompt(void) |
10 | 12 | { |
11 | - printf("%s@%s: ~",env.USER_NAME, env.PC_NAME); | |
12 | - if(admin_flag==1){ | |
13 | - printf("# "); | |
13 | + char uname[32]={0}; | |
14 | + | |
15 | + if(admin_flag==0){ | |
16 | + putchar('%'); | |
17 | + strcpy(uname,env.USER_NAME); | |
18 | + | |
14 | 19 | }else{ |
15 | - printf("$ "); | |
20 | + putchar('#'); | |
21 | + strcpy(uname,"Root"); | |
22 | + | |
16 | 23 | } |
24 | + printf("-%s/%s/%s>",uname, env.PC_NAME, dir); | |
25 | +} | |
26 | + | |
27 | +inline void ChangeDir(const char* dirname) | |
28 | +{ | |
29 | + strcpy(dir,dirname); | |
17 | 30 | } |
@@ -0,0 +1,32 @@ | ||
1 | +/* | |
2 | +*libgcc functions. | |
3 | +*(C) 2014 VOSystems. | |
4 | +*/ | |
5 | + | |
6 | +#include<VaneOS.h> | |
7 | +#include<type.h> | |
8 | + | |
9 | +quad_t __divdi3(quad_t a,quad_t b) | |
10 | +{ | |
11 | + u_quad_t ua,ub,uq; | |
12 | + int neg; | |
13 | + | |
14 | + if(a<0){ | |
15 | + ua= -(u_quad_t)a; | |
16 | + neg=1; | |
17 | + | |
18 | + }else{ | |
19 | + ua=a; | |
20 | + neg=0; | |
21 | + } | |
22 | + | |
23 | + if(b<0){ | |
24 | + ub= -(u_quad_t)b; | |
25 | + neg^=1; | |
26 | + }else{ | |
27 | + ub=b; | |
28 | + } | |
29 | + | |
30 | + uq=__qdivrem(ua,ub,(u_quad_t*)0); | |
31 | + return(neg ? -uq : uq); | |
32 | +} |
@@ -1,6 +1,20 @@ | ||
1 | 1 | #include<memory.h> |
2 | 2 | |
3 | -void memman_init(struct MEMMAN *man) | |
3 | +void memset( void* p, int val, int size ) | |
4 | +{ | |
5 | + int i = 0; | |
6 | + char* pp = p; | |
7 | + for( i = 0; i < size; ++i, ++pp ){ | |
8 | + *pp = val; | |
9 | + } | |
10 | +} | |
11 | + | |
12 | +void zero_memory( void* p, int size ) | |
13 | +{ | |
14 | + memset( p, 0, size ); | |
15 | +} | |
16 | + | |
17 | +void k_minit(memmgr *man) | |
4 | 18 | { |
5 | 19 | man->frees=0; |
6 | 20 | man->maxfrees=0; |
@@ -10,7 +24,7 @@ void memman_init(struct MEMMAN *man) | ||
10 | 24 | return; |
11 | 25 | } |
12 | 26 | |
13 | -unsigned int memman_total(struct MEMMAN *man) | |
27 | +unsigned int k_mtotal(memmgr *man) | |
14 | 28 | { |
15 | 29 | unsigned int i,t=0; |
16 | 30 | for(i=0;i<man->frees;i++) |
@@ -20,7 +34,7 @@ unsigned int memman_total(struct MEMMAN *man) | ||
20 | 34 | return t; |
21 | 35 | } |
22 | 36 | |
23 | -unsigned int memman_alloc(struct MEMMAN *man,unsigned int size) | |
37 | +unsigned int k_malloc_src(memmgr *man,unsigned int size) | |
24 | 38 | { |
25 | 39 | unsigned int i,a; |
26 | 40 | for(i=0;i<man->frees;i++) |
@@ -44,7 +58,7 @@ unsigned int memman_alloc(struct MEMMAN *man,unsigned int size) | ||
44 | 58 | return 0; |
45 | 59 | } |
46 | 60 | |
47 | -int memman_free(struct MEMMAN *man,unsigned int addr,unsigned int size) | |
61 | +int k_mfree_src(memmgr *man,unsigned int addr,unsigned int size) | |
48 | 62 | { |
49 | 63 | int i,j; |
50 | 64 | for(i=0;i<man->frees;i++) |
@@ -106,18 +120,18 @@ int memman_free(struct MEMMAN *man,unsigned int addr,unsigned int size) | ||
106 | 120 | return -1;/*FAIL*/ |
107 | 121 | } |
108 | 122 | |
109 | -unsigned int memman_alloc_4k(struct MEMMAN* man,unsigned int size) | |
123 | +unsigned int k_malloc(memmgr* man,unsigned int size) | |
110 | 124 | { |
111 | 125 | unsigned int a; |
112 | 126 | size=(size+0xfff) & 0xfffff0000; |
113 | - a=memman_alloc(man,size); | |
127 | + a=k_malloc_src(man,size); | |
114 | 128 | return a; |
115 | 129 | } |
116 | 130 | |
117 | -int memman_free_4k(struct MEMMAN* man,unsigned int addr,unsigned int size) | |
131 | +int k_mfree(memmgr* man,unsigned int addr,unsigned int size) | |
118 | 132 | { |
119 | 133 | int i; |
120 | 134 | size=(size+0xfff) & 0xfffff000; |
121 | - i=memman_free(man,addr,size); | |
135 | + i=k_mfree_src(man,addr,size); | |
122 | 136 | return i; |
123 | 137 | } |
@@ -126,6 +126,12 @@ char* scan_str(char* in,size_t lengh) | ||
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
129 | + if(count+1 > lengh){ | |
130 | + putchar('\n'); | |
131 | + *p='\0'; | |
132 | + break; | |
133 | + | |
134 | + } | |
129 | 135 | } |
130 | 136 | return in; |
131 | 137 | } |
@@ -9,53 +9,79 @@ | ||
9 | 9 | #include<timer.h> |
10 | 10 | #include<memory.h> |
11 | 11 | #include<GDT_IDT.h> |
12 | +#include<tools.h> | |
12 | 13 | |
13 | -void task_b_main(void) | |
14 | + | |
15 | +unsigned int esp_addr[TASK_INFO_TOTAL]; | |
16 | + | |
17 | +void task_a() | |
14 | 18 | { |
15 | - printf("TASKB"); | |
16 | - while(1)io_hlt(); | |
19 | +// asm_halt(); | |
20 | + int a = 0; | |
21 | + printf("task a : %d", a ); | |
22 | + | |
23 | + switch_task_2( TASK_INFO_ADDR + sizeof( TaskInfo ), TASK_INFO_ADDR + sizeof( TaskInfo ) * 2 ); | |
24 | + for( ; ; ){ | |
25 | + ++a; | |
26 | + if( a % 10 == 0 ){ | |
27 | + switch_task_2( TASK_INFO_ADDR + sizeof( TaskInfo ), TASK_INFO_ADDR + sizeof( TaskInfo ) * 2 ); | |
28 | + } | |
29 | + printf("task a : %d", a ); | |
30 | + } | |
17 | 31 | } |
18 | 32 | |
19 | -void setupSegmentDescriptor(int num,unsigned short limit,unsigned int base,unsigned short flags) | |
33 | +void task_b() | |
20 | 34 | { |
21 | - if(num==1 || num==2 || num==3 || num>=NUM_GDT)return; | |
22 | - gdt[num].limitLo=limit; | |
23 | - gdt[num].baseLo=base & 0xffff; | |
24 | - gdt[num].baseMid=(base >> 16) & 0xff; | |
25 | - gdt[num].flags=flags; | |
26 | - gdt[num].baseHi=(base >> 24) & 0xff; | |
35 | + int b = 0; | |
36 | + printf("task b : %d", b ); | |
37 | + //asm_halt(); | |
38 | + switch_task_2( TASK_INFO_ADDR + sizeof( TaskInfo ) * 2, TASK_INFO_ADDR + sizeof( TaskInfo ) ); | |
39 | + for( ; ; ){ | |
40 | + ++b; | |
41 | + if( b % 10 == 0 ){ | |
42 | + switch_task_2( TASK_INFO_ADDR + sizeof( TaskInfo ) * 2, TASK_INFO_ADDR /*+ sizeof( TaskInfo )*/ ); | |
43 | + } | |
44 | + printf("task b : %d", b ); | |
45 | + } | |
27 | 46 | } |
28 | 47 | |
29 | -void task_switch(struct MEMMAN* memman) | |
48 | +void init_task() | |
30 | 49 | { |
31 | - struct tss a,b; | |
32 | - a.ldtr=0; | |
33 | - a.iomap=0x40000000; | |
34 | - b.ldtr=0; | |
35 | - b.iomap=0x40000000; | |
36 | - | |
37 | - setupSegmentDescriptor(3,103,(int)&a,DEF_GDT_CODE_FLAGS); | |
38 | - setupSegmentDescriptor(4,103,(int)&b,DEF_GDT_CODE_FLAGS); | |
50 | + unsigned int* cur_task = (unsigned int*)CUR_TASK_NUM_ADDR; | |
51 | + TaskInfo* t = (TaskInfo*)TASK_INFO_ADDR; | |
52 | + int i = 0; | |
39 | 53 | |
40 | - int task_b_esp; | |
41 | - task_b_esp=memman_alloc_4k(memman,64*1024)+64*1024; | |
42 | - | |
43 | - b.eip=(int)&task_b_main; | |
44 | - b.eflags=0x00000202; | |
45 | - b.eax=0; | |
46 | - b.ebx=0; | |
47 | - b.ecx=0; | |
48 | - b.edx=0; | |
49 | - b.esp=task_b_esp; | |
50 | - b.ebp=0; | |
51 | - b.esi=0; | |
52 | - b.edi=0; | |
53 | - b.es=1*8; | |
54 | - b.cs=2*8; | |
55 | - b.ss=1*8; | |
56 | - b.ds=1*8; | |
57 | - b.fs=1*8; | |
58 | - b.gs=1*8; | |
59 | - load_tr(3*8); | |
60 | - taskswitch(); | |
54 | + *cur_task = 0; | |
55 | + for( i = 0; i < TASK_INFO_TOTAL; ++i ){ | |
56 | + zero_memory( t + i, sizeof( TaskInfo ) ); | |
57 | + } | |
58 | +} | |
59 | + | |
60 | +void k_mktask(unsigned task,void (*f)(),memmgr *memman) | |
61 | +{ | |
62 | + int free=int_linear_search(esp_addr[512],0); | |
63 | + esp_addr[free]=k_malloc(memman,1); | |
64 | + set_task(task,f,esp_addr[free]); | |
65 | +} | |
66 | + | |
67 | +void set_task( unsigned int task, void (*f)(), unsigned char* esp ) | |
68 | +{ | |
69 | + TaskInfo* t = (TaskInfo*)TASK_INFO_ADDR; | |
70 | + if( task > TASK_INFO_TOTAL ){ | |
71 | + return; | |
72 | + } | |
73 | + t += task; | |
74 | + zero_memory( t, sizeof( TaskInfo ) ); | |
75 | + t->cs = 0x18; | |
76 | + t->ds = t->fs = t->gs = t->es = 0x10; | |
77 | + t->ss = 0x10; | |
78 | + t->eip = -0x280000 + (unsigned int) f; | |
79 | + t->esp = (unsigned int) esp; | |
80 | + t->eflags = 0x00000202; | |
81 | +} | |
82 | + | |
83 | +unsigned int get_cur_task_num() | |
84 | +{ | |
85 | + unsigned int* cur_task = (unsigned int*)CUR_TASK_NUM_ADDR; | |
86 | + return *cur_task; | |
61 | 87 | } |
@@ -16,3 +16,14 @@ inline void Sleep(DWORD milisec) | ||
16 | 16 | DWORD sec; |
17 | 17 | for(sec=0;sec<=milisec;sec+=10)io_hlt(); |
18 | 18 | } |
19 | + | |
20 | +inline int int_linear_search(int ser[],int search_num) | |
21 | +{ | |
22 | + size_t size=sizeof(ser)/sizeof(ser[0]); | |
23 | + unsigned int i=0; | |
24 | + while(i<size){ | |
25 | + if(ser[i]==search_num)return i; | |
26 | + i++; | |
27 | + } | |
28 | + return -1; | |
29 | +} |
@@ -8,6 +8,8 @@ | ||
8 | 8 | #ifndef VANEOS_H |
9 | 9 | #define VANEOS_H |
10 | 10 | |
11 | +#include<type.h> | |
12 | + | |
11 | 13 | #define local static |
12 | 14 | #define DEBUG while(getchar()!='\n') |
13 | 15 | void write_mem_8(int,int); |
@@ -33,6 +35,12 @@ void init_all(void); | ||
33 | 35 | int getmsg(int msg_num); |
34 | 36 | void sendmsg(int msg,int msg_num); |
35 | 37 | |
38 | +/*Task.S*/ | |
39 | +void task_switch(void); | |
40 | +void switch_task(int src,int dst); | |
41 | +void switch_task_2(int src,int dst); | |
42 | +void toswitch(int eax); | |
43 | + | |
36 | 44 | #define cr() putchar('\n'); |
37 | 45 | |
38 | 46 | #define COL8_000000 0 |
@@ -53,21 +61,6 @@ void sendmsg(int msg,int msg_num); | ||
53 | 61 | #define COL8_848484 15 |
54 | 62 | |
55 | 63 | /*DEFINE COMMON*/ |
56 | -typedef unsigned char BYTE; | |
57 | -typedef unsigned int WORD; | |
58 | -typedef unsigned long long DWORD; | |
59 | - | |
60 | -typedef long long int64_t; | |
61 | -typedef int int32_t; | |
62 | -typedef short int16_t; | |
63 | -typedef char int8_t; | |
64 | - | |
65 | -typedef unsigned long long uint64_t; | |
66 | -typedef unsigned int uint32_t; | |
67 | -typedef unsigned short uint16_t; | |
68 | -typedef unsigned char uint8_t; | |
69 | -typedef unsigned long size_t; | |
70 | - | |
71 | 64 | #define ADR_BOOTINFO 0x00000ff0 |
72 | 65 | #define ADR_DISKIMG 0x00100000 |
73 | 66 | #define FAT_DISK_PLASE 0x00020000 |
@@ -8,6 +8,8 @@ | ||
8 | 8 | #ifndef VANEOS_H |
9 | 9 | #define VANEOS_H |
10 | 10 | |
11 | +#include<type.h> | |
12 | + | |
11 | 13 | #define local static |
12 | 14 | #define DEBUG while(getchar()!='\n') |
13 | 15 | void write_mem_8(int,int); |
@@ -33,6 +35,12 @@ void init_all(void); | ||
33 | 35 | int getmsg(int msg_num); |
34 | 36 | void sendmsg(int msg,int msg_num); |
35 | 37 | |
38 | +/*Task.S*/ | |
39 | +void task_switch(void); | |
40 | +void switch_task(int src,int dst); | |
41 | +void switch_task_2(); | |
42 | +void toswitch(int eax); | |
43 | + | |
36 | 44 | #define cr() putchar('\n'); |
37 | 45 | |
38 | 46 | #define COL8_000000 0 |
@@ -53,21 +61,6 @@ void sendmsg(int msg,int msg_num); | ||
53 | 61 | #define COL8_848484 15 |
54 | 62 | |
55 | 63 | /*DEFINE COMMON*/ |
56 | -typedef unsigned char BYTE; | |
57 | -typedef unsigned short WORD; | |
58 | -typedef unsigned long DWORD; | |
59 | - | |
60 | -typedef long long int64_t; | |
61 | -typedef int int32_t; | |
62 | -typedef short int16_t; | |
63 | -typedef char int8_t; | |
64 | - | |
65 | -typedef unsigned long long uint64_t; | |
66 | -typedef unsigned int uint32_t; | |
67 | -typedef unsigned short uint16_t; | |
68 | -typedef unsigned char uint8_t; | |
69 | -typedef unsigned long size_t; | |
70 | - | |
71 | 64 | #define ADR_BOOTINFO 0x00000ff0 |
72 | 65 | #define ADR_DISKIMG 0x00100000 |
73 | 66 | #define FAT_DISK_PLASE 0x00020000 |
@@ -7,5 +7,6 @@ | ||
7 | 7 | #define _CMD_H_VANE_ |
8 | 8 | |
9 | 9 | void ShowPrompt(void); |
10 | +void ChangeDir(const char*); | |
10 | 11 | |
11 | 12 | #endif |
@@ -0,0 +1,11 @@ | ||
1 | +/* | |
2 | +*cmd shell header. | |
3 | +*(C) 2014 VOSystems. | |
4 | +*/ | |
5 | + | |
6 | +#ifndef _CMD_H_VANE_ | |
7 | +#define _CMD_H_VANE_ | |
8 | + | |
9 | +void ShowPrompt(void); | |
10 | + | |
11 | +#endif |
@@ -1,5 +1,6 @@ | ||
1 | 1 | /* |
2 | - | |
2 | +*memory mgr | |
3 | +*(C) 2014 VOSystems. | |
3 | 4 | */ |
4 | 5 | |
5 | 6 | #ifndef _MEMORY_H_VANE_ |
@@ -12,16 +13,20 @@ struct FREEINFO | ||
12 | 13 | unsigned int addr,size; |
13 | 14 | }; |
14 | 15 | |
15 | -struct MEMMAN | |
16 | +typedef struct | |
16 | 17 | { |
17 | 18 | int frees,maxfrees,lostsize,losts; |
18 | 19 | struct FREEINFO free[MEMMAN_FREES]; |
19 | -}; | |
20 | +}memmgr; | |
21 | + | |
22 | +void k_minit(memmgr *man); | |
23 | +unsigned int k_mtotal(memmgr *man); | |
24 | +unsigned int k_malloc_src(memmgr *man,unsigned int size); | |
25 | +int k_mfree_src(memmgr *man,unsigned int addr,unsigned int size); | |
26 | +unsigned int k_malloc(memmgr* man,unsigned int size); | |
27 | +int k_mfree(memmgr* man,unsigned int addr,unsigned int size); | |
28 | + | |
29 | +void memset( void* p, int val, int size ); | |
30 | +void zero_memory( void* p, int size ); | |
20 | 31 | |
21 | -void memman_init(struct MEMMAN *man); | |
22 | -unsigned int memman_total(struct MEMMAN *man); | |
23 | -unsigned int memman_alloc(struct MEMMAN *man,unsigned int size); | |
24 | -int memman_free(struct MEMMAN *man,unsigned int addr,unsigned int size); | |
25 | -unsigned int memman_alloc_4k(struct MEMMAN* man,unsigned int size); | |
26 | -int memman_free_4k(struct MEMMAN* man,unsigned int addr,unsigned int size); | |
27 | 32 | #endif |
@@ -0,0 +1,32 @@ | ||
1 | +/* | |
2 | +*memory mgr | |
3 | +*(C) 2014 VOSystems. | |
4 | +*/ | |
5 | + | |
6 | +#ifndef _MEMORY_H_VANE_ | |
7 | +#define _MEMORY_H_VANE_ | |
8 | + | |
9 | +#define MEMMAN_FREES 4090 | |
10 | +#define MEMMAN_ADDR 0x003c0000 | |
11 | +struct FREEINFO | |
12 | +{ | |
13 | + unsigned int addr,size; | |
14 | +}; | |
15 | + | |
16 | +typedef struct | |
17 | +{ | |
18 | + int frees,maxfrees,lostsize,losts; | |
19 | + struct FREEINFO free[MEMMAN_FREES]; | |
20 | +}memmgr; | |
21 | + | |
22 | +void k_minit(memmgr *man); | |
23 | +unsigned int memman_total(memmgr *man); | |
24 | +unsigned int k_malloc_src(memmgr *man,unsigned int size); | |
25 | +int k_mfree_src(memmgr *man,unsigned int addr,unsigned int size); | |
26 | +unsigned int k_malloc(memmgr* man,unsigned int size); | |
27 | +int k_mfree(memmgr* man,unsigned int addr,unsigned int size); | |
28 | + | |
29 | +void memset( void* p, int val, int size ); | |
30 | +void zero_memory( void* p, int size ); | |
31 | + | |
32 | +#endif |
@@ -6,51 +6,78 @@ | ||
6 | 6 | #ifndef _TASK_H_VANE_ |
7 | 7 | #define _TASK_H_VANE_ |
8 | 8 | |
9 | -#include<Message.h> | |
10 | -#include<GDT_IDT.h> | |
11 | -#include<memory.h> | |
12 | - | |
13 | -#define MAX_TASKS 1000 | |
14 | -#define TASK_GDT0 3 | |
15 | -#define MAX_TASKS_LV 100 | |
16 | -#define MAX_TASKLEVELS 10 | |
17 | -#define ADR_GDT 0x00270000 | |
18 | -#define AR_TSS32 0x0089 | |
19 | -#define AR_LDT 0x0082 | |
20 | - | |
21 | -void task_switch(struct MEMMAN* memman); | |
22 | - | |
23 | -struct tss { | |
24 | - int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3; | |
25 | - int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi; | |
26 | - int es, cs, ss, ds, fs, gs; | |
27 | - int ldtr, iomap; | |
28 | -}; | |
29 | - | |
30 | -struct TASK { | |
31 | - int sel, flags; | |
32 | - int level, priority; | |
33 | - struct msg_data fifo; | |
34 | - struct tss tss; | |
35 | - SEGMENT_DESCRIPTOR ldt[2]; | |
36 | - struct CONSOLE *cons; | |
37 | - int ds_base, cons_stack; | |
38 | - //struct FILEHANDLE *fhandle; | |
39 | - int *fat; | |
40 | - char *cmdline; | |
41 | - unsigned char langmode, langbyte1; | |
42 | -}; | |
43 | - | |
44 | -struct TASKLEVEL { | |
45 | - int running; | |
46 | - int now; | |
47 | - struct TASK *tasks[MAX_TASKS_LV]; | |
48 | -}; | |
49 | - | |
50 | -struct TASKCTL { | |
51 | - int now_lv; | |
52 | - char lv_change; | |
53 | - struct TASKLEVEL level[MAX_TASKLEVELS]; | |
54 | - struct TASK tasks0[MAX_TASKS]; | |
55 | -}; | |
9 | +#define CUR_TASK_NUM_ADDR 0x25ff00 // Current task number | |
10 | +#define TASK_INFO_ADDR 0x260000 // Address to the head of TaskInfo structure. | |
11 | +#define TASK_INFO_TOTAL 10 // Number of tasks. | |
12 | + | |
13 | +/*Status Label*/ | |
14 | +#define NORMAL 0x00000000 //Normal | |
15 | +#define EXCEPT 0x00000001 //Exception | |
16 | +#define ABNRML 0x00000002 //Abnormal | |
17 | +#define BADTCH 0x00000003 //Bad memory address touch | |
18 | + | |
19 | +/*Run Level Label*/ | |
20 | +#define KERNEL 0x00000000 //Kernel Mode (Ling 0) | |
21 | +#define DRIVER 0x00000001 //Driver Mode | |
22 | +#define SHELLS 0x00000002 //Shell Servers Mode | |
23 | +#define APPPAR 0x00000003 //Parent Application | |
24 | +#define APPCHI 0x00000004 //Child Application | |
25 | +#define APPGAB 0x00000005 //Gabage Request Application | |
26 | + | |
27 | +/*Request Label*/ | |
28 | +#define NONERQ 0x00000000 | |
29 | +#define SYSCAL 0x00000001 | |
30 | +#define GABAGE 0x00000002 | |
31 | + | |
32 | +typedef struct | |
33 | +{ | |
34 | + int id; | |
35 | + int status; | |
36 | + int run_level; | |
37 | + int request; | |
38 | + int parent_id | |
39 | +}task_status; | |
40 | + | |
41 | +typedef struct | |
42 | +{ | |
43 | + unsigned int backlink; | |
44 | + unsigned int esp0; // Stack pointer. ( Privilage level 0 ) | |
45 | + unsigned int ss0; // Stack segment. ( Privilage level 0 ) | |
46 | + unsigned int esp1; // Stack pointer. ( Privilage level 1 ) | |
47 | + unsigned int ss1; // Stack segment. ( Privilage level 1 ) | |
48 | + unsigned int esp2; // Stack pointer. ( Privilage level 2 ) | |
49 | + unsigned int ss2; // Stack segment. ( Privilage level 2 ) | |
50 | + unsigned int cr3; // Address table of task. | |
51 | + unsigned int eip; // Instruction pointer. | |
52 | + unsigned int eflags; // E-flags. | |
53 | + unsigned int eax; // EAX register. | |
54 | + unsigned int ecx; // ECX register. | |
55 | + unsigned int edx; // EDX register. | |
56 | + unsigned int ebx; // EBX register. | |
57 | + unsigned int esp; // Stack pointer. | |
58 | + unsigned int ebp; | |
59 | + unsigned int esi; | |
60 | + unsigned int edi; | |
61 | + unsigned int es; | |
62 | + unsigned int cs; | |
63 | + unsigned int ss; | |
64 | + unsigned int ds; | |
65 | + unsigned int fs; | |
66 | + unsigned int gs; | |
67 | + unsigned int ldtr; | |
68 | + unsigned int iomap; | |
69 | +} TaskInfo; | |
70 | + | |
71 | +void init_task(); | |
72 | +void set_task( unsigned int task, void (*f)(), unsigned char* esp ); | |
73 | +unsigned int get_cur_task_num(); | |
74 | +//void switch_task( unsigned int task ); | |
75 | + | |
76 | +void init_task(); | |
77 | +void set_task( unsigned int task, void (*f)(), unsigned char* esp ); | |
78 | +unsigned int get_cur_task_num(); | |
79 | + | |
80 | +void task_a(); | |
81 | +void task_b(); | |
82 | + | |
56 | 83 | #endif |
@@ -6,50 +6,57 @@ | ||
6 | 6 | #ifndef _TASK_H_VANE_ |
7 | 7 | #define _TASK_H_VANE_ |
8 | 8 | |
9 | -#include<Message.h> | |
10 | -#include<GDT_IDT.h> | |
11 | - | |
12 | -#define MAX_TASKS 1000 | |
13 | -#define TASK_GDT0 3 | |
14 | -#define MAX_TASKS_LV 100 | |
15 | -#define MAX_TASKLEVELS 10 | |
16 | -#define ADR_GDT 0x00270000 | |
17 | -#define AR_TSS32 0x0089 | |
18 | -#define AR_LDT 0x0082 | |
19 | - | |
20 | -void task_switch(struct MEMMAN* memman); | |
21 | - | |
22 | -struct tss { | |
23 | - int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3; | |
24 | - int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi; | |
25 | - int es, cs, ss, ds, fs, gs; | |
26 | - int ldtr, iomap; | |
27 | -}; | |
28 | - | |
29 | -struct TASK { | |
30 | - int sel, flags; | |
31 | - int level, priority; | |
32 | - struct msg_data fifo; | |
33 | - struct tss tss; | |
34 | - SEGMENT_DESCRIPTOR ldt[2]; | |
35 | - struct CONSOLE *cons; | |
36 | - int ds_base, cons_stack; | |
37 | - //struct FILEHANDLE *fhandle; | |
38 | - int *fat; | |
39 | - char *cmdline; | |
40 | - unsigned char langmode, langbyte1; | |
41 | -}; | |
42 | - | |
43 | -struct TASKLEVEL { | |
44 | - int running; | |
45 | - int now; | |
46 | - struct TASK *tasks[MAX_TASKS_LV]; | |
47 | -}; | |
48 | - | |
49 | -struct TASKCTL { | |
50 | - int now_lv; | |
51 | - char lv_change; | |
52 | - struct TASKLEVEL level[MAX_TASKLEVELS]; | |
53 | - struct TASK tasks0[MAX_TASKS]; | |
54 | -}; | |
9 | +#define CUR_TASK_NUM_ADDR 0x25ff00 // Current task number | |
10 | +#define TASK_INFO_ADDR 0x260000 // Address to the head of TaskInfo structure. | |
11 | +#define TASK_INFO_TOTAL 10 // Number of tasks. | |
12 | + | |
13 | +typedef struct | |
14 | +{ | |
15 | + int status; | |
16 | + int run_level; | |
17 | + int request; | |
18 | +}task_status; | |
19 | + | |
20 | +typedef struct | |
21 | +{ | |
22 | + unsigned int backlink; | |
23 | + unsigned int esp0; // Stack pointer. ( Privilage level 0 ) | |
24 | + unsigned int ss0; // Stack segment. ( Privilage level 0 ) | |
25 | + unsigned int esp1; // Stack pointer. ( Privilage level 1 ) | |
26 | + unsigned int ss1; // Stack segment. ( Privilage level 1 ) | |
27 | + unsigned int esp2; // Stack pointer. ( Privilage level 2 ) | |
28 | + unsigned int ss2; // Stack segment. ( Privilage level 2 ) | |
29 | + unsigned int cr3; // Address table of task. | |
30 | + unsigned int eip; // Instruction pointer. | |
31 | + unsigned int eflags; // E-flags. | |
32 | + unsigned int eax; // EAX register. | |
33 | + unsigned int ecx; // ECX register. | |
34 | + unsigned int edx; // EDX register. | |
35 | + unsigned int ebx; // EBX register. | |
36 | + unsigned int esp; // Stack pointer. | |
37 | + unsigned int ebp; | |
38 | + unsigned int esi; | |
39 | + unsigned int edi; | |
40 | + unsigned int es; | |
41 | + unsigned int cs; | |
42 | + unsigned int ss; | |
43 | + unsigned int ds; | |
44 | + unsigned int fs; | |
45 | + unsigned int gs; | |
46 | + unsigned int ldtr; | |
47 | + unsigned int iomap; | |
48 | +} TaskInfo; | |
49 | + | |
50 | +void init_task(); | |
51 | +void set_task( unsigned int task, void (*f)(), unsigned char* esp ); | |
52 | +unsigned int get_cur_task_num(); | |
53 | +//void switch_task( unsigned int task ); | |
54 | + | |
55 | +void init_task(); | |
56 | +void set_task( unsigned int task, void (*f)(), unsigned char* esp ); | |
57 | +unsigned int get_cur_task_num(); | |
58 | + | |
59 | +void task_a(); | |
60 | +void task_b(); | |
61 | + | |
55 | 62 | #endif |
@@ -6,7 +6,7 @@ | ||
6 | 6 | #ifndef _TIME_H_VANE_ |
7 | 7 | #define _TIME_H_VANE_ |
8 | 8 | |
9 | -typedef unsigned long time_t; | |
9 | +typedef unsigned long long time_t; | |
10 | 10 | |
11 | 11 | struct tm |
12 | 12 | { |
@@ -14,6 +14,8 @@ struct tm | ||
14 | 14 | unsigned long tm_year; |
15 | 15 | }; |
16 | 16 | |
17 | +extern struct tm ttime; | |
18 | + | |
17 | 19 | int hex2dec_bcd(int hex); |
18 | 20 | time_t time(time_t* timer); |
19 | 21 | struct tm* localtime(time_t* timer); |
@@ -10,5 +10,6 @@ | ||
10 | 10 | |
11 | 11 | void init_char_arrey(char* arrey,size_t lengh); |
12 | 12 | void Sleep(DWORD milisec); |
13 | +int int_linear_search(int ser[],int search_num); | |
13 | 14 | |
14 | 15 | #endif |
@@ -9,5 +9,6 @@ | ||
9 | 9 | #include<VaneOS.h> |
10 | 10 | |
11 | 11 | void init_char_arrey(char* arrey,size_t lengh); |
12 | +void Sleep(DWORD milisec); | |
12 | 13 | |
13 | 14 | #endif |
@@ -0,0 +1,27 @@ | ||
1 | +/* | |
2 | +*type defines | |
3 | +*(C) 2014 VOSystems | |
4 | +*/ | |
5 | + | |
6 | +#ifndef _TYPE_H_VANE_ | |
7 | +#define _TYPE_H_VANE_ | |
8 | + | |
9 | +typedef unsigned char BYTE; | |
10 | +typedef unsigned int WORD; | |
11 | +typedef unsigned long long DWORD; | |
12 | + | |
13 | +typedef long long int64_t; | |
14 | +typedef int int32_t; | |
15 | +typedef short int16_t; | |
16 | +typedef char int8_t; | |
17 | + | |
18 | +typedef unsigned long long uint64_t; | |
19 | +typedef unsigned int uint32_t; | |
20 | +typedef unsigned short uint16_t; | |
21 | +typedef unsigned char uint8_t; | |
22 | +typedef unsigned long size_t; | |
23 | + | |
24 | +typedef long long quad_t; | |
25 | +typedef unsigned long long u_quad_t; | |
26 | + | |
27 | +#endif |
@@ -0,0 +1,27 @@ | ||
1 | +/* | |
2 | +*type defines | |
3 | +*(C) 2014 VOSystems | |
4 | +*/ | |
5 | + | |
6 | +#ifndef _TYPE_H_VANE_ | |
7 | +#define _TYPE_H_VANE_ | |
8 | + | |
9 | +typedef unsigned char BYTE; | |
10 | +typedef unsigned int WORD; | |
11 | +typedef unsigned long long DWORD; | |
12 | + | |
13 | +typedef long long int64_t; | |
14 | +typedef int int32_t; | |
15 | +typedef short int16_t; | |
16 | +typedef char int8_t; | |
17 | + | |
18 | +typedef unsigned long long uint64_t; | |
19 | +typedef unsigned int uint32_t; | |
20 | +typedef unsigned short uint16_t; | |
21 | +typedef unsigned char uint8_t; | |
22 | +typedef unsigned long size_t; | |
23 | + | |
24 | +typedef long long quad_t; | |
25 | +typedef unsigned long long uquad_t; | |
26 | + | |
27 | +#endif |