Skip to content

Commit ae84afb

Browse files
implement sys_putchar
1 parent e179014 commit ae84afb

File tree

12 files changed

+134
-13
lines changed

12 files changed

+134
-13
lines changed

include/env.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#define _ENV_H_
33
#include<trapframe.h>
44
#include<queue.h>
5-
#define UTOP 0x7f400000
5+
//#define UTOP 0x7f400000
6+
#define UTOP 0xe0000000
67
#define LOG2NENV 10
78
#define NENV (1<<10)
89
#define USTACKTOP (UTOP - 2*BY2PG)

include/syscall_lib.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _SYSCALL_LIB_H_
2+
#define _SYSCALL_LIB_H_
3+
4+
#define __SYSCALL_BASE 9527
5+
#define __NR_SYSCALLS 20
6+
7+
#define SYS_putchar ((__SYSCALL_BASE ) + (0 ) )
8+
9+
#endif

init/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void main() {
2727
env_create(&(user_mainb),0,1);
2828

2929

30-
enable_irq();
30+
//enable_irq();
3131
enable_interrupt_controller();
3232
timer_init();
3333
printf(">>>timer interrupt started!\n");

lib/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ INCLUDES := -I./ -I../ -I../include/
77

88
.PHONY: clean
99

10-
all: print.o printf.o helpfunct.o env.o entry.o handleirq.o irq.o unimplement.o sched.o timer.o
10+
all: print.o printf.o helpfunct.o env.o entry.o handleirq.o irq.o unimplement.o sched.o timer.o syscall_lib.o syscall_all.o msyscall.o
1111

1212
clean:
1313
rm -rf *~ *.o

lib/entry.S

+81-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ b \label
7070
ldr x16,[sp,#8*34]//pc
7171
msr elr_el1,x16
7272
add sp, sp, #280
73-
eret
73+
//eret
7474
.endm
7575

7676

@@ -97,7 +97,7 @@ vectors:
9797
handler fiq_invalid_el1h // FIQ EL1h
9898
handler error_invalid_el1h // Error EL1h
9999

100-
handler sync_invalid_el0_64 // Synchronous 64-bit EL0
100+
handler el0_sync // Synchronous 64-bit EL0
101101
handler el0_irq // IRQ 64-bit EL0
102102
handler fiq_invalid_el0_64 // FIQ 64-bit EL0
103103
handler error_invalid_el0_64 // Error 64-bit EL0
@@ -163,9 +163,8 @@ el0_irq:
163163
CLI
164164
ldr x16,=0x82000000//TIMESTACK
165165
mov sp,x16
166-
//saveall
167-
168-
sub sp, sp, #280
166+
saveall
167+
/*sub sp, sp, #280
169168
stp x0, x1, [sp, #16 * 0]
170169
stp x2, x3, [sp, #16 * 1]
171170
stp x4, x5, [sp, #16 * 2]
@@ -182,6 +181,7 @@ el0_irq:
182181
stp x26, x27, [sp, #16 * 13]
183182
stp x28, x29, [sp, #16 * 14]
184183
str x30, [sp, #16 * 15]
184+
185185
mrs x16,sp_el0
186186
str x16,[sp,#8*31]
187187
mrs x16,elr_el1
@@ -190,13 +190,88 @@ el0_irq:
190190

191191
mrs x16,spsr_el1
192192
str x16,[sp,#8*33]
193-
193+
*/
194194

195195
bl handle_irq
196196
restore
197197
STI
198198
eret
199199

200+
el0_sync:
201+
.extern sys_call_table
202+
.extern invalid_syscall
203+
CLI
204+
ldr x16,=0x81fff000//TIMESTACK
205+
mov sp,x16
206+
saveall
207+
/*sub sp, sp, #280
208+
stp x0, x1, [sp, #16 * 0]
209+
stp x2, x3, [sp, #16 * 1]
210+
stp x4, x5, [sp, #16 * 2]
211+
stp x6, x7, [sp, #16 * 3]
212+
stp x8, x9, [sp, #16 * 4]
213+
stp x10, x11, [sp, #16 * 5]
214+
stp x12, x13, [sp, #16 * 6]
215+
stp x14, x15, [sp, #16 * 7]
216+
stp x16, x17, [sp, #16 * 8]
217+
stp x18, x19, [sp, #16 * 9]
218+
stp x20, x21, [sp, #16 * 10]
219+
stp x22, x23, [sp, #16 * 11]
220+
stp x24, x25, [sp, #16 * 12]
221+
stp x26, x27, [sp, #16 * 13]
222+
stp x28, x29, [sp, #16 * 14]
223+
str x30, [sp, #16 * 15]
224+
225+
mrs x16,sp_el0
226+
str x16,[sp,#8*31]
227+
mrs x16,elr_el1
228+
str x16,[sp,#8*32]
229+
str x16,[sp,#8*34]//pc
230+
231+
mrs x16,spsr_el1
232+
str x16,[sp,#8*33]*/
233+
234+
ldr x17,=9527
235+
sub x0,x0,x17
236+
cmp x0,#1//===========1 syscalls
237+
b.ge invalid_syscall
238+
239+
adr x17,sys_call_table
240+
add x17,x17,x0,lsl #3
241+
ldr x17,[x17]
242+
blr x17
243+
244+
/*ldp x0, x1, [sp, #16 * 0]
245+
ldp x2, x3, [sp, #16 * 1]
246+
ldp x4, x5, [sp, #16 * 2]
247+
ldp x6, x7, [sp, #16 * 3]
248+
ldp x8, x9, [sp, #16 * 4]
249+
ldp x10, x11, [sp, #16 * 5]
250+
ldp x12, x13, [sp, #16 * 6]
251+
ldp x14, x15, [sp, #16 * 7]
252+
ldp x16, x17, [sp, #16 * 8]
253+
ldp x18, x19, [sp, #16 * 9]
254+
ldp x20, x21, [sp, #16 * 10]
255+
ldp x22, x23, [sp, #16 * 11]
256+
ldp x24, x25, [sp, #16 * 12]
257+
ldp x26, x27, [sp, #16 * 13]
258+
ldp x28, x29, [sp, #16 * 14]
259+
ldr x30, [sp, #16 * 15]
260+
261+
ldr x16,[sp,#8*31]
262+
msr sp_el0,x16
263+
264+
ldr x16,[sp,#8*33]
265+
msr spsr_el1,x16
266+
267+
ldr x16,[sp,#8*34]//pc
268+
msr elr_el1,x16
269+
add sp, sp, #280*/
270+
restore
271+
//STI
272+
eret
273+
274+
200275
.globl irq_vector_init
201276
.extern vectors
202277
irq_vector_init:

lib/env.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@ env_alloc(struct Env **new, unsigned long parent_id)
135135
panic("fuck,env_create_priority:env_alloc failed");
136136
return;
137137
}
138+
/*stack*/
138139
struct Page *p = NULL;
139140
r=page_alloc(&p);
140141
p->pp_ref++;
141142
if(r<0){
142143
printf("env_create:page_alloc failed\n");
143144
return;
144145
}
146+
printf("fuck %x\n",e->env_pgdir);
145147
r=page_insert(e->env_pgdir,p,USTACKTOP-BY2PG,PTE_V);
146148
/*Step 2: assign priority to the new env. */
147149
e->env_pri=priority;
@@ -168,6 +170,7 @@ extern void env_pop_tf(struct Trapframe *tf,unsigned long* pgdir);
168170

169171
void env_run(struct Env *e)
170172
{
173+
extern void tlb_invalidate();
171174
struct Trapframe *old=(struct Trapframe*)(TIMESTACK-sizeof(struct Trapframe));
172175
/*Step 1: save register state of curenv. */
173176
/* Hint: if there is a environment running,you should do
@@ -186,7 +189,11 @@ void env_run(struct Env *e)
186189
* environment registers and drop into user mode in the
187190
* the environment.
188191
*/
189-
192+
//printf("jump to %x of %x\n",curenv->env_tf.pc,curenv->env_id);
193+
/*printf("pgdir %x,pmd %x\n",curenv->env_pgdir,(curenv->env_pgdir)[PUDX(USTACKTOP-BY2PG)]);
194+
unsigned long* tmp= PTE_ADDR((curenv->env_pgdir)[PUDX(USTACKTOP-BY2PG)]);
195+
printf("pte%x\n",tmp[PMDX(USTACKTOP-BY2PG)]);*/
196+
tlb_invalidate();
190197
env_pop_tf(&(curenv->env_tf),curenv->env_pgdir);//---------
191198

192199
}

lib/helpfunct.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include<uart.h>
2+
#include<syscall_lib.h>
23
void bcopy(const void *src, void *dst, unsigned long len)
34
{
45
void *max;
@@ -45,11 +46,13 @@ void bzero(void *b, unsigned long len)
4546
}
4647
void user_maina(){
4748
while(1){
48-
uart_send_boot('1');
49+
syscall_putchar('1');
50+
//uart_send_boot('1');
4951
}
5052
}
5153
void user_mainb(){
5254
while(1){
53-
uart_send_boot('2');
55+
//uart_send_boot('2');
56+
syscall_putchar('2');
5457
}
5558
}

lib/msyscall.S

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global msyscall
2+
msyscall:
3+
svc #0
4+
ret

lib/sched.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include<env.h>
2+
#include<printf.h>
23
int remaining_time;
34
void sched_yield(){
45
static int pos = -1;
6+
//printf("sched!\n");
57
while(1){
68
pos = (pos+1)%NENV;
79
if(envs[pos].env_status==ENV_RUNNABLE){

lib/syscall_all.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include<printf.h>
2+
#include<uart.h>
3+
int sys_putchar(long no,long ch){
4+
5+
uart_send_boot(ch);
6+
return 0;
7+
}
8+
long * const sys_call_table[] ={sys_putchar};

lib/syscall_lib.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include<syscall_lib.h>
2+
#include<printf.h>
3+
4+
void invalid_syscall(long a0){
5+
printf("invalid syscall :%x\n",a0);
6+
panic("error:syscall");
7+
}
8+
9+
int syscall_putchar(char ch){
10+
//printf("syscall:%c@%x\n",ch,&ch);
11+
msyscall(SYS_putchar,(long)ch,0,0,0,0);
12+
}

lib/timer.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
timer_init:
33
mov x0,#0x3
44
msr cntkctl_el1,x0
5-
ldr x0,=(0x3b9aca0>>4)
5+
ldr x0,=(0x3b9aca0>>6)
66
//when the qemu start,the frequency is 0x3b9aca0 HZ
77
//i don't know why i cannot change the frquency of it
88
//doing so to so set 1s per exception

0 commit comments

Comments
 (0)