134 lines
2.9 KiB
NASM
134 lines
2.9 KiB
NASM
|
||
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||
; syscall.asm
|
||
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||
; Forrest Yu, 2005
|
||
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||
|
||
%include "sconst.inc"
|
||
|
||
; TODO 系统调用的设置
|
||
_NR_get_ticks equ 0 ; 要跟 global.c 中 sys_call_table 的定义相对应!
|
||
_NR_print_str equ 1 ; 要跟 global.c 中 sys_call_table 的定义相对应!
|
||
_NR_ms_delay equ 2 ; 要跟 global.c 中 sys_call_table 的定义相对应!
|
||
_NR_p equ 3 ; 要跟 global.c 中 sys_call_table 的定义相对应!
|
||
_NR_v equ 4 ; 要跟 global.c 中 sys_call_table 的定义相对应!
|
||
INT_VECTOR_SYS_CALL equ 0x90
|
||
|
||
; TODO 系统调用的导出符号
|
||
global get_ticks
|
||
global print_str
|
||
global sys_print_str
|
||
global ms_delay ;外部调用,准备现场,发出中断
|
||
global sys_ms_delay ;具体实现,将ebx压入内核栈,调用sys_ms_delay_proc(int)
|
||
global sys_p
|
||
global sys_v
|
||
global p
|
||
global v
|
||
|
||
; TODO 导入外部函数
|
||
extern sys_ms_delay_proc
|
||
extern disp_str
|
||
extern sys_p_impl
|
||
extern sys_v_impl
|
||
|
||
bits 32
|
||
[section .text]
|
||
|
||
; ====================================================================
|
||
; get_ticks
|
||
; ====================================================================
|
||
get_ticks:
|
||
mov eax, _NR_get_ticks
|
||
int INT_VECTOR_SYS_CALL
|
||
ret
|
||
|
||
; ====================================================================
|
||
; TODO 不分配时间片sys_ms_delay
|
||
; ====================================================================
|
||
ms_delay:
|
||
;准备现场,发出中断
|
||
mov eax, _NR_ms_delay
|
||
push ebx
|
||
mov ebx, [esp+8]
|
||
int INT_VECTOR_SYS_CALL
|
||
pop ebx
|
||
ret
|
||
|
||
sys_ms_delay:
|
||
;系统调用
|
||
pusha
|
||
push ebx
|
||
call sys_ms_delay_proc ;保存ebx后调用sys_ms_delay_proc
|
||
pop ebx
|
||
popa
|
||
ret
|
||
|
||
|
||
; ====================================================================
|
||
; TODO 打印字符串sys_print_str
|
||
; ====================================================================
|
||
print_str:
|
||
;准备现场,发出中断
|
||
mov eax, _NR_print_str
|
||
push ebx
|
||
mov ebx, [esp+8]
|
||
int INT_VECTOR_SYS_CALL
|
||
pop ebx
|
||
ret
|
||
|
||
sys_print_str:
|
||
;系统调用
|
||
pusha
|
||
push ebx
|
||
call disp_str
|
||
pop ebx
|
||
popa
|
||
ret
|
||
|
||
|
||
; ====================================================================
|
||
; TODO PV
|
||
; ====================================================================
|
||
p:
|
||
;准备现场,发出中断
|
||
mov eax, _NR_p
|
||
push ebx
|
||
mov ebx, [esp+8]
|
||
int INT_VECTOR_SYS_CALL
|
||
pop ebx
|
||
ret
|
||
|
||
|
||
v:
|
||
;准备现场,发出中断
|
||
mov eax, _NR_v
|
||
push ebx
|
||
mov ebx, [esp+8]
|
||
int INT_VECTOR_SYS_CALL
|
||
pop ebx
|
||
ret
|
||
|
||
sys_p:
|
||
;系统调用
|
||
pusha
|
||
push ebx
|
||
call sys_p_impl
|
||
pop ebx
|
||
popa
|
||
ret
|
||
|
||
sys_v:
|
||
;系统调用
|
||
pusha
|
||
push ebx
|
||
call sys_v_impl
|
||
pop ebx
|
||
popa
|
||
ret
|
||
|
||
|
||
|
||
|
||
|