;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;
|
;
|
; Filename: sys.i
|
; Filename: sys.i
|
;
|
;
|
; Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
; Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
;
|
;
|
; Purpose: This is the beginnings of a system wide header file for the
|
; Purpose: This is the beginnings of a system wide header file for the
|
; Zip System. It describes and declares the peripherals
|
; Zip System. It describes and declares the peripherals
|
; that will the be used and referenced by the assembly files.
|
; that will the be used and referenced by the assembly files.
|
;
|
;
|
; Status: As of August, 2015, I have no confidence that the preprocessor
|
; Status: As of August, 2015, I have no confidence that the preprocessor
|
; can properly include this file. It certainly cannot handle
|
; can properly include this file. It certainly cannot handle
|
; macros (yet).
|
; macros (yet).
|
;
|
;
|
; Creator: Dan Gisselquist, Ph.D.
|
; Creator: Dan Gisselquist, Ph.D.
|
; Gisselquist Tecnology, LLC
|
; Gisselquist Technology, LLC
|
;
|
;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;
|
;
|
; Copyright (C) 2015, Gisselquist Technology, LLC
|
; Copyright (C) 2015, Gisselquist Technology, LLC
|
;
|
;
|
; This program is free software (firmware): you can redistribute it and/or
|
; This program is free software (firmware): you can redistribute it and/or
|
; modify it under the terms of the GNU General Public License as published
|
; modify it under the terms of the GNU General Public License as published
|
; by the Free Software Foundation, either version 3 of the License, or (at
|
; by the Free Software Foundation, either version 3 of the License, or (at
|
; your option) any later version.
|
; your option) any later version.
|
;
|
;
|
; This program is distributed in the hope that it will be useful, but WITHOUT
|
; This program is distributed in the hope that it will be useful, but WITHOUT
|
; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
; for more details.
|
; for more details.
|
;
|
;
|
; License: GPL, v3, as defined and found on www.gnu.org,
|
; License: GPL, v3, as defined and found on www.gnu.org,
|
; http://www.gnu.org/licenses/gpl.html
|
; http://www.gnu.org/licenses/gpl.html
|
;
|
;
|
;
|
;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;
|
;
|
sys.bus equ 0xc0000000
|
sys.bus equ 0xc0000000
|
sys.breaken equ 0x080
|
sys.breaken equ 0x080
|
sys.step equ 0x040
|
sys.step equ 0x040
|
sys.gie equ 0x020
|
sys.gie equ 0x020
|
sys.sleep equ 0x010
|
sys.sleep equ 0x010
|
sys.ccv equ 0x008
|
sys.ccv equ 0x008
|
sys.ccn equ 0x004
|
sys.ccn equ 0x004
|
sys.ccc equ 0x002
|
sys.ccc equ 0x002
|
sys.ccz equ 0x001
|
sys.ccz equ 0x001
|
sys.bus.pic equ 0x000
|
sys.bus.pic equ 0x000
|
sys.bus.wdt equ 0x001
|
sys.bus.wdt equ 0x001
|
sys.bus.cache equ 0x002
|
sys.bus.cache equ 0x002
|
sys.bus.ctrpic equ 0x003
|
sys.bus.ctrpic equ 0x003
|
sys.bus.tma equ 0x004
|
sys.bus.tma equ 0x004
|
sys.bus.tmb equ 0x005
|
sys.bus.tmb equ 0x005
|
sys.bus.tmc equ 0x006
|
sys.bus.tmc equ 0x006
|
|
|
|
|
|
|
; Define the location(s) of our peripherals,
|
; Define the location(s) of our peripherals,
|
#define sys.base 0xc0000000
|
#define sys.base 0xc0000000
|
#define sys.cache.base 0xc0100000
|
#define sys.cache.base 0xc0100000
|
#struct sys
|
#struct sys
|
pic
|
pic
|
wdt
|
wdt
|
cache
|
cache
|
ctrpic
|
ctrpic
|
tma
|
tma
|
tmb
|
tmb
|
tmc
|
tmc
|
jiffies
|
jiffies
|
mtask
|
mtask
|
mstl
|
mstl
|
mpstl
|
mpstl
|
mastl
|
mastl
|
utask
|
utask
|
ustl
|
ustl
|
upstl
|
upstl
|
uastl
|
uastl
|
#endstruct
|
#endstruct
|
; and their associated interrupt vectors ...
|
; and their associated interrupt vectors ...
|
#define CACHEINT 0x01
|
#define CACHEINT 0x01
|
#define JIFFYINT 0x02 ;
|
#define JIFFYINT 0x02 ;
|
#define TMCINT 0x04 ;
|
#define TMCINT 0x04 ;
|
#define TMBINT 0x08 ;
|
#define TMBINT 0x08 ;
|
#define TMAINT 0x10 ;
|
#define TMAINT 0x10 ;
|
#define CTRPICINT 0x20 ; The aux interrupt controller
|
#define CTRPICINT 0x20 ; The aux interrupt controller
|
; Masks to send to enable those same vectors
|
; Masks to send to enable those same vectors
|
#define CACHEINTEN 0x80010000
|
#define CACHEINTEN 0x80010000
|
#define JIFFYINTEN 0x80020000
|
#define JIFFYINTEN 0x80020000
|
#define TMCINTEN 0x80040000
|
#define TMCINTEN 0x80040000
|
#define TMBINTEN 0x80080000
|
#define TMBINTEN 0x80080000
|
#define TMAINTEN 0x80100000
|
#define TMAINTEN 0x80100000
|
#define CTRPICEN 0x80200000
|
#define CTRPICEN 0x80200000
|
; And similar masks to disable them
|
; And similar masks to disable them
|
#define CACHEINTDIS 0x00010000
|
#define CACHEINTDIS 0x00010000
|
#define JIFFYINTDIS 0x00020000
|
#define JIFFYINTDIS 0x00020000
|
#define TMCINTDIS 0x00040000
|
#define TMCINTDIS 0x00040000
|
#define TMBINTDIS 0x00080000
|
#define TMBINTDIS 0x00080000
|
#define TMAINTDIS 0x00100000
|
#define TMAINTDIS 0x00100000
|
#define CTRPICDIS 0x00200000
|
#define CTRPICDIS 0x00200000
|
|
|
; Define our condition code bits
|
; Define our condition code bits
|
#define CCZ 0x001
|
#define CCZ 0x001
|
#define CCC 0x002
|
#define CCC 0x002
|
#define CCN 0x004
|
#define CCN 0x004
|
#define CCV 0x008
|
#define CCV 0x008
|
#define CCSLEEP 0x010
|
#define CCSLEEP 0x010
|
#define CCGIE 0x020
|
#define CCGIE 0x020
|
#define CCSTEP 0x040
|
#define CCSTEP 0x040
|
#define CCUBRK 0x080
|
#define CCUBRK 0x080
|
|
|
; Now, some macros
|
; Now, some macros
|
#define PUSH(RG,SP) SUB 1,SP \
|
#define PUSH(RG,SP) SUB 1,SP \
|
STO RG,1(SP)
|
STO RG,1(SP)
|
#define POP(RG,SP) LOD 1(SP),RG \
|
#define POP(RG,SP) LOD 1(SP),RG \
|
ADD 1,SP
|
ADD 1,SP
|
#define FJSR(LBL,RG) MOV __here__+2(PC),RG \
|
#define FJSR(LBL,RG) MOV __here__+2(PC),RG \
|
BRA LBL
|
BRA LBL
|
#define FRET(RG) MOV RG,PC
|
#define FRET(RG) MOV RG,PC
|
#define JSR(LBL,RG) SUB 1,SP \
|
#define JSR(LBL,RG) SUB 1,SP \
|
MOV __here__+3(PC),RG \
|
MOV __here__+3(PC),RG \
|
STO RG,1(SP) \
|
STO RG,1(SP) \
|
BRA LBL \
|
BRA LBL \
|
ADD 1,SP
|
ADD 1,SP
|
|
|
#define RET LOD 1(SP),PC
|
#define RET LOD 1(SP),PC
|
#define SAVE_USER_CONTEXT(DR,AR) \
|
#define SAVE_USER_CONTEXT(DA,DB,DC,DD,AR) \
|
MOV -15(uSP),AR \
|
MOV -15(uSP),AR \
|
MOV uPC,DR \
|
MOV uR0,DA \
|
STO DR,15(AR) \
|
MOV uR1,DB \
|
MOV uCC,DR \
|
MOV uR2,DC \
|
STO DR,14(AR) \
|
MOV uR3,DD \
|
MOV uR12,DR \
|
STO DA,(AR) \
|
STO DR,13(AR) \
|
STO DB,1(AR) \
|
MOV uR11,DR \
|
STO DC,2(AR) \
|
STO DR,12(AR) \
|
STO DD,3(AR) \
|
MOV uR10,DR \
|
MOV uR4,DA \
|
STO DR,11(AR) \
|
MOV uR5,DB \
|
MOV uR9,DR \
|
MOV uR6,DC \
|
STO DR,10(AR) \
|
MOV uR7,DD \
|
MOV uR8,DR \
|
STO DA,4(AR) \
|
STO DR,9(AR) \
|
STO DB,5(AR) \
|
MOV uR7,DR \
|
STO DC,6(AR) \
|
STO DR,8(AR) \
|
STO DD,7(AR) \
|
MOV uR6,DR \
|
MOV uR8,DA \
|
STO DR,7(AR) \
|
MOV uR9,DB \
|
MOV uR5,DR \
|
MOV uR10,DC \
|
STO DR,6(AR) \
|
MOV uR11,DD \
|
MOV uR4,DR \
|
STO DA,8(AR) \
|
STO DR,5(AR) \
|
STO DB,9(AR) \
|
MOV uR3,DR \
|
STO DC,10(AR) \
|
STO DR,4(AR) \
|
STO DD,11(AR) \
|
MOV uR2,DR \
|
MOV uR12,DA \
|
STO DR,3(AR) \
|
MOV uCC,DC \
|
MOV uR1,DR \
|
MOV uPC,DD \
|
STO DR,2(AR) \
|
STO DA,12(AR) \
|
MOV uR0,DR \
|
STO DC,13(AR) \
|
STO DR,1(AR)
|
STO DD,14(AR)
|
#define RESTORE_USER_CONTEXT(DR,AR) \
|
#define RESTORE_USER_CONTEXT(DA,DB,DC,DD,AR) \
|
LOD 1(AR),DR \
|
LOD (AR),DA \
|
MOV DR,uR0 \
|
LOD 1(AR),DB \
|
LOD 2(AR),DR \
|
LOD 2(AR),DC \
|
MOV DR,uR1 \
|
LOD 3(AR),DD \
|
LOD 3(AR),DR \
|
MOV DA,uR0 \
|
MOV DR,uR2 \
|
MOV DB,uR1 \
|
LOD 4(AR),DR \
|
MOV DC,uR2 \
|
MOV DR,uR3 \
|
MOV DD,uR3 \
|
LOD 5(AR),DR \
|
LOD 4(AR),DA \
|
MOV DR,uR4 \
|
LOD 5(AR),DB \
|
LOD 6(AR),DR \
|
LOD 6(AR),DC \
|
MOV DR,uR5 \
|
LOD 7(AR),DD \
|
LOD 7(AR),DR \
|
MOV DA,uR4 \
|
MOV DR,uR6 \
|
MOV DB,uR5 \
|
LOD 8(AR),DR \
|
MOV DC,uR6 \
|
MOV DR,uR7 \
|
MOV DD,uR7 \
|
LOD 9(AR),DR \
|
LOD 8(AR),DA \
|
MOV DR,uR8 \
|
LOD 9(AR),DB \
|
LOD 10(AR),DR \
|
LOD 10(AR),DC \
|
MOV DR,uR9 \
|
LOD 11(AR),DD \
|
LOD 11(AR),DR \
|
MOV DA,uR8 \
|
MOV DR,uR10 \
|
MOV DB,uR9 \
|
LOD 12(AR),DR \
|
MOV DC,uR10 \
|
MOV DR,uR11 \
|
MOV DD,uR11 \
|
LOD 13(AR),DR \
|
LOD 12(AR),DA \
|
MOV DR,uR12 \
|
LOD 13(AR),DB \
|
LOD 14(AR),DR \
|
LOD 14(AR),DC \
|
MOV DR,uCC \
|
MOV DA,uR12 \
|
LOD 15(AR),DR \
|
MOV DB,uCC \
|
MOV DR,uPC
|
MOV DC,uPC \
|
|
MOV 15(AR),uSP
|
#define READ_USER_TRAP(RG) \
|
#define READ_USER_TRAP(RG) \
|
MOV uCC,RG \
|
MOV uCC,RG \
|
AND -256,RG
|
AND -256,RG
|
|
|
|
|