📄 api.h
字号:
//// Visopsys// Copyright (C) 1998-2007 J. Andrew McLaughlin// // This program is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 of the License, or (at your option)// any later version.// // This program is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License// for more details.// // You should have received a copy of the GNU General Public License along// with this program; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// api.h//// This file describes all of the functions that are directly exported by// the Visopsys kernel to the outside world. All functions and their// numbers are listed here, as well as macros needed to perform call-gate// calls into the kernel. Also, each exported kernel function is represented// here in the form of a little inline function.#if !defined(_API_H)// This file should mostly never be included when we're compiling a kernel// file (kernelApi.c is an exception)#if defined(KERNEL)#error "You cannot call the kernel API from within a kernel function"#endif#include <time.h>#include <sys/file.h>#include <sys/stream.h>// Included in the Visopsys standard library to prevent API calls from// within kernel code.extern int visopsys_in_kernel;// Text input/output functions. All are in the 1000-1999 range.#define _fnum_textGetForeground 1003#define _fnum_textSetForeground 1004#define _fnum_textGetBackground 1005#define _fnum_textSetBackground 1006#define _fnum_textPutc 1007#define _fnum_textPrint 1008#define _fnum_textPrintLine 1009#define _fnum_textNewline 1010#define _fnum_textBackSpace 1011#define _fnum_textTab 1012#define _fnum_textCursorUp 1013#define _fnum_textCursorDown 1014#define _fnum_ternelTextCursorLeft 1015#define _fnum_textCursorRight 1016#define _fnum_textGetNumColumns 1017#define _fnum_textGetNumRows 1018#define _fnum_textGetColumn 1019#define _fnum_textSetColumn 1020#define _fnum_textGetRow 1021#define _fnum_textSetRow 1022#define _fnum_textClearScreen 1023#define _fnum_textInputCount 1024#define _fnum_textInputGetc 1025#define _fnum_textInputReadN 1026#define _fnum_textInputReadAll 1027#define _fnum_textInputAppend 1028#define _fnum_textInputAppendN 1029#define _fnum_textInputRemove 1030#define _fnum_textInputRemoveN 1031#define _fnum_textInputRemoveAll 1032#define _fnum_textInputSetEcho 1033// Filesystem functions. All are in the 8000-8999 range.#define _fnum_filesystemSync 8001#define _fnum_filesystemMount 8002#define _fnum_filesystemUnmount 8003#define _fnum_filesystemNumberMounted 8004#define _fnum_filesystemFirstFilesystem 8005#define _fnum_filesystemNextFilesystem 8006#define _fnum_filesystemGetFree 8007#define _fnum_filesystemGetBlockSize 8008// File functions. All are in the 9000-9999 range.#define _fnum_fileFixupPath 9001#define _fnum_fileFirst 9002#define _fnum_fileNext 9003#define _fnum_fileFind 9004#define _fnum_fileOpen 9005#define _fnum_fileClose 9006#define _fnum_fileRead 9007#define _fnum_fileWrite 9008#define _fnum_fileDelete 9009#define _fnum_fileDeleteSecure 9010#define _fnum_fileMakeDir 9011#define _fnum_fileRemoveDir 9012#define _fnum_fileCopy 9013#define _fnum_fileMove 9014#define _fnum_fileTimestamp 9015#define _fnum_fileStreamOpen 9016#define _fnum_fileStreamSeek 9017#define _fnum_fileStreamRead 9018#define _fnum_fileStreamWrite 9019#define _fnum_fileStreamFlush 9020#define _fnum_fileStreamClose 9021// Memory manager functions. All are in the 10000-10999 range.#define _fnum_memoryPrintUsage 10001#define _fnum_memoryRequestBlock 10002#define _fnum_memoryRequestPhysicalBlock 10003#define _fnum_memoryReleaseBlock 10004#define _fnum_memoryReleaseAllByProcId 10005#define _fnum_memoryChangeOwner 10006// Multitasker functions. All are in the 11000-11999 range.#define _fnum_multitaskerCreateProcess 11001#define _fnum_multitaskerSpawn 11002#define _fnum_multitaskerGetCurrentProcessId 11003#define _fnum_multitaskerGetProcessOwner 11004#define _fnum_multitaskerGetProcessName 11005#define _fnum_multitaskerGetProcessState 11006#define _fnum_multitaskerSetProcessState 11007#define _fnum_multitaskerGetProcessPriority 11008#define _fnum_multitaskerSetProcessPriority 11009#define _fnum_multitaskerGetProcessPrivilege 11010#define _fnum_multitaskerGetCurrentDirectory 11011#define _fnum_multitaskerSetCurrentDirectory 11012#define _fnum_multitaskerGetProcessorTime 11013#define _fnum_multitaskerYield 11014#define _fnum_multitaskerWait 11015#define _fnum_multitaskerBlock 11016#define _fnum_multitaskerKillProcess 11017#define _fnum_multitaskerTerminate 11018#define _fnum_multitaskerDumpProcessList 11019// Loader functions. All are in the 12000-12999 range.#define _fnum_loaderLoadAndExec 12001// Real-time clock functions. All are in the 13000-13999 range.#define _fnum_rtcReadSeconds 13001#define _fnum_rtcReadMinutes 13002#define _fnum_rtcReadHours 13003#define _fnum_rtcReadDayOfWeek 13004#define _fnum_rtcReadDayOfMonth 13005#define _fnum_rtcReadMonth 13006#define _fnum_rtcReadYear 13007#define _fnum_rtcUptimeSeconds 13008#define _fnum_rtcDateTime 13009// Random number functions. All are in the 14000-14999 range.#define _fnum_randomUnformatted 14001#define _fnum_randomFormatted 14002#define _fnum_randomSeededUnformatted 14003#define _fnum_randomSeededFormatted 14004// Environment functions. All are in the 15000-15999 range.#define _fnum_environmentGet 15001#define _fnum_environmentSet 15002#define _fnum_environmentUnset 15003#define _fnum_environmentDump 15004// Window manager functions#define _fnum_windowManagerStart 16001#define _fnum_windowManagerNewWindow 16002#define _fnum_windowSetTitle 16003#define _fnum_windowSetSize 16004#define _fnum_windowSetLocation 16005#define _fnum_windowSetVisible 16006// Miscellaneous functions#define _fnum_shutdown 99001#define _fnum_version 99002// Utility macros for stack manipulation#define stackPush(value) \ __asm__ __volatile__ ("pushl %0 \n\t" : : "r" (value))#define stackAdj(bytes) \ __asm__ __volatile__ ("addl %0, %%esp \n\t" \ : : "r" (bytes) : "%esp")// The generic calls for accessing the kernel API#define sysCall(retCode) \ if (!visopsys_in_kernel) \ { \ __asm__ __volatile__ ("lcall $0x003B,$0x00000000 \n\t" \ "movl %%eax, %0 \n\t" \ : "=r" (retCode) : : "%eax", "memory"); \ } \ else \ { \ retCode = -1; \ }// These use the macros defined above to call the kernel with the// appropriate number of argumentsstatic inline int sysCall_0(int fnum){ // Do a syscall with NO parameters int status = 0; stackPush(fnum); stackPush(1); sysCall(status); stackAdj(8); return (status);}static inline int sysCall_1(int fnum, void *arg1){ // Do a syscall with 1 parameter int status = 0; stackPush(arg1); stackPush(fnum); stackPush(2); sysCall(status); stackAdj(12); return (status);}static inline int sysCall_2(int fnum, void *arg1, void *arg2){ // Do a syscall with 2 parameters int status = 0; stackPush(arg2); stackPush(arg1); stackPush(fnum); stackPush(3); sysCall(status); stackAdj(16); return (status);}static inline int sysCall_3(int fnum, void *arg1, void *arg2, void *arg3){ // Do a syscall with 3 parameters int status = 0; stackPush(arg3); stackPush(arg2); stackPush(arg1); stackPush(fnum); stackPush(4); sysCall(status); stackAdj(20); return (status);}static inline int sysCall_4(int fnum, void *arg1, void *arg2, void *arg3, void *arg4){ // Do a syscall with 4 parameters int status = 0; stackPush(arg4); stackPush(arg3); stackPush(arg2); stackPush(arg1); stackPush(fnum); stackPush(5); sysCall(status); stackAdj(24); return (status);}static inline int sysCall_5(int fnum, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5){ // Do a syscall with 5 parameters int status = 0; stackPush(arg5); stackPush(arg4); stackPush(arg3); stackPush(arg2); stackPush(arg1); stackPush(fnum); stackPush(6); sysCall(status); stackAdj(28); return (status);}static inline int sysCall_6(int fnum, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6){ // Do a syscall with 5 parameters int status = 0; stackPush(arg6); stackPush(arg5); stackPush(arg4); stackPush(arg3); stackPush(arg2); stackPush(arg1); stackPush(fnum); stackPush(7); sysCall(status); stackAdj(32); return (status);}// These inline functions are used to call specific kernel functions. // There will be one of these for every API function.//// Text input/output functions//static inline int textGetForeground(void){ // Proto: int kernelTextGetForeground(void); return (sysCall_0(_fnum_textGetForeground));}static inline int textSetForeground(int color){ // Proto: int kernelTextSetForeground(int); return (sysCall_1(_fnum_textSetForeground, (void *) color));}static inline int textGetBackground(void){ // Proto: int kernelTextGetBackground(void); return (sysCall_0(_fnum_textGetBackground));}static inline int textSetBackground(int color){ // Proto: int kernelTextSetBackground(int); return (sysCall_1(_fnum_textSetBackground, (void *) color));}static inline int textPutc(int ascii){ // Proto: int kernelTextPutc(int); return (sysCall_1(_fnum_textPutc, (void*)ascii));}static inline int textPrint(const char *str){ // Proto: int kernelTextPrint(const char *); return (sysCall_1(_fnum_textPrint, (void *) str));}static inline int textPrintLine(const char *str){ // Proto: int kernelTextPrintLine(const char *); return (sysCall_1(_fnum_textPrintLine, (void *) str));}static inline void textNewline(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -