IBNOS
syscall.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef _H_SYSCALL_
29 #define _H_SYSCALL_
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 
39 enum
40 {
41 
50 
59 
68 
77 
86 
95 
105 
116 
125 
135 
144 
153 
163 
172 
181 
191 
201  SYSCALL_FORK = 0x300,
202 
216 
225 
234 
243 
252 
261 
271 
280 
291 
300 
310 
322 
334 
344 
356 
368 
380 
390 
401 
412 
421 
430 
439 
448 
458 
467 
477 
486 
495 
504 
516 
528 
537 
538 };
539 
540 #ifndef __KERNEL__
541 
542  #define IBNOS_SYSCALL_FN(syscall, n0, n1, n2, n3, n4, n5, n6, n7, n8, n, ...) ibnos_syscall##n
543  #define ibnos_syscall(syscall, ...) IBNOS_SYSCALL_FN(syscall, ##__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)(syscall, ##__VA_ARGS__)
544 
545  static inline int ibnos_syscall0(int syscall)
546  {
547  int ret;
548  asm volatile ("int $0x80" :"=a"(ret) :"a"(syscall));
549  return ret;
550  }
551 
552  static inline int ibnos_syscall1(int syscall, uint32_t value1)
553  {
554  int ret;
555  asm volatile ("int $0x80" :"=a"(ret) : "a"(syscall), "b"(value1));
556  return ret;
557  }
558 
559  static inline int ibnos_syscall2(int syscall, uint32_t value1, uint32_t value2)
560  {
561  int ret;
562  asm volatile ("int $0x80" :"=a"(ret) : "a"(syscall), "b"(value1), "c" (value2));
563  return ret;
564  }
565 
566  static inline int ibnos_syscall3(int syscall, uint32_t value1, uint32_t value2, uint32_t value3)
567  {
568  int ret;
569  asm volatile ("int $0x80" :"=a"(ret) : "a"(syscall), "b"(value1), "c" (value2), "d" (value3));
570  return ret;
571  }
572 
573  static inline int ibnos_syscall4(int syscall, uint32_t value1, uint32_t value2, uint32_t value3, uint32_t value4)
574  {
575  int ret;
576  asm volatile ("int $0x80" :"=a"(ret) : "a"(syscall), "b"(value1), "c" (value2), "d" (value3), "S" (value4));
577  return ret;
578  }
579 
580  static inline int ibnos_syscall5(int syscall, uint32_t value1, uint32_t value2, uint32_t value3, uint32_t value4, uint32_t value5)
581  {
582  int ret;
583  asm volatile ("int $0x80" :"=a"(ret) : "a"(syscall), "b"(value1), "c" (value2), "d" (value3), "S" (value4), "D" (value5));
584  return ret;
585  }
586 
587  static inline void yield()
588  {
589  ibnos_syscall(SYSCALL_YIELD);
590  }
591  /* exit is already provided by the libc */
592 
593  static inline void exitThread(int exitcode)
594  {
595  ibnos_syscall(SYSCALL_EXIT_THREAD, exitcode);
596  }
597 
598  static inline int32_t getCurrentProcess()
599  {
600  return (int32_t)ibnos_syscall(SYSCALL_GET_CURRENT_PROCESS);
601  }
602 
603  static inline int32_t getCurrentThread()
604  {
605  return (int32_t)ibnos_syscall(SYSCALL_GET_CURRENT_THREAD);
606  }
607 
608  static inline uint32_t getMonotonicClock()
609  {
610 
611  return ibnos_syscall(SYSCALL_GET_MONOTONIC_CLOCK);
612  }
613 
614  static inline uint32_t getProcessInfo(void *info, uint32_t count)
615  {
616  return ibnos_syscall(SYSCALL_GET_PROCESS_INFO, (uint32_t)info, count);
617  }
618 
619  static inline int32_t executeProgram(int32_t handle, void *arg, uint32_t arglen, void *env, uint32_t envlen)
620  {
621  return ibnos_syscall(SYSCALL_EXECUTE_PROGRAM, (uint32_t)handle, (uint32_t)arg, arglen, (uint32_t)env, envlen);
622  }
623 
624  static inline void *getTLS()
625  {
626  return (void *)ibnos_syscall(SYSCALL_GET_THREADLOCAL_STORAGE_BASE);
627  }
628 
629  static inline uint32_t getTLSLength()
630  {
631  return ibnos_syscall(SYSCALL_GET_THREADLOCAL_STORAGE_LENGTH);
632  }
633 
634  static inline void *getProgramArguments()
635  {
636  return (void *)ibnos_syscall(SYSCALL_GET_PROGRAM_ARGUMENTS_BASE);
637  }
638 
639  static inline uint32_t getProgramArgumentsLength()
640  {
641  return ibnos_syscall(SYSCALL_GET_PROGRAM_ARGUMENTS_LENGTH);
642  }
643 
644  static inline void *getEnvironmentVariables()
645  {
646  return (void *)ibnos_syscall(SYSCALL_GET_ENVIRONMENT_VARIABLES_BASE);
647  }
648 
649  static inline uint32_t getEnvironmentVariablesLength()
650  {
651  return ibnos_syscall(SYSCALL_GET_ENVIRONMENT_VARIABLES_LENGTH);
652  }
653 
654  /* malloc, free and fork are also provided by the libc */
655 
656  extern void *_thread_start;
657  static inline int32_t createThread(void *func, uint32_t arg0, uint32_t arg1, uint32_t arg2)
658  {
659  return (int32_t)ibnos_syscall(SYSCALL_CREATE_THREAD, (uint32_t)&_thread_start, (uint32_t)func, arg0, arg1, arg2);
660  }
661 
662  static inline int32_t createEvent(bool wakeupAll)
663  {
664  return (int32_t)ibnos_syscall(SYSCALL_CREATE_EVENT, (uint32_t)wakeupAll);
665  }
666 
667  static inline int32_t createSemaphore(uint32_t value)
668  {
669  return (int32_t)ibnos_syscall(SYSCALL_CREATE_SEMAPHORE, value);
670  }
671 
672  static inline int32_t createPipe()
673  {
674  return (int32_t)ibnos_syscall(SYSCALL_CREATE_PIPE);
675  }
676 
677  static inline int32_t createTimer(bool wakeupAll)
678  {
679  return (int32_t)ibnos_syscall(SYSCALL_CREATE_TIMER, (uint32_t)wakeupAll);
680  }
681 
682  /* dup, dup2 are provided by libc */
683 
684  static inline bool objectExists(int32_t handle)
685  {
686  return ibnos_syscall(SYSCALL_OBJECT_EXISTS, (uint32_t)handle);
687  }
688 
689  static inline int32_t objectCompare(int32_t handle1, int32_t handle2)
690  {
691  return (int32_t)ibnos_syscall(SYSCALL_OBJECT_EXISTS, (uint32_t)handle1, (uint32_t)handle2);
692  }
693 
694  static inline bool objectClose(int32_t handle)
695  {
696  return ibnos_syscall(SYSCALL_OBJECT_CLOSE, (uint32_t)handle);
697  }
698 
699  static inline bool objectShutdown(int32_t handle, uint32_t mode)
700  {
701  return ibnos_syscall(SYSCALL_OBJECT_SHUTDOWN, (uint32_t)handle, mode);
702  }
703 
704  static inline uint32_t objectGetStatus(int32_t handle, uint32_t mode)
705  {
706  return ibnos_syscall(SYSCALL_OBJECT_GET_STATUS, (uint32_t)handle, mode);
707  }
708 
709  static inline int32_t objectWait(int32_t handle, uint32_t mode)
710  {
711  return (int32_t)ibnos_syscall(SYSCALL_OBJECT_WAIT, (uint32_t)handle, mode);
712  }
713 
714  static inline bool objectSignal(int32_t handle, uint32_t result)
715  {
716  return ibnos_syscall(SYSCALL_OBJECT_SIGNAL, (uint32_t)handle, result);
717  }
718 
719  static inline int32_t objectWrite(int32_t handle, void *buffer, uint32_t length)
720  {
721  return (int32_t)ibnos_syscall(SYSCALL_OBJECT_WRITE, (uint32_t)handle, (uint32_t)buffer, length);
722  }
723 
724  static inline int32_t objectRead(int32_t handle, void *buffer, uint32_t length)
725  {
726  return (int32_t)ibnos_syscall(SYSCALL_OBJECT_READ, (uint32_t)handle, (uint32_t)buffer, length);
727  }
728 
729  static inline bool objectAttach(int32_t handle, int32_t childHandle, uint32_t mode, uint32_t ident)
730  {
731  return ibnos_syscall(SYSCALL_OBJECT_ATTACH_OBJ, (uint32_t)handle, (uint32_t)childHandle, mode, ident);
732  }
733 
734  static inline bool objectDetach(int32_t handle, uint32_t ident)
735  {
736  return ibnos_syscall(SYSCALL_OBJECT_DETACH_OBJ, (uint32_t)handle, ident);
737  }
738 
739  static inline int32_t consoleWrite(const char *buffer, uint32_t length)
740  {
741  return (int32_t)ibnos_syscall(SYSCALL_CONSOLE_WRITE, (uint32_t)buffer, length);
742  }
743 
744  static inline int32_t consoleWriteRaw(const uint16_t *buffer, uint32_t characters)
745  {
746  return (int32_t)ibnos_syscall(SYSCALL_CONSOLE_WRITE_RAW, (uint32_t)buffer, characters);
747  }
748 
749  static inline void consoleClear()
750  {
751  ibnos_syscall(SYSCALL_CONSOLE_CLEAR);
752  }
753 
754  static inline uint32_t consoleGetSize()
755  {
756  return ibnos_syscall(SYSCALL_CONSOLE_GET_SIZE);
757  }
758 
759  static inline void consoleSetColor(uint32_t value)
760  {
761  ibnos_syscall(SYSCALL_CONSOLE_SET_COLOR, value);
762  }
763 
764  static inline uint32_t consoleGetColor()
765  {
766  return ibnos_syscall(SYSCALL_CONSOLE_GET_COLOR);
767  }
768 
769  static inline void consoleSetCursor(uint32_t x, uint32_t y)
770  {
771  ibnos_syscall(SYSCALL_CONSOLE_SET_CURSOR, x, y);
772  }
773 
774  static inline uint32_t consoleGetCursor()
775  {
776  return ibnos_syscall(SYSCALL_CONSOLE_GET_CURSOR);
777  }
778 
779  static inline void consoleSetHardwareCursor(uint32_t x, uint32_t y)
780  {
781  ibnos_syscall(SYSCALL_CONSOLE_SET_HARDWARE_CURSOR, x, y);
782  }
783 
784  static inline uint32_t consoleGetHardwareCursor()
785  {
786  return ibnos_syscall(SYSCALL_CONSOLE_GET_HARDWARE_CURSOR);
787  }
788 
789  static inline void consoleSetFlags(uint32_t flags)
790  {
791  ibnos_syscall(SYSCALL_CONSOLE_SET_FLAGS, flags);
792  }
793 
794  static inline uint32_t consoleGetFlags()
795  {
796  return ibnos_syscall(SYSCALL_CONSOLE_GET_FLAGS);
797  }
798 
799  static inline int32_t filesystemSearchFile(int32_t handle, const char *path, uint32_t length, bool create)
800  {
801  return ibnos_syscall(SYSCALL_FILESYSTEM_SEARCH_FILE, (uint32_t)handle, (uint32_t)path, length, create);
802  }
803 
804  static inline int32_t filesystemSearchDirectory(int32_t handle, const char *path, uint32_t length, bool create)
805  {
806  return ibnos_syscall(SYSCALL_FILESYSTEM_SEARCH_DIRECTORY, (uint32_t)handle, (uint32_t)path, length, create);
807  }
808 
809  static inline int32_t filesystemOpen(int32_t handle)
810  {
811  return ibnos_syscall(SYSCALL_FILESYSTEM_OPEN, (uint32_t)handle);
812  }
813 
814 #endif
815 
818 #endif /* _H_SYSCALL_ */
uint32_t consoleGetSize()
Returns the packed size of the console.
Definition: console.c:454
#define objectSignal(p, a)
Definition: object.h:129
#define objectGetStatus(p, a)
Definition: object.h:117
#define objectShutdown(p, a)
Definition: object.h:111
uint32_t consoleGetHardwareCursor()
Get packed position of the hardware cursor.
Definition: console.c:513
bool wakeupAll
Definition: timer.h:57
#define objectWait(p, a, b)
Definition: object.h:123
void consoleSetColor(uint8_t color)
Set the text and background color of the console.
Definition: console.c:113
#define objectRead(p, a, b)
Definition: object.h:141
#define objectWrite(p, a, b)
Definition: object.h:135
void consoleClear()
Clear the screen contents.
Definition: console.c:90
uint8_t consoleGetColor()
Get current color.
Definition: console.c:124
void consoleSetHardwareCursor(uint8_t x, uint8_t y)
Set the position of the hardware cursor.
Definition: console.c:498
void consoleSetFlags(uint32_t flags)
Set console flags.
Definition: console.c:554
uint32_t value
Definition: paging.h:55
char mode[8]
Definition: filesystem.h:65
uint32_t consoleGetFlags()
Get console flags.
Definition: console.c:564