1 |
52 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: zipsystem.c
|
4 |
|
|
//
|
5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
6 |
|
|
//
|
7 |
|
|
// Purpose: Implements some ZipCPU specific functions. Specifically, these
|
8 |
|
|
// are the system call trap (which just switches to supervisor
|
9 |
|
|
// mode), and the two context switching functions.
|
10 |
|
|
//
|
11 |
|
|
//
|
12 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
13 |
|
|
// Gisselquist Technology, LLC
|
14 |
|
|
//
|
15 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
16 |
|
|
//
|
17 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
18 |
|
|
//
|
19 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
20 |
|
|
// modify it under the terms of the GNU General Public License as published
|
21 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
22 |
|
|
// your option) any later version.
|
23 |
|
|
//
|
24 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
25 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
26 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
27 |
|
|
// for more details.
|
28 |
|
|
//
|
29 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
30 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
31 |
|
|
//
|
32 |
|
|
//
|
33 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
//
|
35 |
|
|
//
|
36 |
|
|
#include "zipcpu.h"
|
37 |
|
|
|
38 |
|
|
// Implement a save_context function. This really boils into a long series of
|
39 |
|
|
// instructions within the compiler. For this reason, it makes more sense
|
40 |
|
|
// for it to be a function call rather than an inline function--although
|
41 |
|
|
// zip_save_context could be either. Of course, the difficult part of placing
|
42 |
|
|
// it in line is that the CPU may not realize the context changes between one
|
43 |
|
|
// invocation of save_context and the corresponding restore_context function...
|
44 |
|
|
void save_context(int *c) {
|
45 |
|
|
zip_save_context(c);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
void restore_context(int *c) {
|
49 |
|
|
zip_restore_context(c);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
#ifdef C_SYSCALL
|
53 |
|
|
/* While the following system call *should* be identical to the assembly
|
54 |
|
|
* equivalent beneath it, the dependency is actually dependent upon any
|
55 |
|
|
* optimizations within the compiler. If the compiler is not optimized,
|
56 |
|
|
* then it may try to create a stack frame, store id, a, b, and c, on the
|
57 |
|
|
* stack frame, call the system call, clear the stack frame and return.
|
58 |
|
|
*
|
59 |
|
|
* The problem with this is that system traps may believe that they can replace
|
60 |
|
|
* the system call with a goto. In that case, there is no knowledge of the
|
61 |
|
|
* stack frame that needs to be unwound. Hence, we need to make certain that
|
62 |
|
|
* the system call does not create a stack frame, and thus use the assembly
|
63 |
|
|
* form beneath here.
|
64 |
|
|
*/
|
65 |
|
|
int syscall(const int id, const int a, const int b, const int c) {
|
66 |
|
|
zip_syscall();
|
67 |
|
|
}
|
68 |
|
|
#else
|
69 |
|
|
/* By making this into an assembly language equivalent, we can be specific about
|
70 |
|
|
* what we are expecting. That way the kernel can just set the PC address and
|
71 |
|
|
* the system call may believe that it was called like any ordinary subroutine.
|
72 |
|
|
*/
|
73 |
|
|
asm(ASMFNSTR("syscall")
|
74 |
|
|
"\tCLR\tCC\n"
|
75 |
|
|
"\tRETN\n"
|
76 |
|
|
);
|
77 |
|
|
#endif
|
78 |
|
|
|
79 |
|
|
|