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

Subversion Repositories s6soc

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

Go to most recent revision | 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
        //              If the timeout == 0, does nothing.
60
        TRAPID_WAIT, TRAPID_CLEAR, TRAPID_POST,
61
        // Yield: Yields the processor until the next scheduled time slice.
62
        TRAPID_YIELD,
63
        TRAPID_READ, TRAPID_WRITE,
64
        TRAPID_TIME,
65
        // Return from a kernel system call.  This is necessary if ever an
66
        // exception triggers a syste call.  In such cases, it will be
67
        // impossible to return the caller back to his context in a pristine
68
        // manner ... without help.
69
        // TRAPID_KRETURN
70
        // Semaphore ID's.  These allow us to run the rest of the trap
71
        // stuffs in kernel space
72
        TRAPID_SEMGET, TRAPID_SEMPUT, TRAPID_SEMNEW,
73
        // Malloc--since we're using a system level malloc, from a system
74
        // heap for everything, malloc/free require system calls
75
        TRAPID_MALLOC, TRAPID_FREE,
76
        // EXIT -- end a task
77
        TRAPID_EXIT
78
} TRAPID;
79
 
80
extern  int     syscall(const int id, const int a, const int b, const int c);
81
 
82
static inline int       read(int fid, void *buf, int ln) {
83
        return syscall(TRAPID_READ, fid,(int)buf,ln);
84
} static inline int     write(int fid, const void *buf, int ln) {
85
        return syscall(TRAPID_WRITE, fid, (int)buf, ln);
86
}
87
 
88
static inline unsigned  time(void) {
89
        return syscall(TRAPID_TIME, 0,0,0);
90
}
91
 
92
static inline   void    yield(void) {
93
        syscall(TRAPID_YIELD, 0, 0, 0);
94
} static inline int     wait(unsigned event_mask, int timeout) {
95
        return syscall(TRAPID_WAIT, (int)event_mask, timeout, 0);
96
} static inline void    clear(unsigned event) {
97
        syscall(TRAPID_CLEAR, (int)event, 0, 0);
98
} static inline void    post(unsigned event) {
99
        syscall(TRAPID_POST, (int)event, 0, 0);
100
}
101
 
102
static inline   void *malloc(unsigned nbytes) {
103
        return (void *)syscall(TRAPID_MALLOC, (int)nbytes, 0, 0);
104
} static inline void    free(void *buf) {
105
        syscall(TRAPID_FREE,(int)buf,0,0);
106
}
107
 
108
static inline void      exit(int status) {
109
        syscall(TRAPID_EXIT,status,0,0);
110
}
111
 
112
#endif

powered by: WebSVN 2.1.0

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