SLEEPINT = 2
.include "include/memory.inc"
.include "include/kstructs.inc"
.include "macros.s"
.text
.global SysCalls
.global GoToSleep
.global SetCurrentDirectory
CallNo:
.quad Sys_Exit
.quad Sys_Fork
.quad Sys_Read
.quad Sys_Write
.quad Sys_Open
.quad Sys_Close
.quad SysWaitPID
.quad Sys_Creat
.quad Unimplemented #Sys_Link
.quad Sys_UnLink
.quad Sys_Execve
.quad Sys_ChDir
.quad Unimplemented #Sys_Time
.quad Unimplemented #Sys_MkNod
.quad Unimplemented #Sys_ChMod
.quad Unimplemented #Sys_LChOwn
.quad Unimplemented #Unused
.quad Sys_Stat
.quad Sys_LSeek
.quad Unimplemented #Sys_GetPid
.quad Unimplemented #Sys_Mount
.quad Unimplemented #Sys_Umount
.quad Unimplemented #Sys_SetUID
.quad Unimplemented #Sys_GetUID
.quad Unimplemented #Sys_Stime
.quad Unimplemented #Sys_Ptrace
.quad Unimplemented #Sys_Alarm
.quad Sys_FStat
.quad GetTicks
.quad Sys_Nanosleep
.quad Alloc_Mem
.quad Send_Message
.quad Receive_Message
.quad Dealloc_Mem
.quad Send_Receive
.quad GetCurrentConsole
.quad Sys_Getcwd
.quad Sys_MkDir
SysCalls:
jmp *(CallNo - 8)(,%r9, 8)
#=========================================================
#=========================================================
Sys_Exit:
push %rcx
call KillTask
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Fork:
push %rcx
call DoFork
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Read:
push %rcx
call DoRead
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Write:
push %rcx
call DoWrite
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Open:
push %rcx
call KOpenFile
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Close:
push %rcx
call KCloseFile
pop %rcx
sysretq
#=========================================================
#=========================================================
SysWaitPID:
push %rcx
call Do_Wait
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Creat:
push %rcx
call DoCreate
pop %rcx
sysretq
#=========================================================
#=========================================================
Unimplemented: #Sys_Link:
sysretq
#=========================================================
#=========================================================
Sys_UnLink:
push %rcx
call DoDelete
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Execve:
push %rcx
call DoExec
cmp $1,%rax
je notLoaded
mov $(UserStack + PageSize), %rsp
push $UserCode
notLoaded:
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_ChDir:
push %rcx
call DoChDir
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_Stat:
push %rcx
call DoStat
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_FStat:
push %rcx
call DoFStat
pop %rcx
sysretq
#=========================================================
#=========================================================
Sys_LSeek:
push %rcx
call Do_Seek
pop %rcx
sysretq
#========================================================
#========================================================
PrintString:
mov $160, %ax
mul %bh
mov $0, %bh
shl $1, %bx
add %ax, %bx
.isItStringEnd:
mov (%edx), %ah
cmp $0, %ah
je .done
mov %ah, 0xB8000(%ebx)
add $2, %bx
inc %edx
jmp .isItStringEnd
.done: sysretq
#========================================================
#========================================================
PrintDouble:
push %rcx
mov $160, %ax
mul %bh
mov $0, %bh
shl $1, %bx
add %ax, %bx
mov $8, %rcx
.stillCounting:
shld $4, %edx, %eax
shl $4, %edx
and $0xF, %eax
add $'0, %al
cmp $'9, %al
jle .under10
add $7, %al
.under10:
mov %al, 0xB8000(%ebx)
add $2, %bx
loop .stillCounting
pop %rcx
sysretq
#========================================================
#========================================================
PrintChar:
push %ax
mov $160, %ax
mul %bh
mov $0, %bh
shl $1, %bx
add %ax, %bx
pop %ax
mov %ah, 0xB8000(%ebx)
sysretq
#=============================================================================
#=============================================================================
GetTicks:
mov Ticks, %rax
sysretq
#=====================================================
#=====================================================
Sys_Nanosleep:
push %rcx
mov currentTask, %r15
movb $SLEEPINT, TS.waiting(%r15)
mov %rdi, TS.timer(%r15)
mov %r15, %rdi
call BlockTask
SWITCH_TASKS # The current task is no longer runnable
pop %rcx
sysretq
#==============================================================
#==============================================================
Alloc_Mem:
push %rcx
mov currentTask, %r15
mov TS.firstfreemem(%r15), %rsi
call AllocMem
pop %rcx
sysretq
#===================================
#===================================
Send_Message:
push %rcx
call SendMessage
pop %rcx
sysretq
#===========================================================
#===========================================================
Receive_Message:
push %rcx
call ReceiveMessage
pop %rcx
sysretq
#==================================================
#==================================================
Dealloc_Mem:
push %rcx
call DeallocMem
pop %rcx
sysretq
#======================================================
#======================================================
Send_Receive:
push %rcx
call SendReceiveMessage
pop %rcx
sysretq
#=================================================
#=================================================
GetCurrentConsole:
mov currentTask, %r15
mov TS.console(%r15), %rax
sysretq
#===================================================
#===================================================
Sys_Getcwd:
push %rcx
call DoGetcwd
pop %rcx
sysretq
#========================================================
#========================================================
Sys_MkDir:
push %rcx
call DoMkDir
pop %rcx
sysretq
#========================================================
#========================================================
GoToSleep:
push %rdx
mov currentTask, %r15
movb $SLEEPINT, TS.waiting(%r15)
mov %rdi, TS.timer(%r15)
mov %r15, %rdi
call BlockTask
pop %rdx
SWITCH_TASKS # The current task is no longer runnable
ret