OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [ktraps.h] - Blame information for rev 45

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    ktraps.h
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
#ifndef KTRAPS_H
39
#define KTRAPS_H
40
 
41
typedef enum {
42
        // First two deal with interrupts:
43
        //      syscall(TRAPID_WAIT, intmask, timeout, ?)
44
        //              returns when an interrupt in intmask has taken place
45
        //              may return immediately if such an interrupt has
46
        //              occurred between the last such syscall and this one
47
        //              If timeout is != 0, specifies the maximum amount of
48
        //                      time to wait for the event to occurr.
49
        //              If intmask = 0, then the task will wait for a timeout
50
        //                      alone.
51
        //              If the task is stalled for another reason, it may wake
52
        //                      early from the trap when the timeout is up.
53
        //      syscall(TRAPID_CLEAR, intmask, timeout, ?)
54
        //              Same thing, except this returns immediately after
55
        //              clearing any potentially pending interrupts
56
        //              If the timeout < 0, clears any pending timeout wakeup
57
        //              If the timeout > 0, sets a pending timeout wakeup and
58
        //                      returns.
59 45 dgisselq
        //              If the timeout == 0, clears the respective interrupt
60
        //                      slash event, and does nothing more.
61 22 dgisselq
        TRAPID_WAIT, TRAPID_CLEAR, TRAPID_POST,
62
        // Yield: Yields the processor until the next scheduled time slice.
63
        TRAPID_YIELD,
64
        TRAPID_READ, TRAPID_WRITE,
65
        TRAPID_TIME,
66
        // Return from a kernel system call.  This is necessary if ever an
67 45 dgisselq
        // exception triggers a system call.  In such cases, it will be
68 22 dgisselq
        // impossible to return the caller back to his context in a pristine
69
        // manner ... without help.
70 45 dgisselq
        // TRAPID_KRETURN,
71 22 dgisselq
        // Semaphore ID's.  These allow us to run the rest of the trap
72
        // stuffs in kernel space
73
        TRAPID_SEMGET, TRAPID_SEMPUT, TRAPID_SEMNEW,
74
        // Malloc--since we're using a system level malloc, from a system
75
        // heap for everything, malloc/free require system calls
76
        TRAPID_MALLOC, TRAPID_FREE,
77
        // EXIT -- end a task
78
        TRAPID_EXIT
79
} TRAPID;
80
 
81
extern  int     syscall(const int id, const int a, const int b, const int c);
82
 
83
static inline int       read(int fid, void *buf, int ln) {
84
        return syscall(TRAPID_READ, fid,(int)buf,ln);
85
} static inline int     write(int fid, const void *buf, int ln) {
86
        return syscall(TRAPID_WRITE, fid, (int)buf, ln);
87
}
88
 
89
static inline unsigned  time(void) {
90
        return syscall(TRAPID_TIME, 0,0,0);
91
}
92
 
93
static inline   void    yield(void) {
94
        syscall(TRAPID_YIELD, 0, 0, 0);
95
} static inline int     wait(unsigned event_mask, int timeout) {
96
        return syscall(TRAPID_WAIT, (int)event_mask, timeout, 0);
97 44 dgisselq
} static inline int     clear(unsigned event, int timeout) {
98
        return syscall(TRAPID_CLEAR, (int)event, timeout, 0);
99 22 dgisselq
} static inline void    post(unsigned event) {
100
        syscall(TRAPID_POST, (int)event, 0, 0);
101
}
102
 
103
static inline   void *malloc(unsigned nbytes) {
104
        return (void *)syscall(TRAPID_MALLOC, (int)nbytes, 0, 0);
105
} static inline void    free(void *buf) {
106
        syscall(TRAPID_FREE,(int)buf,0,0);
107
}
108
 
109
static inline void      exit(int status) {
110
        syscall(TRAPID_EXIT,status,0,0);
111
}
112
 
113
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.