finish exec3.4-8

This commit is contained in:
KAAAsS 2021-05-16 14:00:20 +08:00
parent 37f581eb6a
commit 28a1f7d5a2
Signed by: KAAAsS
GPG Key ID: D56625F3E671882F
7 changed files with 61 additions and 9 deletions

View File

@ -13,4 +13,4 @@ define add-symbol-file-auto
end end
add-symbol-file-auto ./build/kernel.img add-symbol-file-auto ./build/kernel.img
add-symbol-file-auto ./user/build/ramdisk/badinsn.bin add-symbol-file-auto ./user/build/ramdisk/hello.bin

View File

@ -180,6 +180,7 @@ sync_el0_64:
exception_exit exception_exit
el0_syscall: el0_syscall:
//
sub sp, sp, #16 * 8 sub sp, sp, #16 * 8
stp x0, x1, [sp, #16 * 0] stp x0, x1, [sp, #16 * 0]
stp x2, x3, [sp, #16 * 1] stp x2, x3, [sp, #16 * 1]
@ -199,6 +200,7 @@ el0_syscall:
ldp x14, x15, [sp, #16 * 7] ldp x14, x15, [sp, #16 * 7]
add sp, sp, #16 * 8 add sp, sp, #16 * 8
// 2
adr x27, syscall_table // syscall table in x27 adr x27, syscall_table // syscall table in x27
uxtw x16, w8 // syscall number in x16 uxtw x16, w8 // syscall number in x16
ldr x16, [x27, x16, lsl #3] // find the syscall entry ldr x16, [x27, x16, lsl #3] // find the syscall entry

View File

@ -29,8 +29,11 @@ void sys_putc(char ch)
* Lab3: Your code here * Lab3: Your code here
* Send ch to the screen in anyway as your like * Send ch to the screen in anyway as your like
*/ */
uart_send(ch);
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winitializer-overrides"
/* /*
* Lab3: Your code here * Lab3: Your code here
* Update the syscall table as you like to redirect syscalls * Update the syscall table as you like to redirect syscalls
@ -38,5 +41,11 @@ void sys_putc(char ch)
*/ */
const void *syscall_table[NR_SYSCALL] = { const void *syscall_table[NR_SYSCALL] = {
[0 ... NR_SYSCALL - 1] = sys_debug, [0 ... NR_SYSCALL - 1] = sys_debug,
[SYS_putc] = sys_putc,
[SYS_exit] = sys_exit,
[SYS_create_pmo] = sys_create_pmo,
[SYS_map_pmo] = sys_map_pmo,
[SYS_handle_brk] = sys_handle_brk,
/* lab3 syscalls finished */ /* lab3 syscalls finished */
}; };
#pragma clang diagnostic pop

View File

@ -14,10 +14,10 @@
#define NR_SYSCALL 256 #define NR_SYSCALL 256
void sys_exit(void); void sys_exit(int ret);
void sys_create_pmo(void); int sys_create_pmo(u64 size, u64 type);
void sys_map_pmo(void); int sys_map_pmo(u64 target_process_cap, u64 pmo_cap, u64 addr, u64 perm);
void sys_handle_brk(void); u64 sys_handle_brk(u64 addr);
/* lab3 syscalls finished */ /* lab3 syscalls finished */
#define SYS_putc 0 #define SYS_putc 0

View File

@ -13,5 +13,6 @@ void _start_c(long *p)
* Lab3: Your code here * Lab3: Your code here
* Complete the main function * Complete the main function
*/ */
usys_exit(ret);
return; return;
} }

View File

@ -13,7 +13,28 @@ u64 syscall(u64 sys_no, u64 arg0, u64 arg1, u64 arg2, u64 arg3, u64 arg4,
* And finally use svc to execute the system call. After syscall returned, don't forget * And finally use svc to execute the system call. After syscall returned, don't forget
* to move return value from x0 to the ret variable of this function * to move return value from x0 to the ret variable of this function
*/ */
return ret;
__asm __volatile("mov x9, %0"::"r"(sys_no));
// 参数
#define SET_ARG(n) __asm __volatile("mov x"#n", %0"::"r"(arg##n));
SET_ARG(0);
SET_ARG(1);
SET_ARG(2);
SET_ARG(3);
SET_ARG(4);
SET_ARG(5);
SET_ARG(6);
SET_ARG(7);
// 系统调用
__asm __volatile("mov x8, x9");
__asm ("svc #0");
// 返回值
__asm __volatile("mov %0, x0":"=r"(ret));
return ret;
} }
/* /*
@ -22,25 +43,27 @@ u64 syscall(u64 sys_no, u64 arg0, u64 arg1, u64 arg2, u64 arg3, u64 arg4,
*/ */
void usys_putc(char ch) void usys_putc(char ch)
{ {
syscall(SYS_putc, ch, 0, 0, 0, 0, 0, 0, 0, 0);
} }
void usys_exit(int ret) void usys_exit(int ret)
{ {
syscall(SYS_exit, ret, 0, 0, 0, 0, 0, 0, 0, 0);
} }
int usys_create_pmo(u64 size, u64 type) int usys_create_pmo(u64 size, u64 type)
{ {
return 0; return (int) syscall(SYS_create_pmo, size, type, 0, 0, 0, 0, 0, 0, 0);
} }
int usys_map_pmo(u64 process_cap, u64 pmo_cap, u64 addr, u64 rights) int usys_map_pmo(u64 process_cap, u64 pmo_cap, u64 addr, u64 rights)
{ {
return 0; return (int) syscall(SYS_map_pmo, process_cap, pmo_cap, addr, rights, 0, 0, 0, 0, 0);
} }
u64 usys_handle_brk(u64 addr) u64 usys_handle_brk(u64 addr)
{ {
return 0; return syscall(SYS_handle_brk, addr, 0, 0, 0, 0, 0, 0, 0, 0);
} }
/* Here finishes all syscalls need by lab3 */ /* Here finishes all syscalls need by lab3 */

View File

@ -156,3 +156,20 @@ ELF Section、Segment 两个概念。
*** 练习2 *** 练习2
process_create_root、thread_create_main 直接写在注释里面了。 process_create_root、thread_create_main 直接写在注释里面了。
*** 练习4
见注释
*** 练习5
基本就是移动参数寄存器然后 svc。注意要先保存 x0 寄存器到另一寄存器。
*** 练习7
主要原因是 libmain 中跳转都是使用 b 指令(没有填写链接寄存器),因此执行到 main 的 ret 时链接寄存器值为 0
程序就返回到 0x0 处执行了。由此触发指令异常。
*** 练习8
这个是最离谱的。所谓退出其实就是输出里出现了“breakpoint”。实际上程序并不会退出评测机倒是会