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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [zipsys.c] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    zipsystem.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
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
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
 
41
#include "zipsys.h"
42
 
43
// Implement a save_context function.  This really boils into a long series of
44
// instructions within the compiler.  For this reason, it makes more sense
45
// for it to be a function call rather than an inline function--although
46
// zip_save_context could be either.  Of course, the difficult part of placing
47
// it in line is that the CPU may not realize the context changes between one
48
// invocation of save_context and the corresponding restore_context function...
49
void    save_context(int *c) {
50
        zip_save_context(c);
51
}
52
 
53
void    restore_context(int *c) {
54
        zip_restore_context(c);
55
}
56
 
57
#ifdef  C_SYSCALL
58
/* While the following system call *should* be identical to the assembly
59
 * equivalent beneath it, the dependency is actually dependent upon any
60
 * optimizations within the compiler.  If the compiler is not optimized,
61
 * then it may try to create a stack frame, store id, a, b, and c, on the
62
 * stack frame, call the system call, clear the stack frame and return.
63
 *
64
 * The problem with this is that system traps may believe that they can replace
65
 * the system call with a goto.  In that case, there is no knowledge of the
66
 * stack frame that needs to be unwound.  Hence, we need to make certain that
67
 * the system call does not create a stack frame, and thus use the assembly
68
 * form beneath here.
69
 */
70
int     syscall(const int id, const int a, const int b, const int c) {
71
        zip_syscall();
72
}
73
#else
74
/* By making this into an assembly language equivalent, we can be specific about
75
 * what we are expecting.  That way the kernel can just set the PC address and
76
 * the system call may believe that it was called like any ordinary subroutine.
77
 */
78
asm("\t.section\t.text\n"
79
"\t.global\tsyscall\n"
80
"syscall:\n"
81
"\tCLR\tCC\n"
82
"\tJMP\tR0\n"
83
);
84
#endif
85
 
86
 

powered by: WebSVN 2.1.0

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