From 83334549fbcd15f7be6931176473639fe9e3960f Mon Sep 17 00:00:00 2001 From: marcus Date: Mon, 11 Dec 2000 18:19:12 +0000 Subject: [PATCH] Initial import of port "dreamcast" (cloned from port "evbsh3"). --- etc/etc.dreamcast/MAKEDEV | 318 ++++ etc/etc.dreamcast/disktab | 44 + etc/etc.dreamcast/fstab.md | 2 + etc/etc.dreamcast/ttys | 48 + sys/arch/dreamcast/Makefile | 30 + sys/arch/dreamcast/conf/GENERIC | 140 ++ sys/arch/dreamcast/conf/GENERIC.local | 5 + sys/arch/dreamcast/conf/Makefile.dreamcast | 221 +++ sys/arch/dreamcast/conf/files.dreamcast | 16 + sys/arch/dreamcast/conf/files.shbus | 69 + sys/arch/dreamcast/conf/shl.x | 56 + sys/arch/dreamcast/conf/shl.x.ICE | 50 + sys/arch/dreamcast/conf/shl.x.RAM | 50 + sys/arch/dreamcast/conf/shl.x.ROM | 33 + sys/arch/dreamcast/conf/std.dreamcast | 7 + sys/arch/dreamcast/dreamcast/conf.c | 326 ++++ sys/arch/dreamcast/dreamcast/genassym.cf | 110 ++ sys/arch/dreamcast/dreamcast/locore.s | 1722 +++++++++++++++++++ sys/arch/dreamcast/dreamcast/machdep.c | 1241 +++++++++++++ sys/arch/dreamcast/dreamcast/shb.c | 849 +++++++++ sys/arch/dreamcast/include/Makefile | 14 + sys/arch/dreamcast/include/ansi.h | 7 + sys/arch/dreamcast/include/aout_machdep.h | 7 + sys/arch/dreamcast/include/asm.h | 7 + sys/arch/dreamcast/include/bootinfo.h | 7 + sys/arch/dreamcast/include/bswap.h | 7 + sys/arch/dreamcast/include/bus.h | 7 + sys/arch/dreamcast/include/cdefs.h | 7 + sys/arch/dreamcast/include/coff_machdep.h | 7 + sys/arch/dreamcast/include/conf.h | 47 + sys/arch/dreamcast/include/cpu.h | 7 + sys/arch/dreamcast/include/cpufunc.h | 7 + sys/arch/dreamcast/include/cputypes.h | 7 + sys/arch/dreamcast/include/db_machdep.h | 7 + sys/arch/dreamcast/include/disklabel.h | 7 + sys/arch/dreamcast/include/elf_machdep.h | 7 + sys/arch/dreamcast/include/endian.h | 3 + sys/arch/dreamcast/include/endian_machdep.h | 8 + sys/arch/dreamcast/include/float.h | 7 + sys/arch/dreamcast/include/frame.h | 7 + sys/arch/dreamcast/include/ieee.h | 7 + sys/arch/dreamcast/include/ieeefp.h | 7 + sys/arch/dreamcast/include/int_types.h | 3 + sys/arch/dreamcast/include/intr.h | 39 + sys/arch/dreamcast/include/limits.h | 7 + sys/arch/dreamcast/include/lock.h | 4 + sys/arch/dreamcast/include/math.h | 3 + sys/arch/dreamcast/include/mmeye.h | 23 + sys/arch/dreamcast/include/param.h | 186 ++ sys/arch/dreamcast/include/pcb.h | 7 + sys/arch/dreamcast/include/pio.h | 7 + sys/arch/dreamcast/include/pmap.h | 7 + sys/arch/dreamcast/include/proc.h | 7 + sys/arch/dreamcast/include/profile.h | 7 + sys/arch/dreamcast/include/psl.h | 7 + sys/arch/dreamcast/include/pte.h | 7 + sys/arch/dreamcast/include/ptrace.h | 7 + sys/arch/dreamcast/include/reg.h | 7 + sys/arch/dreamcast/include/segments.h | 7 + sys/arch/dreamcast/include/setjmp.h | 7 + sys/arch/dreamcast/include/shbvar.h | 7 + sys/arch/dreamcast/include/signal.h | 7 + sys/arch/dreamcast/include/stdarg.h | 7 + sys/arch/dreamcast/include/trap.h | 7 + sys/arch/dreamcast/include/types.h | 7 + sys/arch/dreamcast/include/varargs.h | 7 + sys/arch/dreamcast/include/vmparam.h | 7 + 67 files changed, 5926 insertions(+) create mode 100755 etc/etc.dreamcast/MAKEDEV create mode 100644 etc/etc.dreamcast/disktab create mode 100644 etc/etc.dreamcast/fstab.md create mode 100644 etc/etc.dreamcast/ttys create mode 100644 sys/arch/dreamcast/Makefile create mode 100644 sys/arch/dreamcast/conf/GENERIC create mode 100644 sys/arch/dreamcast/conf/GENERIC.local create mode 100644 sys/arch/dreamcast/conf/Makefile.dreamcast create mode 100644 sys/arch/dreamcast/conf/files.dreamcast create mode 100644 sys/arch/dreamcast/conf/files.shbus create mode 100644 sys/arch/dreamcast/conf/shl.x create mode 100644 sys/arch/dreamcast/conf/shl.x.ICE create mode 100644 sys/arch/dreamcast/conf/shl.x.RAM create mode 100644 sys/arch/dreamcast/conf/shl.x.ROM create mode 100644 sys/arch/dreamcast/conf/std.dreamcast create mode 100644 sys/arch/dreamcast/dreamcast/conf.c create mode 100644 sys/arch/dreamcast/dreamcast/genassym.cf create mode 100644 sys/arch/dreamcast/dreamcast/locore.s create mode 100644 sys/arch/dreamcast/dreamcast/machdep.c create mode 100644 sys/arch/dreamcast/dreamcast/shb.c create mode 100644 sys/arch/dreamcast/include/Makefile create mode 100644 sys/arch/dreamcast/include/ansi.h create mode 100644 sys/arch/dreamcast/include/aout_machdep.h create mode 100644 sys/arch/dreamcast/include/asm.h create mode 100644 sys/arch/dreamcast/include/bootinfo.h create mode 100644 sys/arch/dreamcast/include/bswap.h create mode 100644 sys/arch/dreamcast/include/bus.h create mode 100644 sys/arch/dreamcast/include/cdefs.h create mode 100644 sys/arch/dreamcast/include/coff_machdep.h create mode 100644 sys/arch/dreamcast/include/conf.h create mode 100644 sys/arch/dreamcast/include/cpu.h create mode 100644 sys/arch/dreamcast/include/cpufunc.h create mode 100644 sys/arch/dreamcast/include/cputypes.h create mode 100644 sys/arch/dreamcast/include/db_machdep.h create mode 100644 sys/arch/dreamcast/include/disklabel.h create mode 100644 sys/arch/dreamcast/include/elf_machdep.h create mode 100644 sys/arch/dreamcast/include/endian.h create mode 100644 sys/arch/dreamcast/include/endian_machdep.h create mode 100644 sys/arch/dreamcast/include/float.h create mode 100644 sys/arch/dreamcast/include/frame.h create mode 100644 sys/arch/dreamcast/include/ieee.h create mode 100644 sys/arch/dreamcast/include/ieeefp.h create mode 100644 sys/arch/dreamcast/include/int_types.h create mode 100644 sys/arch/dreamcast/include/intr.h create mode 100644 sys/arch/dreamcast/include/limits.h create mode 100644 sys/arch/dreamcast/include/lock.h create mode 100644 sys/arch/dreamcast/include/math.h create mode 100644 sys/arch/dreamcast/include/mmeye.h create mode 100644 sys/arch/dreamcast/include/param.h create mode 100644 sys/arch/dreamcast/include/pcb.h create mode 100644 sys/arch/dreamcast/include/pio.h create mode 100644 sys/arch/dreamcast/include/pmap.h create mode 100644 sys/arch/dreamcast/include/proc.h create mode 100644 sys/arch/dreamcast/include/profile.h create mode 100644 sys/arch/dreamcast/include/psl.h create mode 100644 sys/arch/dreamcast/include/pte.h create mode 100644 sys/arch/dreamcast/include/ptrace.h create mode 100644 sys/arch/dreamcast/include/reg.h create mode 100644 sys/arch/dreamcast/include/segments.h create mode 100644 sys/arch/dreamcast/include/setjmp.h create mode 100644 sys/arch/dreamcast/include/shbvar.h create mode 100644 sys/arch/dreamcast/include/signal.h create mode 100644 sys/arch/dreamcast/include/stdarg.h create mode 100644 sys/arch/dreamcast/include/trap.h create mode 100644 sys/arch/dreamcast/include/types.h create mode 100644 sys/arch/dreamcast/include/varargs.h create mode 100644 sys/arch/dreamcast/include/vmparam.h diff --git a/etc/etc.dreamcast/MAKEDEV b/etc/etc.dreamcast/MAKEDEV new file mode 100755 index 000000000000..f76cba05f7f7 --- /dev/null +++ b/etc/etc.dreamcast/MAKEDEV @@ -0,0 +1,318 @@ +#!/bin/sh - +# +# $NetBSD: MAKEDEV,v 1.1 2000/12/11 18:19:16 marcus Exp $ +# +# Copyright (c) 1990 The Regents of the University of California. +# All rights reserved. +# +# Written and contributed by W. Jolitz 12/90 +# +# Redistribution and use in source and binary forms are permitted provided +# that: (1) source distributions retain this entire copyright notice and +# comment, and (2) distributions including binaries display the following +# acknowledgement: ``This product includes software developed by the +# University of California, Berkeley and its contributors'' in the +# documentation or other materials provided with the distribution and in +# all advertising materials mentioning features or use of this software. +# Neither the name of the University nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# +# @(#)MAKEDEV 5.2 (Berkeley) 6/22/90 +# +# Device "make" file. Valid arguments: +# all makes all known devices, including local devices. +# Tries to make the 'standard' number of each type. +# floppy devices to be put on install floppies +# std standard devices +# local configuration specific devices +# +# Tapes: +# wt* QIC-interfaced (e.g. not SCSI) 3M cartridge tape +# st* SCSI tapes +# +# Disks: +# wd* "winchester" disk drives (ST506,IDE,ESDI,RLL,...) +# fd* "floppy" disk drives (3 1/2", 5 1/4") +# sd* SCSI disks +# cd* SCSI CD-ROM +# mcd* Mitsumi CD-ROM +# vnd* "file" pseudo-disks +# md* memory pseudo-disks +# ccd* contatenated disk devices +# +# Console ports: +# ttyv0 pccons or pcvt screen 0 +# ttyv* pcvt +# +# Terminal ports: +# com* standard PC COM ports (XXX) +# tty* alias for PC COM ports, this is what the system really wants +# +# Pseudo terminals: +# pty* set of 16 master and slave pseudo terminals +# +# Call units: +# +# Special purpose devices: +# fd file descriptors +# bpf* packet filter +# ipl ip filter +# cbq Alternate Queueing (ALTQ) +# random Random number generator +# speaker pc speaker (XXX - installed) +# lkm loadable kernel modules interface +# audio audio device +# apm power management device +# tun* network tunnel driver +# joy* joystick device +# ss* SCSI scanner +# uk* SCSI unknown +# ch* SCSI changer +# + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +umask 77 +for i +do +case $i in + +all) + sh $0 std fd fd0 + sh $0 tty0 tty1 pty0 pty1 + sh $0 vnd0 vnd1 + sh $0 ttyv0 bpf0 bpf1 bpf2 bpf3 tun0 tun1 ipl + sh $0 ccd0 ccd1 ccd2 ccd3 md0 random + sh $0 lkm audio local + sh $0 ttyv0 ttyv1 ttyv2 ttyv3 ttyv4 ttyv5 ttyv6 ttyv7 ttyv8 + ;; + +ramdisk) + sh $0 std md0 + sh $0 tty0 tty1 pty0 pty1 + sh $0 ttyv0 bpf0 bpf1 bpf2 bpf3 tun0 tun1 ipl + ;; + +std) + rm -f console drum mem kmem null zero io tty klog stdin stdout stderr + mknod console c 0 0 + mknod drum c 4 0 ; chmod 640 drum ; chgrp kmem drum + mknod kmem c 2 1 ; chmod 640 kmem ; chgrp kmem kmem + mknod mem c 2 0 ; chmod 640 mem ; chgrp kmem mem + mknod null c 2 2 ; chmod 666 null + mknod zero c 2 12 ; chmod 666 zero + mknod io c 2 14 ; chmod 640 io ; chgrp kmem io + mknod tty c 1 0 ; chmod 666 tty + mknod klog c 7 0 ; chmod 600 klog + mknod stdin c 22 0 ; chmod 666 stdin + mknod stdout c 22 1 ; chmod 666 stdout + mknod stderr c 22 2 ; chmod 666 stderr + ;; + +ttyv*) + chr=12; unit=${i#ttyv} + rm -f ttyv$unit + mknod ttyv$unit c $chr $unit + chown root.wheel ttyv$unit +# case $unit in +# 0) +# rm -f vga +# ln -s ttyv0 vga +# ;; +# esac + ;; + +fd) + rm -f fd/* + mkdir fd > /dev/null 2>&1 + n=0 + while [ $n -lt 64 ]; do + mknod fd/$n c 22 $n + n=$(($n + 1)) + done + chown -R root.wheel fd + chmod 755 fd + chmod 666 fd/* + ;; + +md*) + case $i in + md*) name=md; unit=${i#md}; chr=24; blk=17;; + esac + rm -f $name$unit? r$name$unit? + mknod ${name}${unit}a b $blk $(($unit * 8 + 0)) + mknod ${name}${unit}b b $blk $(($unit * 8 + 1)) + mknod ${name}${unit}c b $blk $(($unit * 8 + 2)) + mknod r${name}${unit}a c $chr $(($unit * 8 + 0)) + mknod r${name}${unit}b c $chr $(($unit * 8 + 1)) + mknod r${name}${unit}c c $chr $(($unit * 8 + 2)) + chgrp operator $name$unit? r$name$unit? + chmod 640 $name$unit? r$name$unit? + ;; + +ccd*|fd*|sd*|vnd*|wd*) + case $i in + ccd*) name=ccd; unit=${i#ccd}; blk=16; chr=18;; + fd*) name=fd; unit=${i#fd}; blk=2; chr=9;; + sd*) name=sd; unit=${i#sd}; blk=4; chr=13;; + vnd*) name=vnd; unit=${i#vnd}; blk=14; chr=41;; + wd*) name=wd; unit=${i#wd}; blk=0; chr=3;; + esac + rm -f $name$unit? r$name$unit? + mknod ${name}${unit}a b $blk $(($unit * 8 + 0)) + mknod ${name}${unit}b b $blk $(($unit * 8 + 1)) + mknod ${name}${unit}c b $blk $(($unit * 8 + 2)) + mknod ${name}${unit}d b $blk $(($unit * 8 + 3)) + mknod ${name}${unit}e b $blk $(($unit * 8 + 4)) + mknod ${name}${unit}f b $blk $(($unit * 8 + 5)) + mknod ${name}${unit}g b $blk $(($unit * 8 + 6)) + mknod ${name}${unit}h b $blk $(($unit * 8 + 7)) + mknod r${name}${unit}a c $chr $(($unit * 8 + 0)) + mknod r${name}${unit}b c $chr $(($unit * 8 + 1)) + mknod r${name}${unit}c c $chr $(($unit * 8 + 2)) + mknod r${name}${unit}d c $chr $(($unit * 8 + 3)) + mknod r${name}${unit}e c $chr $(($unit * 8 + 4)) + mknod r${name}${unit}f c $chr $(($unit * 8 + 5)) + mknod r${name}${unit}g c $chr $(($unit * 8 + 6)) + mknod r${name}${unit}h c $chr $(($unit * 8 + 7)) + chgrp operator $name$unit? r$name$unit? + chmod 640 $name$unit? r$name$unit? + ;; + +com*|tty*) # (XXX -- com should die) + unit=${i#???} + rm -f com$unit tty0$unit + mknod tty0$unit c 8 $unit + chown uucp.wheel tty0$unit + ;; + +pty*) + class=${i#pty} + case $class in + 0) name=p;; + 1) name=q;; + 2) name=r;; + 3) name=s;; + 4) name=t;; + 5) name=u;; + 6) name=v + echo "$0: $i: pty unit conflicts with console ttyv* devices." + continue;; + 7) name=w;; + 8) name=x;; + 9) name=y;; + 10) name=z;; + 11) name=P;; + 12) name=Q;; + 13) name=R;; + 14) name=S;; + 15) name=T;; + *) echo "$0: $i: pty unit must be between 0 and 15" + continue ;; + esac + rm -f tty$name[0-9a-f] pty$name[0-9a-f] + for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f + do + case $j in + [0-9]) jn=$j ;; + a) jn=10 ;; + b) jn=11 ;; + c) jn=12 ;; + d) jn=13 ;; + e) jn=14 ;; + f) jn=15 ;; + esac + unit=$(($class * 16 + $jn)) + mknod tty$name$j c 5 $unit + mknod pty$name$j c 6 $unit + done + chgrp wheel tty$name? pty$name? + chmod 666 tty$name? pty$name? + ;; + +cd*|mcd*) + case $i in + cd*) name=cd; unit=${i#cd}; chr=15; blk=6;; + mcd*) name=mcd; unit=${i#mcd}; chr=39; blk=7;; + esac + rm -f $name$unit? r$name$unit? + mknod ${name}${unit}a b $blk $(($unit * 8 + 0)) + mknod ${name}${unit}d b $blk $(($unit * 8 + 3)) + mknod r${name}${unit}a c $chr $(($unit * 8 + 0)) + mknod r${name}${unit}d c $chr $(($unit * 8 + 3)) + chgrp operator $name$unit? r$name$unit? + chmod 640 $name$unit? r$name$unit? + ;; + +bpf*|tun*|mms*|lms*|pms*|joy*) + case $i in + bpf*) name=bpf; unit=${i#bpf}; chr=23;; + tun*) name=tun; unit=${i#tun}; chr=40;; + mms*) name=mms; unit=${i#mms}; chr=35;; + lms*) name=lms; unit=${i#lms}; chr=36;; + pms*) name=pms; unit=${i#pms}; chr=37;; + joy*) name=joy; unit=${i#joy}; chr=26;; + esac + rm -f $name$unit + mknod $name$unit c $chr $unit + chown root.wheel $name$unit + ;; + +ipl) + rm -f ipl ipnat ipstate ipauth + mknod ipl c 44 0 + mknod ipnat c 44 1 + mknod ipstate c 44 2 + mknod ipauth c 44 3 + chown root.wheel ipl ipnat ipstate ipauth + chmod 600 ipl ipnat ipstate ipauth + ;; + +lkm) + rm -f lkm + mknod lkm c 28 0 + chown root.kmem lkm + chmod 640 lkm + ;; + +audio*) + unit=${i#audio} + audio=audio$unit + sound=sound$unit + mixer=mixer$unit + major=42 + audioctl=audioctl$unit + if [ "$unit" = "" ]; then unit=0; fi + rm -f $audio $sound $mixer $audioctl + mknod $sound c $major $(($unit + 0)) + mknod $audio c $major $(($unit + 128)) + mknod $mixer c $major $(($unit + 16)) + mknod $audioctl c $major $(($unit + 192)) + chown root.wheel $audio $sound $mixer $audioctl + chmod 666 $audio $sound $mixer $audioctl + ;; + +random) + rm -f random urandom + mknod random c 46 0 + mknod urandom c 46 1 + chown root.wheel random urandom + chmod 444 random + chmod 644 urandom + ;; + +local) + umask 0 + #sh $0.local all + umask 77 + ;; + +*) + echo $i: unknown device + ;; + +esac +done diff --git a/etc/etc.dreamcast/disktab b/etc/etc.dreamcast/disktab new file mode 100644 index 000000000000..4cbf6454a84c --- /dev/null +++ b/etc/etc.dreamcast/disktab @@ -0,0 +1,44 @@ +# $NetBSD: disktab,v 1.1 2000/12/11 18:19:16 marcus Exp $ +# +# Disk geometry and partition layout tables. +# Key: +# dt controller type +# ty type of disk (fixed, removeable, simulated) +# d[0-4] drive-type-dependent parameters +# ns #sectors/track +# nt #tracks/cylinder +# nc #cylinders/disk +# sc #sectors/cylinder, ns*nt default +# su #sectors/unit, sc*nc default +# se sector size, DEV_BSIZE default +# rm rpm, 3600 default +# sf supports bad144-style bad sector forwarding +# sk sector skew per track, default 0 +# cs sector skew per cylinder, default 0 +# hs headswitch time, default 0 +# ts one-cylinder seek time, default 0 +# il sector interleave (n:1), 1 default +# bs boot block size, default BBSIZE +# sb superblock size, default SBSIZE +# o[a-h] partition offsets in sectors +# p[a-h] partition sizes in sectors +# b[a-h] partition block sizes in bytes +# f[a-h] partition fragment sizes in bytes +# t[a-h] partition types (filesystem, swap, etc) +# +# All partition sizes reserve space for bad sector tables. +# (5 cylinders needed for maintenance + replacement sectors) +# + +floppy|floppy3|3in|3.5in High Density Floppy:\ + :ty=floppy:se#512:nt#2:rm#300:ns#18:nc#80:\ + :pa#2880:oa#0:ba#4096:fa#512:ta=4.2BSD:\ + :pb#2880:ob#0:\ + :pc#2880:oc#0: + +floppy5|5in|5.25in High Density Floppy:\ + :ty=floppy:se#512:nt#2:rm#300:ns#15:nc#80:\ + :pa#2400:oa#0:ba#4096:fa#512:ta=4.2BSD:\ + :pb#2400:ob#0:bb#4096:fb#512:\ + :pc#2400:oc#0:bc#4096:fc#512: + diff --git a/etc/etc.dreamcast/fstab.md b/etc/etc.dreamcast/fstab.md new file mode 100644 index 000000000000..6d234aa36720 --- /dev/null +++ b/etc/etc.dreamcast/fstab.md @@ -0,0 +1,2 @@ +/kern /kern kernfs rw 0 0 +/proc /proc procfs rw 0 0 diff --git a/etc/etc.dreamcast/ttys b/etc/etc.dreamcast/ttys new file mode 100644 index 000000000000..05d3dc60a80d --- /dev/null +++ b/etc/etc.dreamcast/ttys @@ -0,0 +1,48 @@ +# $NetBSD: ttys,v 1.1 2000/12/11 18:19:16 marcus Exp $ +# from: @(#)ttys 5.1 (Berkeley) 4/17/89 +# +# name getty type status comments +# +# If the console is marked insecure, single-user requires +# the root password. +# +# /dev/console is always valid, regardless of the board type. +# +console "/usr/libexec/getty std.115200" unknown on secure + +#tty00 "/usr/libexec/getty std.9600" unknown off secure +#tty01 "/usr/libexec/getty std.9600" unknown off secure + +# Pseudo Terminals +ttyp0 none network +ttyp1 none network +ttyp2 none network +ttyp3 none network +ttyp4 none network +ttyp5 none network +ttyp6 none network +ttyp7 none network +ttyp8 none network +ttyp9 none network +ttypa none network +ttypb none network +ttypc none network +ttypd none network +ttype none network +ttypf none network +ttyq0 none network +ttyq1 none network +ttyq2 none network +ttyq3 none network +ttyq4 none network +ttyq5 none network +ttyq6 none network +ttyq7 none network +ttyq8 none network +ttyq9 none network +ttyqa none network +ttyqb none network +ttyqc none network +ttyqd none network +ttyqe none network +ttyqf none network diff --git a/sys/arch/dreamcast/Makefile b/sys/arch/dreamcast/Makefile new file mode 100644 index 000000000000..26f3f1782b5c --- /dev/null +++ b/sys/arch/dreamcast/Makefile @@ -0,0 +1,30 @@ +# $NetBSD: Makefile,v 1.1 2000/12/11 18:19:12 marcus Exp $ + +# Makefile for dreamcast tags file and boot blocks + +#.include "../sh3/Makefile.inc" + +TDREAMCAST= ../dreamcast/tags +SDREAMCAST= ../dreamcast/dreamcast/*.[ch] ../dreamcast/include/*.h +ADREAMCAST= ../dreamcast/dreamcast/*.[sS] + +# Directories in which to place tags links +DDREAMCAST= dreamcast include + +.include "../../kern/Make.tags.inc" + +tags: + -ctags -wdtf ${TDREAMCAST} ${SDREAMCAST} ${COMM} + egrep "^ENTRY(.*)|^ALTENTRY(.*)" ${ADREAMCAST} | \ + sed "s;\([^:]*\):\([^(]*\)(\([^, )]*\)\(.*\);\3 \1 /^\2(\3\4$$/;" \ + >> ${TDREAMCAST} + sort -o ${TDREAMCAST} ${TDREAMCAST} + +links: + -for i in ${DDREAMCAST}; do \ + (cd $$i && rm -f tags; ln -s ../tags tags); done + + +SUBDIR= include # stand + +.include diff --git a/sys/arch/dreamcast/conf/GENERIC b/sys/arch/dreamcast/conf/GENERIC new file mode 100644 index 000000000000..8c50f064ea63 --- /dev/null +++ b/sys/arch/dreamcast/conf/GENERIC @@ -0,0 +1,140 @@ +# $NetBSD: GENERIC,v 1.1 2000/12/11 18:19:12 marcus Exp $ +# +# GENERIC -- everything that's currently supported +# + +include "arch/dreamcast/conf/std.dreamcast" + +# Enable the hooks used for initializing the root memory-disk. +options MEMORY_DISK_HOOKS +options MEMORY_DISK_IS_ROOT # force root on memory disk +options MEMORY_DISK_SERVER=0 # no userspace memory disk support +options MINIROOTSIZE=2880 # size of memory disk, in blocks + +options DONT_INIT_BSC + +maxusers 16 # estimated number of users + +# CPU support +options SH7750 +options SH4 +# options SH4_PCMCIA +options EVBSH4 +options MMEYE +options PCLOCK=50000000 # 50MHz +options IOM_ROM_BEGIN=0x00000000 +options IOM_ROM_SIZE=0x00100000 # 1MB +options IOM_RAM_BEGIN=0x8c000000 +options IOM_RAM_SIZE=0x01000000 # 16MB +options INITTODR_ALWAYS_USE_RTC +options BRAINS +options USE_RTCCLK +options SYNC_CLOCK_TO_RTC + +makeoptions LDSCRIPTBASE="shl.x" # for little endian + +options LED_ADDR=0xa8000000 + +# Standard system options +#options UCONSOLE # users can use TIOCCONS (for xconsole) +#options INSECURE # disable kernel security levels + +#options RTC_OFFSET=-540 +options HZ=64 # clock interrupt generates every 1/HZ sec +#options NTP # NTP phase/frequency locked loop + +#options KTRACE # system call tracing via ktrace(1) + +#options SYSVMSG # System V-like message queues +#options SYSVSEM # System V-like semaphores +#options SYSVSHM # System V-like memory sharing +#options SHMMAXPGS=1024 # 1024 pages is the default + +# Diagnostic/debugging support options +#options DIAGNOSTIC # cheap kernel consistency checks +#options DEBUG # expensive debugging checks/support +#options DDB # in-kernel debugger +#makeoptions DEBUG="-g" # compile full symbol table +#options SYSCALL_DEBUG +#options UVMHIST +#options UVMHIST_PRINT + +# Compatibility options +options COMPAT_13 # NetBSD 1.3 +options COMPAT_14 # NetBSD 1.4, +options COMPAT_43 # and 4.3BSD + +# Executable format options +options EXEC_COFF # COFF executables +options EXEC_ELF32 # 32-bit ELF executables + +# File systems +file-system FFS # UFS +file-system MFS # memory file system +#file-system NFS # Network File System client +file-system PROCFS # /proc +file-system KERNFS # /kern +#file-system NULLFS # loopback file system +#file-system UMAPFS # NULLFS + uid and gid remapping + +# File system options +#options QUOTA # UFS quotas +#options NFSSERVER # Network File System server + +# Networking options +options INET # IP + ICMP + TCP + UDP +#options NFS_BOOT_DHCP # Support DHCP NFS root + +#options PCIVERBOSE # verbose PCI device autoconfig messages +#options PCI_CONFIG_DUMP # verbosely dump PCI config space +#options PCMCIAVERBOSE # verbose PCMCIA configuration messages + +# Kernel root file system and dump configuration. +#config netbsd root on ? type nfs +#config netbsd root on wd0a type ffs +config netbsd root on ? type ffs + +# +# Device configuration +# + +mainbus0 at root + +shb* at mainbus? + +# Serial Devices + +options SCIFCN_SPEED=57600 +scif0 at shb? port 0xffe80000 irq 12 + +# SH PCMCIA controllers +#shpcic0 at shb? port 0xb000000a iomem 0xb8000000 iosiz 0x1000000 +#shpcic1 at shb? port 0xb000000c iomem 0xb9000000 iosiz 0x1000000 + +# PCMCIA bus support +#pcmcia* at shpcic? controller ? socket ? + +#com* at pcmcia? function ? # Modems and serial cards +#wdc* at pcmcia? function ? +#wd* at wdc? drive ? # the drives themselves + +#ep* at pcmcia? function ? # 3Com 3c589 and 3c562 Ethernet +#mbe* at pcmcia? function ? # MB8696x based Ethernet +#ne* at pcmcia? function ? # NE2000-compatible Ethernet +#sm* at pcmcia? function ? # Megahertz Ethernet + +#pseudo-device vnd 4 # disk-like interface to files +#pseudo-device bpfilter 8 # Berkeley packet filter +#pseudo-device ipfilter # IP filter (firewall) and NAT +pseudo-device loop # network loopback +pseudo-device pty # pseudo-terminals +#pseudo-device ppp 2 # Point-to-Point Protocol +#pseudo-device tun 2 # network tunneling over tty + +# Enable the hooks used for initializing the root memory-disk. +#options MEMORY_DISK_HOOKS +#options MEMORY_DISK_IS_ROOT # force root on memory disk +#options MEMORY_DISK_SERVER=0 # no userspace memory disk support +#options MINIROOTSIZE=3074 # size of memory disk, in blocks + +pseudo-device md 1 # memory disk device (ramdisk) diff --git a/sys/arch/dreamcast/conf/GENERIC.local b/sys/arch/dreamcast/conf/GENERIC.local new file mode 100644 index 000000000000..fe7783927cc2 --- /dev/null +++ b/sys/arch/dreamcast/conf/GENERIC.local @@ -0,0 +1,5 @@ +# $NetBSD: GENERIC.local,v 1.1 2000/12/11 18:19:12 marcus Exp $ +# +# GENERIC.local -- local additions to the GENERIC configuration +# + diff --git a/sys/arch/dreamcast/conf/Makefile.dreamcast b/sys/arch/dreamcast/conf/Makefile.dreamcast new file mode 100644 index 000000000000..14f3c39e6b02 --- /dev/null +++ b/sys/arch/dreamcast/conf/Makefile.dreamcast @@ -0,0 +1,221 @@ +# $NetBSD: Makefile.dreamcast,v 1.1 2000/12/11 18:19:12 marcus Exp $ + +# Makefile for NetBSD +# +# This makefile is constructed from a machine description: +# config machineid +# Most changes should be made in the machine description +# /sys/arch/sh3/conf/``machineid'' +# after which you should do +# config machineid +# Machine generic makefile changes should be made in +# /sys/arch/sh3/conf/Makefile.sh3 +# after which config should be rerun for all machines of that type. +# +# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE +# IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING +# +# -DTRACE compile in kernel tracing hooks +# -DQUOTA compile in file system quotas + +# DEBUG is set to -g if debugging. +# PROF is set to -pg if profiling. + +AR?= ar +AS?= as +CC?= cc +CPP?= cpp +LD?= ld +LORDER?=lorder +MKDEP?= mkdep +NM?= nm +RANLIB?=ranlib +SIZE?= size +STRIP?= strip +TSORT?= tsort -q +OBJCOPY?= objcopy + +COPTS?= -O2 + +# source tree is located via $S relative to the compilation directory +.ifndef S +S!= cd ../../../..; pwd +.endif +SH3= $S/arch/sh3 +DREAMCAST= $S/arch/dreamcast + +HAVE_EGCS!= ${CC} --version | egrep "^(2\.[89]|egcs)" ; echo +INCLUDES= -I. -I$S/arch -I$S -nostdinc +CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL \ + -Dsh3 +CWARNFLAGS= -Werror -Wall -Wmissing-prototypes -Wstrict-prototypes +CWARNFLAGS+= -Wpointer-arith -Wno-parentheses +# XXX Delete -Wuninitialized for now, since the compiler doesn't +# XXX always get it right. --thorpej +CWARNFLAGS+= -Wno-uninitialized +.if (${HAVE_EGCS} != "") +CWARNFLAGS+= -Wno-main +.endif +CFLAGS= ${DEBUG} ${COPTS} ${CWARNFLAGS} +AFLAGS= -x assembler-with-cpp -traditional-cpp -D_LOCORE +LINKFLAGS= -e start -Map netbsd.map -T ../../conf/${LDSCRIPTBASE} +LINKFLAGS2= -e start -Map netbsd2.map -T ../../conf/${LDSCRIPTBASE}.RAM +LINKFLAGS3= -e start -Map netbsd3.map -T ../../conf/${LDSCRIPTBASE}.ICE +STRIPFLAGS= --strip-debug +MACHINE=dreamcast +MACHINE_ARCH=sh3 + +### find out what to use for libkern +.include "$S/lib/libkern/Makefile.inc" +.ifndef PROF +LIBKERN= ${KERNLIB} +.else +LIBKERN= ${KERNLIB_PROF} +.endif + +### find out what to use for libcompat +.include "$S/compat/common/Makefile.inc" +.ifndef PROF +LIBCOMPAT= ${COMPATLIB} +.else +LIBCOMPAT= ${COMPATLIB_PROF} +.endif + +# compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or +# HOSTED}, and SUFFIX is the file suffix, capitalized (e.g. C for a .c file). + +NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< +NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} -c $< + +%OBJS + +%CFILES + +%SFILES + +# load lines for config "xxx" will be emitted as: +# xxx: ${SYSTEM_DEP} swapxxx.o +# ${SYSTEM_LD_HEAD} +# ${SYSTEM_LD} swapxxx.o +# ${SYSTEM_LD_TAIL} +MMEYEROOT=/usr/home/mmEye/root +SYSTEM_OBJ= locore.o \ + param.o ioconf.o ${OBJS} ${LIBKERN} ${LIBCOMPAT} +SYSTEM_DEP= Makefile ${SYSTEM_OBJ} +SYSTEM_LD_HEAD= rm -f $@ +SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@.out '$${SYSTEM_OBJ}' vers.o; \ + ${LD} ${LINKFLAGS} -o $@.out ${SYSTEM_OBJ} vers.o +SYSTEM_LD_TAIL= @echo ${LD} ${LINKFLAGS2} -o $@2.out '$${SYSTEM_OBJ}' vers.o; \ + ${LD} ${LINKFLAGS2} -o $@2.out ${SYSTEM_OBJ} vers.o swapnetbsd.o ; \ + ${LD} ${LINKFLAGS3} -o $@3.out ${SYSTEM_OBJ} vers.o swapnetbsd.o ; \ + cp $@.out $@; ${STRIP} $@ ; \ + ${SIZE} $@; chmod 755 $@ ; \ + echo ${OBJCOPY} -O srec $@.out $@.s; ${OBJCOPY} -O srec $@.out $@.s + + + +DEBUG?= +.if ${DEBUG} == "-g" +LINKFLAGS+= -X +SYSTEM_LD_TAIL+=; \ + echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \ + echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \ + ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb +.else +LINKFLAGS+= +.endif + +%LOAD + +assym.h: $S/kern/genassym.sh ${DREAMCAST}/dreamcast/genassym.cf + sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \ + < ${DREAMCAST}/dreamcast/genassym.cf > assym.h.tmp && \ + mv -f assym.h.tmp assym.h + +param.c: $S/conf/param.c + rm -f param.c + cp $S/conf/param.c . + +param.o: param.c Makefile + ${NORMAL_C} + +ioconf.o: ioconf.c + ${NORMAL_C} + +newvers: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} + sh $S/conf/newvers.sh + ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c + + +__CLEANKERNEL: .USE + @echo "${.TARGET}ing the kernel objects" + rm -f eddep *netbsd netbsd netbsd.gdb tags *.[io] [a-z]*.s \ + [Ee]rrs linterrs makelinks assym.h.tmp assym.h + +__CLEANDEPEND: .USE + rm -f .depend + +clean: __CLEANKERNEL + +cleandir: __CLEANKERNEL __CLEANDEPEND + +lint: + @lint -hbxncez -Dvolatile= ${CPPFLAGS} -UKGDB \ + ${SH3}/sh3/Locore.c ${CFILES} \ + ioconf.c param.c | \ + grep -v 'static function .* unused' + +tags: + @echo "see $S/kern/Makefile for tags" + +links: + egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ + sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink + echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ + sort -u | comm -23 - dontlink | \ + sed 's,../.*/\(.*.o\),rm -f \1; ln -s ../GENERIC/\1 \1,' > makelinks + sh makelinks && rm -f dontlink + +SRCS= ${DREAMCAST}/dreamcast/locore.s \ + param.c ioconf.c ${CFILES} ${SFILES} +depend: .depend +.depend: ${SRCS} assym.h param.c + ${MKDEP} ${AFLAGS} ${CPPFLAGS} ${DREAMCAST}/dreamcast/locore.s + ${MKDEP} -a ${CFLAGS} ${CPPFLAGS} param.c ioconf.c ${CFILES} + sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} \ + ${CPPFLAGS} < ${DREAMCAST}/dreamcast/genassym.cf + @sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend + @rm -f assym.dep + +dependall: depend all + + +# depend on root or device configuration +autoconf.o conf.o: Makefile + +# depend on network or filesystem configuration +uipc_proto.o vfs_conf.o: Makefile + +# depend on maxusers +machdep.o: Makefile + +# depend on CPU configuration +locore.o machdep.o: Makefile + + +locore.o: ${DREAMCAST}/dreamcast/locore.s assym.h + ${NORMAL_S} + +# The install target can be redefined by putting a +# install-kernel-${MACHINE_NAME} target into /etc/mk.conf +MACHINE_NAME!= uname -n +install: install-kernel-${MACHINE_NAME} +.if !target(install-kernel-${MACHINE_NAME}}) +install-kernel-${MACHINE_NAME}: + rm -f /onetbsd + ln /netbsd /onetbsd + cp netbsd /nnetbsd + mv /nnetbsd /netbsd +.endif + +%RULES diff --git a/sys/arch/dreamcast/conf/files.dreamcast b/sys/arch/dreamcast/conf/files.dreamcast new file mode 100644 index 000000000000..33321203ad0f --- /dev/null +++ b/sys/arch/dreamcast/conf/files.dreamcast @@ -0,0 +1,16 @@ +# $NetBSD: files.dreamcast,v 1.1 2000/12/11 18:19:12 marcus Exp $ +# +# new style config file for sh3 architecture +# + +include "arch/dreamcast/conf/files.shbus" + +file arch/dreamcast/dreamcast/conf.c +file arch/dreamcast/dreamcast/machdep.c + +defopt opt_memsize.h IOM_ROM_BEGIN IOM_ROM_SIZE IOM_RAM_BEGIN IOM_RAM_SIZE +defopt opt_led_addr.h LED_ADDR +defopt opt_initbsc.h BSC_BCR1_VAL BSC_BCR2_VAL BSC_WCR1_VAL BSC_WCR2_VAL + BSC_WCR3_VAL BSC_MCR_VAL BSC_SDMR2_VAL BSC_SDMR3_VAL + BSC_RTCSR_VAL BSC_RTCNT_VAL BSC_RTCOR_VAL BSC_RFCR_VAL + BSC_PCR_VAL FRQCR_VAL PFC_SCPCR_VAL diff --git a/sys/arch/dreamcast/conf/files.shbus b/sys/arch/dreamcast/conf/files.shbus new file mode 100644 index 000000000000..c7c67b00c4fb --- /dev/null +++ b/sys/arch/dreamcast/conf/files.shbus @@ -0,0 +1,69 @@ +# $NetBSD: files.shbus,v 1.1 2000/12/11 18:19:13 marcus Exp $ +# +# Config file and device description for machine-independent SHBus code. +# Included by ports that need it. Requires that the SCSI files be +# defined first. + +# ports should specify appropriate major numbers for the following +# devices: +# mcd, scd, wd, wt + +device shb {[port = -1], [size = 0], + [iomem = -1], [iosiz = 0], + [irq = -1], [drq = -1], [drq2 = -1]} +attach shb at mainbus + +file arch/dreamcast/dreamcast/shb.c shb needs-flag + +# Misc devices + +device wdog +attach wdog at shb +file arch/sh3/dev/wdog.c wdog needs-flag + +# +# Serial drivers +# + +defopt opt_sci.h SCICONSOLE SCICN_SPEED +device sci +attach sci at shb +file arch/sh3/dev/sci.c sci needs-flag + +defopt opt_scif.h SCIFCONSOLE SCIFCN_SPEED +device scif +attach scif at shb +file arch/sh3/dev/scif.c scif needs-flag + +# XXXX pcic here because it needs to be late. The catch: pcic needs +# to be late, so devices which attach to it are attached late. But it +# needs to be before its isa and pci attachments. This answer is +# non-optimal, but I don't have a better answer right now. + +# PCIC pcmcia contoller +# XXX this needs to be done very late, so it's done here. This feels +# like a kludge, but it might be for the best. + +defopt PCIC_SHB_ALLOC_IOBASE +defopt PCIC_SHB_ALLOC_IOSIZE +defopt PCIC_SHB_INTR_ALLOC_MASK + +device shpcic: pcmciabus +file arch/sh3/dev/shpcic.c shpcic + +# PCIC pcmcia contoller +attach shpcic at shb with pcic_shb +file arch/sh3/dev/pcic_shb.c pcic_shb +file arch/sh3/dev/pcic_shbsubr.c pcic_shb + +# PCIC pcmcia contoller +#attach pcic at pci with pcic_pci +#file dev/pci/i82365_pci.c pcic_pci + + +# this wants to be probed as late as possible. +# +# Machine-independent PCMCIA drivers +# +device fdc {drive = -1} +include "dev/pcmcia/files.pcmcia" diff --git a/sys/arch/dreamcast/conf/shl.x b/sys/arch/dreamcast/conf/shl.x new file mode 100644 index 000000000000..b0aced309ffc --- /dev/null +++ b/sys/arch/dreamcast/conf/shl.x @@ -0,0 +1,56 @@ +OUTPUT_FORMAT("coff-shl") +OUTPUT_ARCH(sh) +MEMORY +{ + ram : o = 0x8C010000, l = 16M +} +SECTIONS +{ + ROM = 0x80010000; + + .text : + AT (ROM) + { + *(.text) + *(.rodata) + *(.strings) + _etext = . ; + } > ram + .tors : + AT ( ROM + SIZEOF(.text)) + { + ___ctors = . ; + *(.ctors) + ___ctors_end = . ; + ___dtors = . ; + *(.dtors) + ___dtors_end = . ; + } > ram + .data : + AT ( ROM + SIZEOF(.text) + SIZEOF(.tors)) + { + *(.data) + _edata = . ; + } > ram + .bss : + AT ( ROM + SIZEOF(.text) + SIZEOF(.tors) + SIZEOF(.data)) + { + _bss_start = . ; + *(.bss) + *(COMMON) + _end = . ; + } > ram + .stack : + { + _stack = . ; + *(.stack) + } > ram + .stab 0 (NOLOAD) : + { + *(.stab) + } + .stabstr 0 (NOLOAD) : + { + *(.stabstr) + } +} diff --git a/sys/arch/dreamcast/conf/shl.x.ICE b/sys/arch/dreamcast/conf/shl.x.ICE new file mode 100644 index 000000000000..3a141d03ce03 --- /dev/null +++ b/sys/arch/dreamcast/conf/shl.x.ICE @@ -0,0 +1,50 @@ +OUTPUT_FORMAT("coff-shl") +OUTPUT_ARCH(sh) +MEMORY +{ + ram : o = 0x0c010000, l = 16M +} +SECTIONS +{ + .text : + { + *(.text) + *(.rodata) + *(.strings) + _etext = . ; + } > ram + .tors : + { + ___ctors = . ; + *(.ctors) + ___ctors_end = . ; + ___dtors = . ; + *(.dtors) + ___dtors_end = . ; + } > ram + .data : + { + *(.data) + _edata = . ; + } > ram + .bss : + { + _bss_start = . ; + *(.bss) + *(COMMON) + _end = . ; + } > ram + .stack : + { + _stack = . ; + *(.stack) + } > ram + .stab 0 (NOLOAD) : + { + *(.stab) + } + .stabstr 0 (NOLOAD) : + { + *(.stabstr) + } +} diff --git a/sys/arch/dreamcast/conf/shl.x.RAM b/sys/arch/dreamcast/conf/shl.x.RAM new file mode 100644 index 000000000000..fe83fc482997 --- /dev/null +++ b/sys/arch/dreamcast/conf/shl.x.RAM @@ -0,0 +1,50 @@ +OUTPUT_FORMAT("coff-shl") +OUTPUT_ARCH(sh) +MEMORY +{ + ram : o = 0x8C010000, l = 16M +} +SECTIONS +{ + .text : + { + *(.text) + *(.rodata) + *(.strings) + _etext = . ; + } > ram + .tors : + { + ___ctors = . ; + *(.ctors) + ___ctors_end = . ; + ___dtors = . ; + *(.dtors) + ___dtors_end = . ; + } > ram + .data : + { + *(.data) + _edata = . ; + } > ram + .bss : + { + _bss_start = . ; + *(.bss) + *(COMMON) + _end = . ; + } > ram + .stack : + { + _stack = . ; + *(.stack) + } > ram + .stab 0 (NOLOAD) : + { + *(.stab) + } + .stabstr 0 (NOLOAD) : + { + *(.stabstr) + } +} diff --git a/sys/arch/dreamcast/conf/shl.x.ROM b/sys/arch/dreamcast/conf/shl.x.ROM new file mode 100644 index 000000000000..3ef375c7a2c3 --- /dev/null +++ b/sys/arch/dreamcast/conf/shl.x.ROM @@ -0,0 +1,33 @@ +OUTPUT_FORMAT("coff-shl") +OUTPUT_ARCH(sh) +MEMORY +{ + ram : o = 0x80010000, l = 16M +} +SECTIONS +{ + .text 0xa0000000 : + { + *(.text) + *(.rodata) + *(.strings) + _etext = . ; + } + .data : + { + *(.data) + _edata = . ; + } + .bss 0x8c010000 : + { + _bss_start = . ; + *(.bss) + *(COMMON) + _end = . ; + } + .stack : + { + _stack = . ; + *(.stack) + } +} diff --git a/sys/arch/dreamcast/conf/std.dreamcast b/sys/arch/dreamcast/conf/std.dreamcast new file mode 100644 index 000000000000..c79f4b5f81b5 --- /dev/null +++ b/sys/arch/dreamcast/conf/std.dreamcast @@ -0,0 +1,7 @@ +# $NetBSD: std.dreamcast,v 1.1 2000/12/11 18:19:13 marcus Exp $ +# +# standard, required NetBSD/dreamcast 'options' + +machine dreamcast sh3 + +options EXEC_SCRIPT # exec #! scripts diff --git a/sys/arch/dreamcast/dreamcast/conf.c b/sys/arch/dreamcast/dreamcast/conf.c new file mode 100644 index 000000000000..ed7e73dfb98d --- /dev/null +++ b/sys/arch/dreamcast/dreamcast/conf.c @@ -0,0 +1,326 @@ +/* $NetBSD: conf.c,v 1.1 2000/12/11 18:19:13 marcus Exp $ */ + +/* + * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles Hannum. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "wd.h" +bdev_decl(wd); +bdev_decl(sw); +#include "sd.h" +bdev_decl(sd); +#include "st.h" +bdev_decl(st); +#include "cd.h" +bdev_decl(cd); +#include "vnd.h" +bdev_decl(vnd); +#include "ccd.h" +bdev_decl(ccd); +#include "raid.h" +bdev_decl(raid); +#include "md.h" +bdev_decl(md); + +struct bdevsw bdevsw[] = +{ + bdev_disk_init(NWD,wd), /* 0: ST506/ESDI/IDE disk */ + bdev_swap_init(1,sw), /* 1: swap pseudo-device */ + bdev_notdef(), /* 2 (was floppy diskette) */ + bdev_notdef(), /* 3 (was QIC-02/QIC-36 tape) */ + bdev_disk_init(NSD,sd), /* 4: SCSI disk */ + bdev_tape_init(NST,st), /* 5: SCSI tape */ + bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */ + bdev_notdef(), /* 7 (was Mitsumi CD-ROM) */ + bdev_lkm_dummy(), /* 8 */ + bdev_lkm_dummy(), /* 9 */ + bdev_lkm_dummy(), /* 10 */ + bdev_lkm_dummy(), /* 11 */ + bdev_lkm_dummy(), /* 12 */ + bdev_lkm_dummy(), /* 13 */ + bdev_disk_init(NVND,vnd), /* 14: vnode disk driver */ + bdev_notdef(), /* 15 (was Sony CD-ROM) */ + bdev_disk_init(NCCD,ccd), /* 16: concatenated disk driver */ + bdev_disk_init(NMD,md), /* 17: memory disk driver */ + bdev_disk_init(NRAID,raid), /* 18: RAIDframe disk driver */ +}; +int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); + +cdev_decl(cn); +cdev_decl(ctty); +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); +#include "wdog.h" +cdev_decl(wdog); +cdev_decl(wd); +cdev_decl(sw); +#include "pty.h" +#define ptstty ptytty +#define ptsioctl ptyioctl +cdev_decl(pts); +#define ptctty ptytty +#define ptcioctl ptyioctl +cdev_decl(ptc); +cdev_decl(log); +#include "com.h" +cdev_decl(com); +#include "sci.h" +cdev_decl(sci); +#include "scif.h" +cdev_decl(scif); +cdev_decl(fd); +cdev_decl(sd); +cdev_decl(st); +#include "ss.h" +cdev_decl(ss); +#include "uk.h" +cdev_decl(uk); +cdev_decl(cd); +#include "ch.h" +cdev_decl(ch); +dev_decl(filedesc,open); +#include "bpfilter.h" +cdev_decl(bpf); +cdev_decl(md); +#include "cy.h" +cdev_decl(cy); +#include "tun.h" +cdev_decl(tun); +cdev_decl(vnd); +#include "audio.h" +cdev_decl(audio); +cdev_decl(svr4_net); +cdev_decl(ccd); +cdev_decl(raid); +#include "vcoda.h" +cdev_decl(vc_nb_); + +#include "esh.h" +cdev_decl(esh_fp); +#include "scsibus.h" +cdev_decl(scsibus); + +#include "ipfilter.h" +#include "rnd.h" + +struct cdevsw cdevsw[] = +{ + cdev_cn_init(1,cn), /* 0: virtual console */ + cdev_ctty_init(1,ctty), /* 1: controlling terminal */ + cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ + cdev_disk_init(NWD,wd), /* 3: ST506/ESDI/IDE disk */ + cdev_swap_init(1,sw), /* 4: /dev/drum (swap pseudo-device) */ + cdev_tty_init(NPTY,pts), /* 5: pseudo-tty slave */ + cdev_ptc_init(NPTY,ptc), /* 6: pseudo-tty master */ + cdev_log_init(1,log), /* 7: /dev/klog */ + cdev_tty_init(NCOM,com), /* 8: serial port */ + cdev_notdef(), /* 9 (was floppy disk) */ + cdev_tty_init(NSCIF,scif), /* 10: serial with FIFO */ + cdev_tty_init(NSCI,sci), /* 11: serial */ + cdev_notdef(), /* 12: */ + cdev_disk_init(NSD,sd), /* 13: SCSI disk */ + cdev_tape_init(NST,st), /* 14: SCSI tape */ + cdev_disk_init(NCD,cd), /* 15: SCSI CD-ROM */ + cdev_notdef(), /* 16: */ + cdev_ch_init(NCH,ch), /* 17: SCSI autochanger */ + cdev_disk_init(NCCD,ccd), /* 18: concatenated disk driver */ + cdev_scanner_init(NSS,ss), /* 19: SCSI scanner */ + cdev_uk_init(NUK,uk), /* 20: SCSI unknown */ + cdev_notdef(), /* 21 (was APM) */ + cdev_fd_init(1,filedesc), /* 22: file descriptor pseudo-device */ + cdev_bpftun_init(NBPFILTER,bpf),/* 23: Berkeley packet filter */ + cdev_disk_init(NMD,md), /* 24: memory disk driver */ + cdev_notdef(), /* 25 */ + cdev_notdef(), /* 26 (was joystick) */ + cdev_notdef(), /* 27 (was PC speaker) */ + cdev_lkm_init(NLKM,lkm), /* 28: loadable module driver */ + cdev_lkm_dummy(), /* 29 */ + cdev_lkm_dummy(), /* 30 */ + cdev_lkm_dummy(), /* 31 */ + cdev_lkm_dummy(), /* 32 */ + cdev_lkm_dummy(), /* 33 */ + cdev_lkm_dummy(), /* 34 */ + cdev_notdef(), /* 35 (was Microsoft mouse) */ + cdev_notdef(), /* 36 (was Logitech mouse) */ + cdev_notdef(), /* 37 (was PS/2 mouse) */ + cdev_notdef(), /* 38 (was Cyclom serial port) */ + cdev_notdef(), /* 39 (was Mitsumi CD-ROM) */ + cdev_bpftun_init(NTUN,tun), /* 40: network tunnel */ + cdev_disk_init(NVND,vnd), /* 41: vnode disk driver */ + cdev_audio_init(NAUDIO,audio), /* 42: generic audio I/O */ + cdev_notdef(), /* 43 */ + cdev_ipf_init(NIPFILTER,ipl), /* 44: ip-filter device */ + cdev_notdef(), /* 45 (was planetconnect satlink) */ + cdev_rnd_init(NRND,rnd), /* 46: random source pseudo-device */ + cdev_vc_nb_init(NVCODA,vc_nb_), /* 47: coda file system psdev */ + cdev_scsibus_init(NSCSIBUS,scsibus), /* 48: SCSI bus */ + cdev_disk_init(NRAID,raid), /* 49: RAIDframe disk driver */ + cdev_esh_init(NESH, esh_fp), /* 50: HIPPI (esh) raw device */ + cdev_wdog_init(NWDOG,wdog), /* 51: watchdog timer */ +}; +int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); + +int mem_no = 2; /* major device number of memory special file */ + +/* + * Swapdev is a fake device implemented + * in sw.c used only internally to get to swstrategy. + * It cannot be provided to the users, because the + * swstrategy routine munches the b_dev and b_blkno entries + * before calling the appropriate driver. This would horribly + * confuse, e.g. the hashing routines. Instead, /dev/drum is + * provided as a character (raw) device. + */ +dev_t swapdev = makedev(1, 0); + +/* + * Returns true if dev is /dev/mem or /dev/kmem. + */ +int +iskmemdev(dev) + dev_t dev; +{ + + return (major(dev) == mem_no && (minor(dev) < 2 || minor(dev) == 14)); +} + +/* + * Returns true if dev is /dev/zero. + */ +int +iszerodev(dev) + dev_t dev; +{ + + return (major(dev) == mem_no && minor(dev) == 12); +} + +static int chrtoblktbl[] = { + /* XXXX This needs to be dynamic for LKMs. */ + /*VCHR*/ /*VBLK*/ + /* 0 */ NODEV, + /* 1 */ NODEV, + /* 2 */ NODEV, + /* 3 */ 0, + /* 4 */ NODEV, + /* 5 */ NODEV, + /* 6 */ NODEV, + /* 7 */ NODEV, + /* 8 */ NODEV, + /* 9 */ NODEV, + /* 10 */ NODEV, + /* 11 */ NODEV, + /* 12 */ NODEV, + /* 13 */ 4, + /* 14 */ 5, + /* 15 */ 6, + /* 16 */ NODEV, + /* 17 */ NODEV, + /* 18 */ 16, + /* 19 */ NODEV, + /* 20 */ NODEV, + /* 21 */ NODEV, + /* 22 */ NODEV, + /* 23 */ NODEV, + /* 24 */ 17, + /* 25 */ NODEV, + /* 26 */ NODEV, + /* 27 */ NODEV, + /* 28 */ NODEV, + /* 29 */ NODEV, + /* 30 */ NODEV, + /* 31 */ NODEV, + /* 32 */ NODEV, + /* 33 */ NODEV, + /* 34 */ NODEV, + /* 35 */ NODEV, + /* 36 */ NODEV, + /* 37 */ NODEV, + /* 38 */ NODEV, + /* 39 */ NODEV, + /* 40 */ NODEV, + /* 41 */ 14, + /* 42 */ NODEV, + /* 43 */ NODEV, + /* 44 */ NODEV, + /* 45 */ NODEV, + /* 46 */ NODEV, + /* 47 */ NODEV, + /* 48 */ NODEV, + /* 49 */ NODEV, + /* 50 */ NODEV, +}; + +/* + * Convert a character device number to a block device number. + */ +dev_t +chrtoblk(dev) + dev_t dev; +{ + int blkmaj; + + if (major(dev) >= nchrdev) + return (NODEV); + blkmaj = chrtoblktbl[major(dev)]; + if (blkmaj == NODEV) + return (NODEV); + return (makedev(blkmaj, minor(dev))); +} + +#include + +#define scicnpollc nullcnpollc +#define scifcnpollc nullcnpollc +cons_decl(sci); +cons_decl(scif); +cons_decl(com); + +struct consdev constab[] = { +#if NSCI > 0 + cons_init(sci), +#endif +#if NSCIF > 0 + cons_init(scif), +#endif +#if NCOM > 0 + cons_init(com), +#endif + { 0 }, +}; diff --git a/sys/arch/dreamcast/dreamcast/genassym.cf b/sys/arch/dreamcast/dreamcast/genassym.cf new file mode 100644 index 000000000000..59cd06685b11 --- /dev/null +++ b/sys/arch/dreamcast/dreamcast/genassym.cf @@ -0,0 +1,110 @@ +# $NetBSD: genassym.cf,v 1.1 2000/12/11 18:19:13 marcus Exp $ + +# +# Copyright (c) 1995, 1997 Charles M. Hannum. All rights reserved. +# Copyright (c) 1982, 1990 The Regents of the University of California. +# All rights reserved. +# +# This code is derived from software contributed to Berkeley by +# William Jolitz. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the University of +# California, Berkeley and its contributors. +# 4. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)genassym.c 5.11 (Berkeley) 5/10/91 +# + +include "opt_memsize.h" +include "opt_led_addr.h" + +include +include +include +include +include +include + +include + +include +include +include +include + +define SRUN SRUN +define SONPROC SONPROC + +define PDSLOT_PTE PDSLOT_PTE +define PDSLOT_APTE PDSLOT_APTE +define PDSLOT_KERN PDSLOT_KERN +define NKPTP_MIN NKPTP_MIN +define NKPTP_MAX NKPTP_MAX + +define VM_MAXUSER_ADDRESS (int)VM_MAXUSER_ADDRESS + +define P_ADDR offsetof(struct proc, p_addr) +define P_BACK offsetof(struct proc, p_back) +define P_FORW offsetof(struct proc, p_forw) +define P_PRIORITY offsetof(struct proc, p_priority) +define P_STAT offsetof(struct proc, p_stat) +define P_WCHAN offsetof(struct proc, p_wchan) +define P_VMSPACE offsetof(struct proc, p_vmspace) +define P_FLAG offsetof(struct proc, p_flag) + +define P_SYSTEM P_SYSTEM + +define M_DATA offsetof(struct mbuf, m_data) +define M_LEN offsetof(struct mbuf, m_len) +define M_NEXT offsetof(struct mbuf, m_next) + +define V_TRAP offsetof(struct uvmexp, traps) +define V_INTR offsetof(struct uvmexp, intrs) + +define PCB_PAGEDIRREG offsetof(struct pcb, pageDirReg) +define PCB_ONFAULT offsetof(struct pcb, pcb_onfault) +define PCB_R15 offsetof(struct pcb, r15) +define PCB_R14 offsetof(struct pcb, r14) +define PCB_KR15 offsetof(struct pcb, kr15) + +define TF_SPC offsetof(struct trapframe, tf_spc) +define TF_TRAPNO offsetof(struct trapframe, tf_trapno) + +define SIGF_HANDLER offsetof(struct sigframe, sf_handler) +define SIGF_SC offsetof(struct sigframe, sf_sc) +define SC_EFLAGS offsetof(struct sigcontext, sc_ssr) + +define IOM_RAM_BEGIN IOM_RAM_BEGIN +define IOM_RAM_SIZE IOM_RAM_SIZE +define IOM_ROM_BEGIN IOM_ROM_BEGIN + +# XXX SH4 only +ifdef MMUCR_VALIDBITS +define MMUCR_VALIDBITS MMUCR_VALIDBITS +endif + +define LED_ADDR LED_ADDR diff --git a/sys/arch/dreamcast/dreamcast/locore.s b/sys/arch/dreamcast/dreamcast/locore.s new file mode 100644 index 000000000000..51e184d5b6e8 --- /dev/null +++ b/sys/arch/dreamcast/dreamcast/locore.s @@ -0,0 +1,1722 @@ +/* $NetBSD: locore.s,v 1.1 2000/12/11 18:19:13 marcus Exp $ */ + +/*- + * Copyright (c) 1993, 1994, 1995, 1997 + * Charles M. Hannum. All rights reserved. + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)locore.s 7.3 (Berkeley) 5/13/91 + */ + +#include "opt_ddb.h" +#include "opt_lockdebug.h" + +#include "assym.h" + +#include +#include + +#include +#include +#include +#include +#include + +#define INIT_STACK IOM_RAM_BEGIN + IOM_RAM_SIZE - 0x00001000 + +#ifdef SH4 +#define SHREG_BBRA 0xff200008 +#define SHREG_EXPEVT 0xff000024 +#define SHREG_INTEVT 0xff000028 +#define SHREG_MMUCR 0xff000010 +#define SHREG_TTB 0xff000008 +#else +#define SHREG_BBRA 0xffffffb8 +#define SHREG_EXPEVT 0xffffffd4 +#define SHREG_INTEVT 0xffffffd8 +#define SHREG_MMUCR 0xffffffe0 +#define SHREG_TTB 0xfffffff8 +#endif + +/* + * These are used on interrupt or trap entry or exit. + */ +#define INTRENTRY \ + mov #0x20, r0 ; \ + swap.b r0, r0 ; \ + swap.w r0, r0 ; \ + not r0, r0 ; \ + stc sr, r1 ; \ + and r0, r1 ; \ + ldc r1, sr ; /* Change Register Bank to 0 */ \ + ldc r8, r0_bank ; \ + ldc r9, r1_bank ; \ + ldc r10, r3_bank ; \ + mov r15, r8 ; /* Check if kernel stack is already used */ \ + mov #0x3, r9 ; \ + mov #30, r10 ; \ + shld r10, r9 ; /* r9 = 0xc0000000 */ \ + and r9, r8 ; \ + mov #2, r9 ; \ + shld r10, r9 ; /* r9 = 0x80000000 */ \ + and r15, r9 ; \ + cmp/eq r8, r9 ; \ + bt 1f ; /* If already kernel mode then jump */ \ + ldc r15, r2_bank ; \ + mov.l 3f, r8 ; /* 3f = Kernel Stack */ \ + mov.l @r8, r15 ; /* Change to Kernel Stack */ \ + stc r2_bank, r8 ; /* r8 = user sp */ \ + mov.l r8, @-r15 ; /* save user sp to stack */ \ + bra 2f ; \ + nop ; \ + .align 2 ; \ +3: .long KernelSp ; \ +1: ldc r0, r2_bank ; \ + mov r15, r0 ; \ + mov.l r0, @-r15 ; /* save r15 to stack */ \ + stc r2_bank, r0 ; \ +2: ; \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov.l r2, @-r15 ; \ + mov.l r3, @-r15 ; \ + mov.l r4, @-r15 ; \ + mov.l r5, @-r15 ; \ + mov.l r6, @-r15 ; \ + mov.l r7, @-r15 ; \ + stc.l r0_bank, @-r15 ; /* save r8 */ \ + stc.l r1_bank, @-r15 ; /* save r9 */ \ + stc.l r3_bank, @-r15 ; /* save r10 */ \ + mov.l r11, @-r15 ; \ + mov.l r12, @-r15 ; \ + mov.l r13, @-r15 ; \ + mov.l r14, @-r15 ; \ + sts.l pr, @-r15 ; \ + sts.l mach, @-r15 ; \ + sts.l macl, @-r15 ; \ + stc.l ssr, @-r15 ; \ + stc.l spc, @-r15 ; \ + mov.l r0, @-r15 + +#define INTRFASTEXIT \ + add #4, r15 ; /* pop trap event code */ \ + mov.l @r15+, r0 ; \ + ldc r0, spc ; \ + mov.l @r15+, r0 ; \ + ldc r0, ssr ; \ + lds.l @r15+, macl ; \ + lds.l @r15+, mach ; \ + lds.l @r15+, pr ; \ + mov.l @r15+, r14 ; \ + mov.l @r15+, r13 ; \ + mov.l @r15+, r12 ; \ + mov.l @r15+, r11 ; \ + mov.l @r15+, r10 ; \ + mov.l @r15+, r9 ; \ + mov.l @r15+, r8 ; \ + mov.l @r15+, r7 ; \ + mov.l @r15+, r6 ; \ + mov.l @r15+, r5 ; \ + mov.l @r15+, r4 ; \ + mov.l @r15+, r3 ; \ + mov.l @r15+, r2 ; \ + mov.l @r15+, r1 ; \ + mov.l @r15+, r0 ; \ + mov.l @r15, r15 ; \ + rte ; \ + nop + +#define RECURSEENTRY \ + mov r15, r0 ; \ + mov.l r0, @-r15 ; /* save r15 to stack */ \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov.l r2, @-r15 ; \ + mov.l r3, @-r15 ; \ + mov.l r4, @-r15 ; \ + mov.l r5, @-r15 ; \ + mov.l r6, @-r15 ; \ + mov.l r7, @-r15 ; \ + mov.l r8, @-r15 ; /* save r8 */ \ + mov.l r9, @-r15 ; /* save r9 */ \ + mov.l r10, @-r15 ; /* save r10 */ \ + mov.l r11, @-r15 ; \ + mov.l r12, @-r15 ; \ + mov.l r13, @-r15 ; \ + mov.l r14, @-r15 ; \ + sts.l pr, @-r15 ; \ + sts.l mach, @-r15 ; \ + sts.l macl, @-r15 ; \ + stc.l ssr, @-r15 ; \ + stc.l spc, @-r15 ; \ + mov.l r0, @-r15 + +/* + * emulate x86 cli, sti, ecli, esti + */ + +#define CLI \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov #0x10, r0 ; \ + swap.b r0, r0 ; \ + swap.w r0, r0 ; /* r0 = 0x10000000 */ \ + stc sr, r1 ; \ + or r0, r1 ; \ + ldc r1, sr ; /* disable interrupt */ \ + mov.l @r15+, r1 ; \ + mov.l @r15+, r0 + +#define STI \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov #0x10, r0 ; \ + swap.b r0, r0 ; \ + swap.w r0, r0 ; /* r0 = 0x10000000 */ \ + not r0, r0 ; \ + stc sr, r1 ; \ + and r0, r1 ; \ + ldc r1, sr ; /* enable interrupt */ \ + mov.l @r15+, r1 ; \ + mov.l @r15+, r0 + +#define ECLI \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov #0x78, r0 ; \ + shll r0 ; \ + stc sr, r1 ; \ + or r0, r1 ; \ + ldc r1, sr ; /* disable interrupt */ \ + mov.l @r15+, r1 ; \ + mov.l @r15+, r0 + +#define ESTI \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov #0x78, r0 ; \ + shll r0 ; \ + not r0, r0 ; \ + stc sr, r1 ; \ + and r0, r1 ; \ + ldc r1, sr ; /* enable interrupt */ \ + mov.l @r15+, r1 ; \ + mov.l @r15+, r0 + +/* + * PTmap is recursive pagemap at top of virtual address space. + * Within PTmap, the page directory can be found (third indirection). + * + * XXX 4 == sizeof pde + */ + .set _C_LABEL(PTmap), (PDSLOT_PTE << PDSHIFT) + .set _C_LABEL(PTD), (_C_LABEL(PTmap) + PDSLOT_PTE * NBPG) + .set _C_LABEL(PTDpde), (_C_LABEL(PTD) + PDSLOT_PTE * 4) + +/* + * APTmap, APTD is the alternate recursive pagemap. + * It's used when modifying another process's page tables. + * + * XXX 4 == sizeof pde + */ + .set _C_LABEL(APTmap), (PDSLOT_APTE << PDSHIFT) + .set _C_LABEL(APTD), (_C_LABEL(APTmap) + PDSLOT_APTE * NBPG) + .set _C_LABEL(APTDpde), (_C_LABEL(PTD) + PDSLOT_APTE * 4) + +/* + * Initialization + */ + .data + .globl _C_LABEL(curpcb), _C_LABEL(PTDpaddr) +_C_LABEL(PTDpaddr): + .long 0 /* paddr of PTD, for libkvm */ +KernelStack: .long 0 +KernelSp: .long 0 /* Cache for kernel stack pointer of + current task */ + + .text + .globl _C_LABEL(kernel_text) + .globl start, _C_LABEL(_start) + .set _C_LABEL(kernel_text), KERNTEXTOFF + .set _C_LABEL(_start), start + +start: + /* Set SP to initial position */ + mov.l XLtmpstk, r15 + + ECLI + + /* Set Register Bank to Bank 0 */ + mov.l SR_init, r0 + ldc r0, sr + + xor r0, r0 + mov.l XL_SHREG_MMUCR, r2 + mov.l r0, @r2 /* MMU OFF */ + + bra start1 + nop +#if 0 + mov #0x20, r8 + swap.b r8, r8 + swap.w r8, r8 + not r8, r8 + stc sr, r9 + and r8, r9 + ldc r9, sr /* Change Register Bank to 0 */ +#endif + .align 2 +SR_init: .long 0x500000F0 +XL_SHREG_MMUCR: .long SHREG_MMUCR +start1: + +#ifdef ROMIMAGE + /* Initialize BUS State Control Regs. */ + mov.l _ROM_START, r3 + mov.l _C_LABEL(ram_start), r4 + sub r3, r4 + /* Set Bus State Controler */ + mov.l XLInitializeBsc, r0 + sub r4, r0 + jsr @r0 + nop + + /* Move kernel image from ROM area to RAM area */ + mov.l ___end, r0 + mov.l ___start, r1 + mov.l _KERNBASE, r2 + sub r2, r0 + sub r2, r1 + sub r1, r0 + add #4, r0 /* size of bytes to be copied */ + shlr2 r0 /* number of long word */ + mov.l _ROM_START, r3 + add r3, r1 /* src address */ + mov.l ___start, r3 + sub r2, r3 + mov.l _C_LABEL(ram_start), r4 + add r4, r3 /* dest address */ +1: + mov.l @r1+, r4 + mov.l r4, @r3 + add #4, r3 + dt r0 /* decrement and Test */ + bf 1b + /* kernel image copy end */ + + mov.l LXstart_in_RAM, r0 + jmp @r0 /* jump to RAM area */ + nop + + .align 2 +LXstart_in_RAM: + .long start_in_RAM +#else +#ifndef DONT_INIT_BSC + /* Set Bus State Controler */ + mov.l XLInitializeBsc, r0 + jsr @r0 + nop +#endif +#endif + +start_in_RAM: + mova 1f, r0 + mov r0, r4 + mov.l XLinitSH3, r0 + jsr @r0 /* call initSH3() */ + nop + + .align 2 +1: +#if 1 + mov.l XLKernelStack, r3 + mov.l r15, @r3 +#endif + +#ifdef SH4 + /* CCR must be accessed from P2 area */ + mova cache_on, r0 + mov r0, r5 + mov.l XLtoP2, r1 + add r1, r5 + mova main_label, r0 + mov r0, r2 + mov.l XL_SHREG_CCR, r3 + mov.l XL_CCRVAL, r4 + jmp @r5 + nop + + .align 2 +cache_on: + mov.l r4, @r3 /* Write to CCR */ + nop + nop + nop + nop + nop + nop + nop + nop + jmp @r2 + nop + + .align 2 +main_label: +#endif + mov.l XLmain, r0 + jsr @r0 /* call main() */ + nop + + .align 2 + + .globl _C_LABEL(ram_start) +#ifndef DONT_INIT_BSC +XLInitializeBsc:.long _C_LABEL(InitializeBsc) +#endif +___start: .long start +___etext: .long _etext +___end: .long _end +XLtmpstk: .long INIT_STACK +_KERNBASE: .long KERNBASE +_C_LABEL(ram_start): .long IOM_RAM_BEGIN +_ROM_START: .long IOM_ROM_BEGIN +XLKernelStack: .long KernelStack +XLinitSH3: .long _C_LABEL(initSH3) +XLmain: .long _C_LABEL(main) +XLtoP2: .long 0x20000000 +XL_SHREG_CCR: .long 0xff00001c +#ifdef SH4 +#if 1 +XL_CCRVAL: .long 0x0909 /* Operand cache ON */ +#else +XL_CCRVAL: .long 0x0000 /* cache OFF */ +#endif +#endif + +NENTRY(proc_trampoline) + mov r11, r4 + jsr @r12 + nop + add #4, r15 /* pop tf_trapno */ + CLI + INTRFASTEXIT + /* NOTREACHED */ + +/*****************************************************************************/ + +/* + * Signal trampoline; copied to top of user stack. + */ +NENTRY(sigcode) + mov r15, r0 + mov.l @r0, r4 /* sig_no param */ + add #SIGF_HANDLER, r0 + mov.l @r0, r0 + jsr @r0 + nop + + mov r15, r0 + add #SIGF_SC, r0 + mov.l r0, @-r15 /* junk to fake return address */ + mov r0, r4 + mov.l XLSYS___sigreturn14, r0 + trapa #0x80 /* enter kernel with args on stack */ + mov.l XLSYS_exit, r0 + trapa #0x80 /* exit if sigreturn fails */ + + .align 2 +XLSYS___sigreturn14: + .long SYS___sigreturn14 +XLSYS_exit: + .long SYS_exit + .globl _C_LABEL(esigcode) +_C_LABEL(esigcode): + +/*****************************************************************************/ + +ENTRY(setjmp) + add #4*9, r4 + mov.l r8, @-r4 + mov.l r9, @-r4 + mov.l r10, @-r4 + mov.l r11, @-r4 + mov.l r12, @-r4 + mov.l r13, @-r4 + mov.l r14, @-r4 + mov.l r15, @-r4 + sts.l pr, @-r4 + rts + xor r0, r0 + +ENTRY(longjmp) + lds.l @r4+, pr + mov.l @r4+, r15 + mov.l @r4+, r14 + mov.l @r4+, r13 + mov.l @r4+, r12 + mov.l @r4+, r11 + mov.l @r4+, r10 + mov.l @r4+, r9 + mov.l @r4+, r8 + mov r5, r0 + tst r0, r0 + bf .L0 + add #1, r0 +.L0: + rts + nop + +/*****************************************************************************/ + +/* + * The following primitives manipulate the run queues. + * _whichqs tells which of the 32 queues _qs + * have processes in them. Setrq puts processes into queues, Remrq + * removes them from queues. The running process is on no queue, + * other processes are on a queue related to p->p_pri, divided by 4 + * actually to shrink the 0-127 range of priorities into the 32 available + * queues. + */ + .globl _C_LABEL(sched_whichqs), _C_LABEL(sched_qs), _C_LABEL(panic) + +/* + * When no processes are on the runq, cpu_switch() branches to here to wait for + * something to come ready. + */ + +ENTRY(idle) + /* + * When we get here, interrupts are off (via ECLI) and + * sched_lock is held. + */ + STI + + mov.l XXLwhichqs, r0 + mov.l @r0, r0 + mov r0, r14 + tst r0, r0 + bf sw1 + +#if defined(LOCKDEBUG) + mov.l Xsched_unlock, r0 + jsr @r0 + nop +#endif + ESTI + + sleep + + ECLI +#if defined(LOCKDEBUG) + mov.l Xsched_lock, r0 + jsr @r0 + nop +#endif + + bra _C_LABEL(idle) + nop + + .align 2 +XXLwhichqs: + .long _C_LABEL(sched_whichqs) + + +#define PUSHALL \ + mov.l r0, @-r15 ; \ + mov.l r1, @-r15 ; \ + mov.l r2, @-r15 ; \ + mov.l r3, @-r15 ; \ + mov.l r4, @-r15 ; \ + mov.l r5, @-r15 ; \ + mov.l r6, @-r15 ; \ + mov.l r7, @-r15 ; \ + mov.l r8, @-r15 ; \ + mov.l r9, @-r15 ; \ + mov.l r10, @-r15 ; \ + mov.l r11, @-r15 ; \ + mov.l r12, @-r15 ; \ + mov.l r13, @-r15 ; \ + mov.l r14, @-r15 + +#define POPALL \ + mov.l @r15+, r14 ; \ + mov.l @r15+, r13 ; \ + mov.l @r15+, r12 ; \ + mov.l @r15+, r11 ; \ + mov.l @r15+, r10 ; \ + mov.l @r15+, r9 ; \ + mov.l @r15+, r8 ; \ + mov.l @r15+, r7 ; \ + mov.l @r15+, r6 ; \ + mov.l @r15+, r5 ; \ + mov.l @r15+, r4 ; \ + mov.l @r15+, r3 ; \ + mov.l @r15+, r2 ; \ + mov.l @r15+, r1 ; \ + mov.l @r15+, r0 + +#define PUSHALLBUTR0 \ + mov.l r1, @-r15 ; \ + mov.l r2, @-r15 ; \ + mov.l r3, @-r15 ; \ + mov.l r4, @-r15 ; \ + mov.l r5, @-r15 ; \ + mov.l r6, @-r15 ; \ + mov.l r7, @-r15 ; \ + mov.l r8, @-r15 ; \ + mov.l r9, @-r15 ; \ + mov.l r10, @-r15 ; \ + mov.l r11, @-r15 ; \ + mov.l r12, @-r15 ; \ + mov.l r13, @-r15 ; \ + mov.l r14, @-r15 + +#define POPALLBUTR0 \ + mov.l @r15+, r14 ; \ + mov.l @r15+, r13 ; \ + mov.l @r15+, r12 ; \ + mov.l @r15+, r11 ; \ + mov.l @r15+, r10 ; \ + mov.l @r15+, r9 ; \ + mov.l @r15+, r8 ; \ + mov.l @r15+, r7 ; \ + mov.l @r15+, r6 ; \ + mov.l @r15+, r5 ; \ + mov.l @r15+, r4 ; \ + mov.l @r15+, r3 ; \ + mov.l @r15+, r2 ; \ + mov.l @r15+, r1 + +#define DIAGNOSTIC 1 +#ifdef DIAGNOSTIC +switch_error: + mova 1f, r0 + mov r0, r4 + mov.l 2f, r0 + jsr @r0 + nop + + .align 2 +1: .asciz "cpu_swicth" + .align 2 +2: .long _C_LABEL(panic) +#endif + +/* + * void cpu_switch(struct proc *) + * Find a runnable process and switch to it. Wait if necessary. If the new + * process is the same as the old one, we short-circuit the context save and + * restore. + */ +ENTRY(cpu_switch) + sts.l pr, @-r15 + mov.l r8, @-r15 + mov.l r9, @-r15 + mov.l r10, @-r15 + mov.l r11, @-r15 + mov.l r12, @-r15 + mov.l r13, @-r15 + mov.l r14, @-r15 + mov.l XXLcpl, r0 + mov.l @r0, r0 + mov.l r0, @-r15 + + mov.l XXLcurproc, r12 + mov.l @r12, r12 + tst r12, r12 + bt 1f + + /* Save stack pointers. */ + mov r12, r4 + mov.l XLP_ADDR, r1 + add r1, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.l @r0, r4 /* r4 = oldCurproc->p_addr */ + mov #PCB_R15, r1 + add r1, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.l r15, @r0 +1: + + /* + * Clear curproc so that we don't accumulate system time while idle. + * This also insures that schedcpu() will move the old process to + * the correct queue if it happens to get called from the spllower() + * below and changes the priority. (See corresponding comment in + * userret()). + */ + xor r0, r0 + mov.l XXLcurproc, r1 + mov.l r0, @r1 + +#if 0 + /* switch to proc0's stack */ + mov.l XXLKernelStack, r1 + mov.l @r1, r1 + mov.l XXLKernelSp, r0 + mov.l r1, @r0 +#endif + +#if defined(LOCKDEBUG) + /* Release the sched_lock before processing interrupts. */ + mov.l Xsched_unlock, r0 + jsr @r0 + nop +#endif + xor r0, r0 + mov.l XXLcpl, r1 + mov.l r0, @r1 /* spl0() */ + mov.l XXLXspllower, r0 + jsr @r0 + nop + bra switch_search + nop + + .align 2 +XXLcpl: .long _C_LABEL(cpl) +XXLcurproc: .long _C_LABEL(curproc) +XXLXspllower: .long _C_LABEL(Xspllower) +XXLKernelStack: .long KernelStack +XXLKernelSp: .long KernelSp + +switch_search: + /* + * First phase: find new process. + * + * Registers: + * r0 - queue head, scratch, then zero + * r13 - queue number + * r14 - cached value of whichqs + * r9 - next process in queue + * r12 - old process + * r8 - new process + */ + + /* Lock the scheduler. */ + ECLI /* splhigh doesn't do a cli */ +#if defined(LOCKDEBUG) + mov.l Xsched_lock, r0 + jsr @r0 + nop +#endif + + /* Wait for new process. */ + mov.l XXXLwhichqs, r0 + mov.l @r0, r0 + mov r0, r14 + bra 1f + nop + + .align 2 +XXXLwhichqs: + .long _C_LABEL(sched_whichqs) +1: + + +#define TESTANDSHIFT \ + tst r1, r0 ; \ + bf 1f ; \ + shll r1 ; \ + add #1, r2 + +sw1: mov #1, r1 + xor r2, r2 + TESTANDSHIFT /* bit 0 */ + TESTANDSHIFT /* bit 1 */ + TESTANDSHIFT /* bit 2 */ + TESTANDSHIFT /* bit 3 */ + TESTANDSHIFT /* bit 4 */ + TESTANDSHIFT /* bit 5 */ + TESTANDSHIFT /* bit 6 */ + TESTANDSHIFT /* bit 7 */ + TESTANDSHIFT /* bit 8 */ + TESTANDSHIFT /* bit 9 */ + TESTANDSHIFT /* bit 10 */ + TESTANDSHIFT /* bit 11 */ + TESTANDSHIFT /* bit 12 */ + TESTANDSHIFT /* bit 13 */ + TESTANDSHIFT /* bit 14 */ + TESTANDSHIFT /* bit 15 */ + TESTANDSHIFT /* bit 16 */ + TESTANDSHIFT /* bit 17 */ + TESTANDSHIFT /* bit 18 */ + TESTANDSHIFT /* bit 19 */ + TESTANDSHIFT /* bit 20 */ + TESTANDSHIFT /* bit 21 */ + TESTANDSHIFT /* bit 22 */ + TESTANDSHIFT /* bit 23 */ + TESTANDSHIFT /* bit 24 */ + TESTANDSHIFT /* bit 25 */ + TESTANDSHIFT /* bit 26 */ + TESTANDSHIFT /* bit 27 */ + TESTANDSHIFT /* bit 28 */ + TESTANDSHIFT /* bit 29 */ + TESTANDSHIFT /* bit 30 */ + TESTANDSHIFT /* bit 31 */ + + bra _C_LABEL(idle) /* if none, idle */ + nop + +1: mov.l XLqs, r0 + mov r2, r13 + shll r2 + shll r2 + shll r2 + add r2, r0 /* r0 = &qs[i] */ + + mov r0, r2 + mov #P_FORW, r1 + add r1, r2 + + ldc r0, r0_bank /* save r0 = &qs[i] */ + mov r2, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov r0, r2 + + mov.l @r2, r8 /* r8 = qs[i].p_forw */ + +#ifdef DIAGNOSTIC + stc r0_bank, r0 + cmp/eq r0, r8 /* linked to self (i.e. nothing queued)? */ + bf 10f + mov.l XL_switch_error, r0 + jmp @r0 + nop +10: +#endif + + mov r8, r3 + add r1, r3 + + mov r3, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov r0, r3 + + mov.l @r3, r9 /* r9 = qs[i].p_forw->p_forw */ + + mov.l r9, @r2 /* qs[i].p_forw = qs[i].p_forw->p_forw */ + + mov r9, r4 + mov #P_BACK, r2 + add r2, r4 + + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov r0, r10 + stc r0_bank, r0 + + mov.l r0, @r10 /* qs[i].p_forw->p_forw->p_back = &qs[i] */ + + mov r0, r11 + sub r9, r11 + tst r11, r11 + bf 3f /* if r0 != r9 then goto 3f */ + + mov #1, r0 + shld r13, r0 + not r0, r0 + and r0, r14 + mov.l XLwhichqs, r0 + mov.l r14, @r0 +/* #define sh3_debug */ +#ifdef sh3_debug + mova 1f, r0 + mov r0, r4 + mov r13, r5 + mov r14, r6 + mov.l 2f, r0 + jsr @r0 + nop + bra 3f + nop + + .align 2 +1: .asciz "switch[i=%d,whichqs=0x%0x]\n" + .align 2 +2: .long _C_LABEL(printf) +#endif + +3: + xor r0, r0 + mov.l XLwant_resched, r1 + mov.l r0, @r1 + +#ifdef DIAGNOSTIC + mov r8, r4 + add #P_WCHAN, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.l @r0, r0 + tst r0, r0 + bt 11f + + mov r8, r4 + add #P_STAT, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.b @r0, r0 + extu.b r0, r0 + mov #SRUN, r1 + cmp/eq r0, r1 + bt 11f + + mov.l XL_switch_error, r0 + jmp @r0 + nop + + .align 2 +XL_switch_error: + .long switch_error +11: +#endif + + /* Isolate process. XXX Is this necessary? */ + mov r8, r4 + mov #P_BACK, r2 + add r2, r4 + + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov r0, r1 + + xor r0, r0 + mov.l r0, @r1 /* r8->p_back = 0 */ + +#if defined(LOCKDEBUG) + /* + * Unlock the sched_lock, but leave interrupts off, for now. + */ + mov.l Xsched_unlock, r0 + jsr @r0 + nop +#endif + + /* p->p_cpu initialized in fork1() for single-processor */ + + /* Process now running on a processor. */ + mov #P_STAT, r0 + mov #SONPROC, r1 + mov.b r1, @(r0, r8) /* p->p_stat = SONPROC */ + + /* Record new process. */ + mov.l XXXLcurproc, r0 + mov.l r8, @r0 + + /* It's okay to take interrupts here. */ + ESTI + + /* Skip context switch if same process. */ + mov r12, r0 /* r12 = oldCurproc */ + sub r8, r0 /* r8 = qs[i]->p_forw */ + tst r0, r0 + bt switch_return + + /* If old process exited, don't bother. */ + tst r12, r12 + bt switch_exited + + /* + * Second phase: save old context. + * + * Registers: + * %eax, %ecx - scratch + * %esi - old process, then old pcb + * %edi - new process + */ + mov r12, r0 + mov.l XLP_ADDR, r1 + add r1, r0 + mov.l @r0, r12 /* r12 = oldCurproc->p_addr */ + + /* Save stack pointers. */ + mov r12, r0 + add #PCB_R15, r0 + mov.l r15, @r0 + +switch_exited: + /* + * Third phase: restore saved context. + * + * Registers: + * %eax, %ecx, %edx - scratch + * %esi - new pcb + * %edi - new process + */ + + /* No interrupts while loading new state. */ + ECLI + mov r8, r4 /* r8 = qs[i]->p_forw */ + mov.l XLP_ADDR, r1 + add r1, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.l @r0, r12 + + /* Restore stack pointers. */ + mov r12, r4 + add #PCB_R15, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.l @r0, r15 + + /* Store new kernel mode stack pointer */ + mov r12, r4 + add #PCB_KR15, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + mov.l @r0, r0 + mov.l XL_KernelSp, r1 + mov.l r0, @r1 + + /* Switch address space. */ + mov r12, r4 + add #PCB_PAGEDIRREG, r4 + mov.l XL_ConvVtoP, r0 + jsr @r0 + nop + + mov.l @r0, r0 + mov.l XL_SHREG_TTB, r2 + mov.l r0, @r2 + + /* flush TLB */ + mov.l XXL_SHREG_MMUCR, r0 + mov #4, r1 + mov.l @r0, r2 + or r1, r2 +#ifdef SH4 + mov.l XL_MMUCR_VBITS, r1 + and r1, r2 +#endif + mov.l r2, @r0 + +switch_restored: + /* Record new pcb. */ + mov.l XL_curpcb, r0 + mov.l r12, @r0 + + /* Interrupts are okay again. */ + ESTI + +switch_return: + /* + * Restore old cpl from stack. Note that this is always an increase, + * due to the spl0() on entry. + */ + mov.l @r15+, r0 + mov.l XLcpl, r1 + mov.l r0, @r1 + + mov r8, r0 /* return (p); */ + mov.l @r15+, r14 + mov.l @r15+, r13 + mov.l @r15+, r12 + mov.l @r15+, r11 + mov.l @r15+, r10 + mov.l @r15+, r9 + mov.l @r15+, r8 + lds.l @r15+, pr + + rts + nop + + .align 2 +XLqs: .long _C_LABEL(sched_qs) +XLP_ADDR: .long P_ADDR +XLwhichqs: .long _C_LABEL(sched_whichqs) +XLwant_resched: .long _C_LABEL(want_resched) +XXXLcurproc: .long _C_LABEL(curproc) +XL_ConvVtoP: .long _ConvVtoP +XL_KernelSp: .long KernelSp +XL_SHREG_TTB: .long SHREG_TTB +#if defined(LOCKDEBUG) +Xsched_lock: .long _C_LABEL(sched_lock_idle) +Xsched_unlock: .long _C_LABEL(sched_unlock_idle) +#endif +/* + * switch_exit(struct proc *p); + * Switch to proc0's saved context and deallocate the address space and kernel + * stack for p. Then jump into cpu_switch(), as if we were in proc0 all along. + */ + .globl _C_LABEL(proc0), _C_LABEL(kernel_map) +ENTRY(switch_exit) + mov r4, r8 /* old process */ + mov.l XLproc0, r9 + + /* In case we fault... */ + xor r0, r0 + mov.l XLcurproc, r1 + mov.l r0, @r1 + + /* Restore proc0's context. */ + ECLI + mov r9, r0 + mov.l XXLP_ADDR, r1 + add r1, r0 + mov.l @r0, r10 + + /* Restore stack pointers. */ + mov r10, r0 + mov #PCB_R15, r1 + add r1, r0 + mov.l @r0, r15 + + /* Switch address space. */ + mov r10, r0 + add #PCB_PAGEDIRREG, r0 + mov.l @r0, r2 + mov.l XXL_SHREG_TTB, r1 + mov.l r2, @r1 + + /* flush TLB */ + mov.l XXL_SHREG_MMUCR, r0 + mov #4, r1 + mov.l @r0, r2 + or r1, r2 +#ifdef SH4 + mov.l XL_MMUCR_VBITS, r1 + and r1, r2 +#endif + mov.l r2, @r0 + + /* Record new pcb. */ + mov.l XL_curpcb, r0 + mov.l r10, @r0 + + /* Interrupts are okay again. */ + ESTI + + mov r8, r4 + mov.l XLexit2, r0 + jsr @r0 /* exit2(p) */ + nop + + /* Jump into cpu_switch() with the right state. */ + mov r9, r12 + xor r0, r0 + mov.l XLcurproc, r1 + mov.l r0, @r1 + + bra switch_search + nop + + .align 2 + .globl _C_LABEL(exit2) +XLexit2: + .long _C_LABEL(exit2) + +#ifdef SH4 +XL_MMUCR_VBITS: + .long MMUCR_VALIDBITS +#endif + +XXL_SHREG_MMUCR: + .long SHREG_MMUCR +XXLP_ADDR: + .long P_ADDR + +/* + * savectx(struct pcb *pcb); + * Update pcb, saving current processor state. + */ +ENTRY(savectx) + mov.l r14, @-r15 + sts.l pr, @-r15 + mov r15, r14 + add #PCB_R15, r4 + mov.l r15, @r4 + mov r14, r15 + lds.l @r15+, pr + mov.l @r15+, r14 + + rts + nop + +/*****************************************************************************/ +/* + * Trap and fault vector routines + * + * On exit from the kernel to user mode, we always need to check for ASTs. In + * addition, we need to do this atomically; otherwise an interrupt may occur + * which causes an AST, but it won't get processed until the next kernel entry + * (possibly the next clock tick). Thus, we disable interrupt before checking, + * and only enable them again on the final `iret' or before calling the AST + * handler. + * + * XXX - debugger traps are now interrupt gates so at least bdb doesn't lose + * control. The sti's give the standard losing behaviour for ddb and kgdb. + */ + + .text + +NENTRY(exphandler) +/* #define CHECK_SP */ +#ifdef CHECK_SP + mov.l XL_splimit3, r0 + cmp/hs r15, r0 + bf 100f + mov.l XL_splimit_low3, r0 + cmp/hs r0, r15 + bf 100f + xor r0, r0 + jmp @r0 + nop +100: +#endif + + mov.l XL_SHREG_EXPEVT, r0 + mov.l @r0, r0 + cmp/eq #0x40, r0 /* T_TLBINVALIDR */ + bf 1f +3: + mov.l XL_tlbmisshandler, r0 + jmp @r0 +1: + cmp/eq #0x60, r0 /* T_TLBINVALIDW */ + bt 3b + + mov.l XL_TLBPROTWR, r1 + cmp/eq r0, r1 + bt 3b + + INTRENTRY +#ifdef DDB + mov #0, r0 + mov.l XL_SHREG_BBRA, r1 + mov.w r0, @r1 /* disable UBC */ + mov.l r0, @r15 /* clear frame->dummy */ +#endif + mov.l XL_SHREG_EXPEVT, r0 + mov.l @r0, r0 + mov.l r0, @-r15 + ESTI + STI + mov.l XL_trap, r0 + jsr @r0 + nop + add #4, r15 + nop + +2: /* Check for ASTs on exit to user mode. */ + ECLI + mov.l XL_astpending, r0 + mov.l @r0, r0 + tst r0, r0 + bt 1f + + /* If trap occurred in kernel , skip AST proc */ + mov r15, r0 + add #TF_SPC-4, r0 + mov.l @r0, r0 + mov #1, r1 + mov #31, r2 + shld r2, r1 + tst r1, r0 /* test MSB of TF_SPC */ + bf 1f +5: xor r0, r0 + mov.l XL_astpending, r1 + mov.l r0, @r1 + + ESTI + + mov.l XLT_ASTFLT, r1 + mov.l r1, @-r15 + mov.l XL_trap, r0 + jsr @r0 + nop + add #4, r15 + bra 2b + nop +1: + CLI + +#ifdef DDB + mov.l @r15, r0 + mov.l XL_SHREG_BBRA, r1 + mov.w r0, @r1 +#endif + INTRFASTEXIT + + .align 2 +XL_TLBPROTWR: + .long 0x000000c0 +XL_SHREG_EXPEVT: + .long SHREG_EXPEVT +XL_SHREG_BBRA: + .long SHREG_BBRA + + .globl _C_LABEL(tlbmisshandler_stub) + .globl _C_LABEL(tlbmisshandler_stub_end) +_C_LABEL(tlbmisshandler_stub): + mov.l XL_tlbmisshandler, r0 + jmp @r0 + nop + .align 2 +XL_tlbmisshandler: + .long _C_LABEL(tlbmisshandler) +_C_LABEL(tlbmisshandler_stub_end): + + .align 2 +NENTRY(tlbmisshandler) + INTRENTRY +#ifdef CHECK_SP + mov.l XL_splimit3, r0 + cmp/hs r15, r0 + bf 100f + mov.l XL_splimit_low3, r0 + cmp/hs r0, r15 + bf 100f + xor r0, r0 + jmp @r0 + nop + .align 2 +XL_splimit3: .long _end +XL_splimit_low3: .long 0x80000000 +100: +#endif + ECLI + /* we must permit interrupt to enable address translation */ + STI + mov.l r0, @-r15 /* push dummy trap code */ + mov.l XL_tlb_handler, r0 + jsr @r0 + nop + add #4, r15 /* pop dummy code */ + CLI + ldtlb + INTRFASTEXIT + + .align 2 + .globl _C_LABEL(MonTrap100), _C_LABEL(MonTrap100_end) +_C_LABEL(MonTrap100): + mov.l 1f, r0 + jmp @r0 + nop + + .align 2 +1: + .long _exphandler +_C_LABEL(MonTrap100_end): + + .align 2 + .globl _C_LABEL(MonTrap600), _C_LABEL(MonTrap600_end) +_C_LABEL(MonTrap600): + mov.l 1f, r0 + jmp @r0 + nop + + .align 2 +1: + .long _ihandler +_MonTrap600_end: + +/* + * Immediate Data + */ + .align 2 + +XL_curpcb: .long _C_LABEL(curpcb) +XLcurproc: .long _C_LABEL(curproc) +XLcpl: .long _C_LABEL(cpl) +XLXspllower: .long _C_LABEL(Xspllower) +XLproc0: .long _C_LABEL(proc0) + +XL_trap: .long _C_LABEL(trap) +XL_astpending: .long _C_LABEL(astpending) +XLT_ASTFLT: .long T_ASTFLT +XL_tlb_handler: .long _C_LABEL(tlb_handler) +XLexphandler: .long _C_LABEL(exphandler) + + /* + * Convert Virtual address to Physical Address + * r4 = Virtual Address + * r0 = returned Physical address + */ +#ifdef SH4 +ENTRY(ConvVtoP) + mov.l r1, @-r15 + mov.l r2, @-r15 + mov.l r3, @-r15 + mov.l r5, @-r15 +#ifdef SH4 /* cache flush */ + sts.l pr, @-r15 + mov.l r4, @-r15 + mov.l XL_cacheflush, r0 + jsr @r0 + nop + mov.l @r15+, r4 + lds.l @r15+, pr +#endif + mov r4, r0 + mov.l XL_CSMASK, r1 + mov.l XL_KCSAREA, r2 + and r4, r1 + cmp/eq r1, r2 + bt 1f + mov.l XL_P2AREA, r5 + mov #PDSHIFT, r1 + neg r1, r1 + shld r1, r0 + shll2 r0 + mov.l XXL_SHREG_TTB, r1 + or r5, r1 + mov.l @r1, r1 + add r0, r1 + or r5, r1 + mov.l @r1, r2 /* r2 = pde */ + mov.l XL_PG_FRAME, r1 + and r1, r2 /* r2 = page table address */ + mov r4, r0 + mov.l XL_PT_MASK, r3 + and r3, r0 + mov #PGSHIFT, r1 + neg r1, r1 + shld r1, r0 + shll2 r0 + add r0, r2 /* r2 = pte */ + or r5, r2 + mov.l @r2, r2 + mov.l XL_PG_FRAME, r1 + and r1, r2 + not r1, r1 + and r1, r4 + or r4, r2 + or r5, r2 + mov r2, r0 /* r0 = Physical address */ +1: + mov.l @r15+, r5 + mov.l @r15+, r3 + mov.l @r15+, r2 + mov.l @r15+, r1 + rts + nop +#else +ENTRY(ConvVtoP) + mov.l r1, @-r15 + mov.l r2, @-r15 + mov.l r3, @-r15 + mov r4, r0 + mov.l XL_CSMASK, r1 + mov.l XL_KCSAREA, r2 + and r4, r1 + cmp/eq r1, r2 + bt 1f + mov #PDSHIFT, r1 + neg r1, r1 + shld r1, r0 + shll2 r0 + mov.l XXL_SHREG_TTB, r1 + mov.l @r1, r1 + add r0, r1 + mov.l @r1, r2 /* r2 = pde */ + mov.l XL_PG_FRAME, r1 + and r1, r2 /* r2 = page table address */ + mov r4, r0 + mov.l XL_PT_MASK, r3 + and r3, r0 + mov #PGSHIFT, r1 + neg r1, r1 + shld r1, r0 + shll2 r0 + add r0, r2 /* r2 = pte */ + mov.l @r2, r2 + mov.l XL_PG_FRAME, r1 + and r1, r2 + not r1, r1 + and r1, r4 + or r4, r2 + mov r2, r0 /* r0 = Physical address */ +1: + mov.l @r15+, r3 + mov.l @r15+, r2 + mov.l @r15+, r1 + + rts + nop +#endif + + .align 2 +XL_PT_MASK: .long PT_MASK +XL_PG_FRAME: .long PG_FRAME +XL_CSMASK: .long 0xc0000000 +XL_KCSAREA: .long 0x80000000 +XXL_SHREG_TTB: .long SHREG_TTB +XL_P2AREA: .long 0xa0000000 +#ifdef SH4 +XL_cacheflush: .long _sh4_cache_flush +#endif + +Xrecurse: + stc sr, r0 + ldc r0, ssr + ldc r1, spc + RECURSEENTRY + bra 7f + nop + +NENTRY(ihandler) + INTRENTRY +#ifdef CHECK_SP + mov.l XL_splimit2, r0 + cmp/hs r15, r0 + bf 100f + mov.l XL_splimit_low2, r0 + cmp/hs r0, r15 + bf 100f + xor r0, r0 + jmp @r0 + nop + .align 2 +XL_splimit2: .long _end +XL_splimit_low2: .long 0x80000000 +100: +#endif +7: + mov.l XL_SHREG_INTEVT, r0 + mov.l @r0, r0 + mov.l r0, @-r15 +6: + ECLI /* disable external interrupt */ + STI /* enable exception for TLB handling */ + mov.l XL_intrhandler, r0 + jsr @r0 + nop + add #4, r15 + nop + + tst r0, r0 + bt 1f + + mov.l XL_check_ipending, r0 + jsr @r0 + nop + + tst r0, r0 + bf 7b + +2: /* Check for ASTs on exit to user mode. */ + ECLI + mov.l XXL_astpending, r0 + mov.l @r0, r0 + tst r0, r0 + bt 1f + + /* If trap occurred in kernel , skip AST proc */ + mov r15, r0 + add #TF_SPC-4, r0 + mov.l @r0, r0 + mov #1, r1 + mov #31, r2 + shld r2, r1 + tst r1, r0 /* test MSB of TF_SPC */ + bf 1f +5: xor r0, r0 + mov.l XXL_astpending, r1 + mov.l r0, @r1 + ESTI + mov.l XXLT_ASTFLT, r1 + mov.l r1, @-r15 + mov.l XXL_trap, r0 + jsr @r0 + nop + add #4, r15 + bra 2b + nop +1: + CLI + INTRFASTEXIT + + .align 2 +XL_SHREG_INTEVT: .long SHREG_INTEVT +XL_intrhandler: .long _C_LABEL(intrhandler) +XXL_astpending: .long _C_LABEL(astpending) +XXLT_ASTFLT: .long T_ASTFLT +XXL_trap: .long _C_LABEL(trap) +XL_check_ipending: .long _C_LABEL(check_ipending) + +ENTRY(enable_interrupt) + ESTI + rts + nop + +ENTRY(disable_interrupt) + ECLI + rts + nop + +ENTRY(enable_ext_intr) + ESTI + rts + nop + +ENTRY(disable_ext_intr) + ECLI + rts + nop + +NENTRY(Xspllower) + sts.l pr, @-r15 + mov.l r1, @-r15 + +Xrestart: + ECLI + STI + mov.l XXL_check_ipending, r0 + jsr @r0 + nop + + tst r0, r0 + bt 1f + + mov.l XL_restart, r1 + mov.l XL_Xrecurse, r0 + jmp @r0 + nop + +1: + ESTI + mov.l @r15+, r1 + lds.l @r15+, pr + rts + nop + + .align 2 +XXL_check_ipending: + .long _C_LABEL(check_ipending) +XL_Xrecurse: .long Xrecurse +XL_restart: .long Xrestart + +ENTRY(cpu_printR15) + sts.l pr, @-r15 + mova 1f, r0 + mov r0, r4 + mov r15, r5 + mov.l 2f, r0 + jsr @r0 + nop + lds.l @r15+, pr + rts + nop + + .align 2 +1: .asciz "sp=0x%x\n" + .align 2 +2: .long _C_LABEL(printf) + +load_and_reset: + mov.l XL_start_address, r0 + mov r0, r8 + mov.l @r4+, r1 /* r1 = osimage size */ + mov.l @r4+, r2 /* r2 = check sum */ + shlr2 r1 /* r1 = osimage size in dword */ +1: + mov.l @r4+, r3 + mov.l r3, @r0 + add #4, r0 + dt r1 + bf 1b + + jmp @r8 /* jump to start address */ + nop + + .align 2 +XL_start_address: + .long IOM_RAM_BEGIN + 0x00010000 +load_and_reset_end: + +ENTRY(XLoadAndReset) + ECLI + /* copy trampoline code to RAM area top */ + mov.l XL_load_and_reset, r0 + mov.l XL_load_and_reset_end, r1 + mov.l XL_load_trampoline_addr, r2 + mov r2, r8 + sub r0, r1 /* r1 = bytes to be copied */ +1: mov.b @r0+, r3 + mov.b r3, @r2 + add #1, r2 + dt r1 + bf 1b + + jmp @r8 /* jump to trampoline code */ + nop + + .align 2 +XL_load_trampoline_addr: + .long IOM_RAM_BEGIN + 0x00008000 +XL_load_and_reset: + .long load_and_reset +XL_load_and_reset_end: + .long load_and_reset_end + +ENTRY(Sh3Reset) + mov.l XL_reset_vector, r8 + jmp @r8 + nop + + .align 2 +XL_reset_vector: + .long 0xa0000000 + + .data + .align 2 + .globl _C_LABEL(intrcnt), _C_LABEL(eintrcnt) + .globl _C_LABEL(intrnames), _C_LABEL(eintrnames) +_C_LABEL(intrcnt): + .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +_C_LABEL(eintrcnt): + +_C_LABEL(intrnames): + .asciz "irq0", "irq1", "irq2", "irq3" + .asciz "irq4", "irq5", "irq6", "irq7" + .asciz "irq8", "irq9", "irq10", "irq11" + .asciz "irq12", "irq13", "irq14", "irq15" +_C_LABEL(eintrnames): diff --git a/sys/arch/dreamcast/dreamcast/machdep.c b/sys/arch/dreamcast/dreamcast/machdep.c new file mode 100644 index 000000000000..860209566e5f --- /dev/null +++ b/sys/arch/dreamcast/dreamcast/machdep.c @@ -0,0 +1,1241 @@ +/* $NetBSD: machdep.c,v 1.1 2000/12/11 18:19:13 marcus Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)machdep.c 7.4 (Berkeley) 6/3/91 + */ + +#include "opt_ddb.h" +#include "opt_syscall_debug.h" +#include "opt_memsize.h" +#include "opt_initbsc.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef KGDB +#include +#endif + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sci.h" + +/* the following is used externally (sysctl_hw) */ +char machine[] = MACHINE; /* cpu "architecture" */ +char machine_arch[] = MACHINE_ARCH; /* machine_arch = "sh3" */ + +#ifdef sh3_debug +int cpu_debug_mode = 1; +#else +int cpu_debug_mode = 0; +#endif + +char bootinfo[BOOTINFO_MAXSIZE]; + +int physmem; +int dumpmem_low; +int dumpmem_high; +vaddr_t atdevbase; /* location of start of iomem in virtual */ +paddr_t msgbuf_paddr; +struct user *proc0paddr; + +extern int boothowto; +extern paddr_t avail_start, avail_end; + +#ifdef SYSCALL_DEBUG +#define SCDEBUG_ALL 0x0004 +extern int scdebug; +#endif + +#define IOM_RAM_END ((paddr_t)IOM_RAM_BEGIN + IOM_RAM_SIZE - 1) + +/* + * Extent maps to manage I/O and ISA memory hole space. Allocate + * storage for 8 regions in each, initially. Later, ioport_malloc_safe + * will indicate that it's safe to use malloc() to dynamically allocate + * region descriptors. + * + * N.B. At least two regions are _always_ allocated from the iomem + * extent map; (0 -> ISA hole) and (end of ISA hole -> end of RAM). + * + * The extent maps are not static! Machine-dependent ISA and EISA + * routines need access to them for bus address space allocation. + */ +static long iomem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)]; +struct extent *ioport_ex; +struct extent *iomem_ex; +static int ioport_malloc_safe; + +void setup_bootinfo __P((void)); +void dumpsys __P((void)); +void identifycpu __P((void)); +void initSH3 __P((void *)); +void InitializeSci __P((unsigned char)); +void sh3_cache_on __P((void)); +void LoadAndReset __P((char *)); +void XLoadAndReset __P((char *)); +void Sh3Reset __P((void)); +#ifdef SH4 +void sh4_cache_flush __P((vaddr_t)); +#endif + +#include +#include + +void consinit __P((void)); + +/* + * Machine-dependent startup code + * + * This is called from main() in kern/main.c. + */ +void +cpu_startup() +{ + + sh3_startup(); + + /* Safe for i/o port allocation to use malloc now. */ + ioport_malloc_safe = 1; + +#ifdef SYSCALL_DEBUG + scdebug |= SCDEBUG_ALL; +#endif + +#ifdef FORCE_RB_SINGLE + boothowto |= RB_SINGLE; +#endif +} + +#define CPUDEBUG + +/* + * machine dependent system variables. + */ +int +cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + struct proc *p; +{ + dev_t consdev; + struct btinfo_bootpath *bibp; + struct trapframe *tf; + char *osimage; + + /* all sysctl names at this level are terminal */ + if (namelen != 1) + return (ENOTDIR); /* overloaded */ + + switch (name[0]) { + case CPU_CONSDEV: + if (cn_tab != NULL) + consdev = cn_tab->cn_dev; + else + consdev = NODEV; + return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev, + sizeof consdev)); + + case CPU_NKPDE: + return (sysctl_rdint(oldp, oldlenp, newp, nkpde)); + + case CPU_BOOTED_KERNEL: + bibp = lookup_bootinfo(BTINFO_BOOTPATH); + if (!bibp) + return (ENOENT); /* ??? */ + return (sysctl_rdstring(oldp, oldlenp, newp, bibp->bootpath)); + + case CPU_SETPRIVPROC: + if (newp == NULL) + return (0); + + /* set current process to priviledged process */ + tf = p->p_md.md_regs; + tf->tf_ssr |= PSL_MD; + return (0); + + case CPU_DEBUGMODE: + return (sysctl_int(oldp, oldlenp, newp, newlen, + &cpu_debug_mode)); + + case CPU_LOADANDRESET: + if (newp != NULL) { + osimage = (char *)(*(u_long *)newp); + + LoadAndReset(osimage); + /* not reach here */ + } + return (0); + + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ +} + +int waittime = -1; +struct pcb dumppcb; + +void +cpu_reboot(howto, bootstr) + int howto; + char *bootstr; +{ + + if (cold) { + howto |= RB_HALT; + goto haltsys; + } + + boothowto = howto; + if ((howto & RB_NOSYNC) == 0 && waittime < 0) { + waittime = 0; + vfs_shutdown(); + /* + * If we've been adjusting the clock, the todr + * will be out of synch; adjust it now. + */ + /* resettodr(); */ + } + + /* Disable interrupts. */ + splhigh(); + + /* Do a dump if requested. */ + if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) + dumpsys(); + +haltsys: + doshutdownhooks(); + + if (howto & RB_HALT) { + printf("\n"); + printf("The operating system has halted.\n"); + printf("Please press any key to reboot.\n\n"); + cngetc(); + } + + printf("rebooting...\n"); + cpu_reset(); + for(;;) + ; + /*NOTREACHED*/ +} + +/* + * These variables are needed by /sbin/savecore + */ +u_long dumpmag = 0x8fca0101; /* magic number */ +int dumpsize = 0; /* pages */ +long dumplo = 0; /* blocks */ + +/* + * This is called by main to set dumplo and dumpsize. + * Dumps always skip the first CLBYTES of disk space + * in case there might be a disk label stored there. + * If there is extra space, put dump at the end to + * reduce the chance that swapping trashes it. + */ +void +cpu_dumpconf() +{ +#ifdef TODO + int nblks; /* size of dump area */ + int maj; + + if (dumpdev == NODEV) + return; + maj = major(dumpdev); + if (maj < 0 || maj >= nblkdev) + panic("dumpconf: bad dumpdev=0x%x", dumpdev); + if (bdevsw[maj].d_psize == NULL) + return; + nblks = (*bdevsw[maj].d_psize)(dumpdev); + if (nblks <= ctod(1)) + return; + + dumpsize = btoc(IOM_END + ctob(dumpmem_high)); + + /* Always skip the first CLBYTES, in case there is a label there. */ + if (dumplo < ctod(1)) + dumplo = ctod(1); + + /* Put dump at end of partition, and make it fit. */ + if (dumpsize > dtoc(nblks - dumplo)) + dumpsize = dtoc(nblks - dumplo); + if (dumplo < nblks - ctod(dumpsize)) + dumplo = nblks - ctod(dumpsize); +#endif +} + +/* + * Doadump comes here after turning off memory management and + * getting on the dump stack, either when called above, or by + * the auto-restart code. + */ +#define BYTES_PER_DUMP NBPG /* must be a multiple of pagesize XXX small */ +static vaddr_t dumpspace; + +vaddr_t +reserve_dumppages(p) + vaddr_t p; +{ + + dumpspace = p; + return (p + BYTES_PER_DUMP); +} + +void +dumpsys() +{ +#ifdef TODO + unsigned bytes, i, n; + int maddr, psize; + daddr_t blkno; + int (*dump) __P((dev_t, daddr_t, caddr_t, size_t)); + int error; + + /* Save registers. */ + savectx(&dumppcb); + + msgbufmapped = 0; /* don't record dump msgs in msgbuf */ + if (dumpdev == NODEV) + return; + + /* + * For dumps during autoconfiguration, + * if dump device has already configured... + */ + if (dumpsize == 0) + cpu_dumpconf(); + if (dumplo < 0) + return; + printf("\ndumping to dev %x, offset %ld\n", dumpdev, dumplo); + + psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev); + printf("dump "); + if (psize == -1) { + printf("area unavailable\n"); + return; + } + +#if 0 /* XXX this doesn't work. grr. */ + /* toss any characters present prior to dump */ + while (sget() != NULL); /* syscons and pccons differ */ +#endif + + bytes = ctob(dumpmem_high) + IOM_END; + maddr = 0; + blkno = dumplo; + dump = bdevsw[major(dumpdev)].d_dump; + error = 0; + for (i = 0; i < bytes; i += n) { + /* + * Avoid dumping the ISA memory hole, and areas that + * BIOS claims aren't in low memory. + */ + if (i >= ctob(dumpmem_low) && i < IOM_END) { + n = IOM_END - i; + maddr += n; + blkno += btodb(n); + continue; + } + + /* Print out how many MBs we to go. */ + n = bytes - i; + if (n && (n % (1024*1024)) == 0) + printf("%d ", n / (1024 * 1024)); + + /* Limit size for next transfer. */ + if (n > BYTES_PER_DUMP) + n = BYTES_PER_DUMP; + + (void) pmap_map(dumpspace, maddr, maddr + n, VM_PROT_READ); + error = (*dump)(dumpdev, blkno, (caddr_t)dumpspace, n); + if (error) + break; + maddr += n; + blkno += btodb(n); /* XXX? */ + +#if 0 /* XXX this doesn't work. grr. */ + /* operator aborting dump? */ + if (sget() != NULL) { + error = EINTR; + break; + } +#endif + } + + switch (error) { + + case ENXIO: + printf("device bad\n"); + break; + + case EFAULT: + printf("device not ready\n"); + break; + + case EINVAL: + printf("area improper\n"); + break; + + case EIO: + printf("i/o error\n"); + break; + + case EINTR: + printf("aborted from console\n"); + break; + + case 0: + printf("succeeded\n"); + break; + + default: + printf("error %d\n", error); + break; + } + printf("\n\n"); + delay(5000000); /* 5 seconds */ +#endif /* TODO */ +} + +/* + * Initialize segments and descriptor tables + */ +#define VBRINIT ((char *)IOM_RAM_BEGIN) +#define Trap100Vec (VBRINIT + 0x100) +#define Trap600Vec (VBRINIT + 0x600) +#define TLBVECTOR (VBRINIT + 0x400) +#define VADDRSTART VM_MIN_KERNEL_ADDRESS + +extern int nkpde; +extern char MonTrap100[], MonTrap100_end[]; +extern char MonTrap600[], MonTrap600_end[]; +extern char _start[], etext[], edata[], end[]; +extern char tlbmisshandler_stub[], tlbmisshandler_stub_end[]; + +void +initSH3(pc) + void *pc; /* XXX return address */ +{ + paddr_t avail; + pd_entry_t *pagedir; + pt_entry_t *pagetab, pte; + u_int sp; + int x; + char *p; + + avail = sh3_round_page(end); + + /* XXX nkpde = kernel page dir area (IOM_RAM_SIZE*2 Mbyte (why?)) */ + nkpde = IOM_RAM_SIZE >> (PDSHIFT - 1); + + /* + * clear .bss, .common area, page dir area, + * process0 stack, page table area + */ + p = (char *)avail + (1 + UPAGES) * NBPG + NBPG * (1 + nkpde); /* XXX */ + bzero(edata, p - edata); + + /* + * install trap handler + */ + bcopy(MonTrap100, Trap100Vec, MonTrap100_end - MonTrap100); + bcopy(MonTrap600, Trap600Vec, MonTrap600_end - MonTrap600); + __asm ("ldc %0, vbr" :: "r"(VBRINIT)); + +/* + * edata end + * +-------------+------+-----+----------+-------------+------------+ + * | kernel text | data | bss | Page Dir | Proc0 Stack | Page Table | + * +-------------+------+-----+----------+-------------+------------+ + * NBPG USPACE (1+nkpde)*NBPG + * (= 4*NBPG) + * Build initial page tables + */ + pagedir = (void *)avail; + pagetab = (void *)(avail + SYSMAP); + + /* + * Construct a page table directory + * In SH3 H/W does not support PTD, + * these structures are used by S/W. + */ + pte = (pt_entry_t)pagetab; + pte |= PG_KW | PG_V | PG_4K | PG_M | PG_N; + pagedir[KERNTEXTOFF >> PDSHIFT] = pte; + + /* make pde for 0xd0000000, 0xd0400000, 0xd0800000,0xd0c00000, + 0xd1000000, 0xd1400000, 0xd1800000, 0xd1c00000 */ + pte += NBPG; + for (x = 0; x < nkpde; x++) { + pagedir[(VADDRSTART >> PDSHIFT) + x] = pte; + pte += NBPG; + } + + /* Install a PDE recursively mapping page directory as a page table! */ + pte = (u_int)pagedir; + pte |= PG_V | PG_4K | PG_KW | PG_M | PG_N; + pagedir[PDSLOT_PTE] = pte; + + /* set PageDirReg */ + SHREG_TTB = (u_int)pagedir; + + /* Set TLB miss handler */ + p = tlbmisshandler_stub; + x = tlbmisshandler_stub_end - p; + bcopy(p, TLBVECTOR, x); + + /* + * Activate MMU + */ + +#ifdef SH4 + SHREG_MMUCR = MMUCR_AT | MMUCR_TF | MMUCR_SV | MMUCR_SQMD; +#else + SHREG_MMUCR = MMUCR_AT | MMUCR_TF | MMUCR_SV; +#endif + + /* + * Now here is virtual address + */ + + /* Set proc0paddr */ + proc0paddr = (void *)(avail + NBPG); + + /* Set pcb->PageDirReg of proc0 */ + proc0paddr->u_pcb.pageDirReg = (int)pagedir; + + /* avail_start is first available physical memory address */ + avail_start = avail + NBPG + USPACE + NBPG + NBPG * nkpde; + + /* atdevbase is first available logical memory address */ + atdevbase = VADDRSTART; + + proc0.p_addr = proc0paddr; /* page dir address */ + + /* XXX: PMAP_NEW requires valid curpcb. also init'd in cpu_startup */ + curpcb = &proc0.p_addr->u_pcb; + + /* + * Initialize the I/O port and I/O mem extent maps. + * Note: we don't have to check the return value since + * creation of a fixed extent map will never fail (since + * descriptor storage has already been allocated). + * + * N.B. The iomem extent manages _all_ physical addresses + * on the machine. When the amount of RAM is found, the two + * extents of RAM are allocated from the map (0 -> ISA hole + * and end of ISA hole -> end of RAM). + */ + iomem_ex = extent_create("iomem", 0x0, 0xffffffff, M_DEVBUF, + (caddr_t)iomem_ex_storage, sizeof(iomem_ex_storage), + EX_NOCOALESCE|EX_NOWAIT); + +#if 0 + consinit(); /* XXX SHOULD NOT BE DONE HERE */ +#endif + + splraise(-1); + enable_intr(); + + avail_end = sh3_trunc_page(IOM_RAM_END + 1); + + printf("initSH3\r\n"); + + /* + * Calculate check sum + */ + { + u_short *p, sum; + int size; + + size = etext - _start; + p = (u_short *)_start; + sum = 0; + size >>= 1; + while (size--) + sum += *p++; + printf("Check Sum = 0x%x\r\n", sum); + } + /* + * Allocate the physical addresses used by RAM from the iomem + * extent map. This is done before the addresses are + * page rounded just to make sure we get them all. + */ + if (extent_alloc_region(iomem_ex, IOM_RAM_BEGIN, + (IOM_RAM_END-IOM_RAM_BEGIN) + 1, + EX_NOWAIT)) { + /* XXX What should we do? */ + printf("WARNING: CAN'T ALLOCATE RAM MEMORY FROM IOMEM EXTENT MAP!\n"); + } + + /* number of pages of physmem addr space */ + physmem = btoc(IOM_RAM_END - IOM_RAM_BEGIN +1); +#ifdef TODO + dumpmem = physmem; +#endif + + /* + * Initialize for pmap_free_pages and pmap_next_page. + * These guys should be page-aligned. + */ + if (physmem < btoc(2 * 1024 * 1024)) { + printf("warning: too little memory available; " + "have %d bytes, want %d bytes\n" + "running in degraded mode\n" + "press a key to confirm\n\n", + ctob(physmem), 2*1024*1024); + cngetc(); + } + + /* Call pmap initialization to make new kernel address space */ + pmap_bootstrap(atdevbase); + + /* + * Initialize error message buffer (at end of core). + */ + initmsgbuf((caddr_t)msgbuf_paddr, round_page(MSGBUFSIZE)); + + /* + * set boot device information + */ + setup_bootinfo(); + +#if 0 + sh3_cache_on(); +#endif + + /* setup proc0 stack */ + sp = avail + NBPG + USPACE - 16 - sizeof(struct trapframe); + + /* + * XXX We can't return here, because we change stack pointer. + * So jump to return address directly. + */ + __asm __volatile ("jmp @%0; mov %1, r15" :: "r"(pc), "r"(sp)); +} + +void +setup_bootinfo(void) +{ + struct btinfo_bootdisk *help; + + *(int *)bootinfo = 1; + help = (struct btinfo_bootdisk *)(bootinfo + sizeof(int)); + help->biosdev = 0; + help->partition = 0; + ((struct btinfo_common *)help)->len = sizeof(struct btinfo_bootdisk); + ((struct btinfo_common *)help)->type = BTINFO_BOOTDISK; +} + +void * +lookup_bootinfo(type) + int type; +{ + struct btinfo_common *help; + int n = *(int*)bootinfo; + help = (struct btinfo_common *)(bootinfo + sizeof(int)); + while (n--) { + if (help->type == type) + return (help); + help = (struct btinfo_common *)((char*)help + help->len); + } + return (0); +} + + +/* + * consinit: + * initialize the system console. + * XXX - shouldn't deal with this initted thing, but then, + * it shouldn't be called from init386 either. + */ +void +consinit() +{ + static int initted; + + if (initted) + return; + initted = 1; + + cninit(); + +#ifdef DDB + ddb_init(); +#endif +} + +void +cpu_reset() +{ + + disable_intr(); + + Sh3Reset(); + for (;;) + ; +} + +int +bus_space_map (t, addr, size, flags, bshp) + bus_space_tag_t t; + bus_addr_t addr; + bus_size_t size; + int flags; + bus_space_handle_t *bshp; +{ + + *bshp = (bus_space_handle_t)addr; + + return 0; +} + +int +sh_memio_subregion(t, bsh, offset, size, nbshp) + bus_space_tag_t t; + bus_space_handle_t bsh; + bus_size_t offset, size; + bus_space_handle_t *nbshp; +{ + + *nbshp = bsh + offset; + return (0); +} + +int +sh_memio_alloc(t, rstart, rend, size, alignment, boundary, flags, + bpap, bshp) + bus_space_tag_t t; + bus_addr_t rstart, rend; + bus_size_t size, alignment, boundary; + int flags; + bus_addr_t *bpap; + bus_space_handle_t *bshp; +{ + *bshp = *bpap = rstart; + + return (0); +} + +void +sh_memio_free(t, bsh, size) + bus_space_tag_t t; + bus_space_handle_t bsh; + bus_size_t size; +{ + +} + +void +sh_memio_unmap(t, bsh, size) + bus_space_tag_t t; + bus_space_handle_t bsh; + bus_size_t size; +{ + return; +} + +#ifdef SH4_PCMCIA + +int +shpcmcia_memio_map(t, bpa, size, flags, bshp) + bus_space_tag_t t; + bus_addr_t bpa; + bus_size_t size; + int flags; + bus_space_handle_t *bshp; +{ + int error; + struct extent *ex; + bus_space_tag_t pt = t & ~SH3_BUS_SPACE_PCMCIA_8BIT; + + if (pt != SH3_BUS_SPACE_PCMCIA_IO && + pt != SH3_BUS_SPACE_PCMCIA_MEM && + pt != SH3_BUS_SPACE_PCMCIA_ATT) { + *bshp = (bus_space_handle_t)bpa; + + return 0; + } + + ex = iomem_ex; + +#if 0 + /* + * Before we go any further, let's make sure that this + * region is available. + */ + error = extent_alloc_region(ex, bpa, size, + EX_NOWAIT | EX_MALLOCOK ); + if (error){ + printf("sh3_pcmcia_memio_map:extent_alloc_region error\n"); + return (error); + } +#endif + + /* + * For memory space, map the bus physical address to + * a kernel virtual address. + */ + error = shpcmcia_mem_add_mapping(bpa, size, (int)t, bshp ); +#if 0 + if (error) { + if (extent_free(ex, bpa, size, EX_NOWAIT | EX_MALLOCOK )) { + printf("sh3_pcmcia_memio_map: pa 0x%lx, size 0x%lx\n", + bpa, size); + printf("sh3_pcmcia_memio_map: can't free region\n"); + } + } +#endif + + return (error); +} + +int +shpcmcia_mem_add_mapping(bpa, size, type, bshp) + bus_addr_t bpa; + bus_size_t size; + int type; + bus_space_handle_t *bshp; +{ + u_long pa, endpa; + vaddr_t va; + pt_entry_t *pte; + unsigned int m = 0; + int io_type = type & ~SH3_BUS_SPACE_PCMCIA_8BIT; + + pa = sh3_trunc_page(bpa); + endpa = sh3_round_page(bpa + size); + +#ifdef DIAGNOSTIC + if (endpa <= pa) + panic("sh3_pcmcia_mem_add_mapping: overflow"); +#endif + + va = uvm_km_valloc(kernel_map, endpa - pa); + if (va == 0){ + printf("shpcmcia_add_mapping: nomem \n"); + return (ENOMEM); + } + + *bshp = (bus_space_handle_t)(va + (bpa & PGOFSET)); + + if( io_type == SH3_BUS_SPACE_PCMCIA_IO ){ + m = PG_PCMCIA_IO; + } + else if( io_type == SH3_BUS_SPACE_PCMCIA_MEM ){ + m = PG_PCMCIA_MEM; + } + else if( io_type == SH3_BUS_SPACE_PCMCIA_ATT ){ + m = PG_PCMCIA_ATT; + } + + if( type & SH3_BUS_SPACE_PCMCIA_8BIT ){ + m |= PG_PCMCIA_8; + } + + for (; pa < endpa; pa += NBPG, va += NBPG) { + pmap_enter(pmap_kernel(), va, pa, + VM_PROT_READ | VM_PROT_WRITE, TRUE, 0); + + pte = kvtopte(va); + *pte &= ~PG_N; + *pte |= m; + pmap_update_pg(va); + } + + return 0; +} + +void +shpcmcia_memio_unmap(t, bsh, size) + bus_space_tag_t t; + bus_space_handle_t bsh; + bus_size_t size; +{ + struct extent *ex; + u_long va, endva; + bus_addr_t bpa; + bus_space_tag_t pt = t & ~SH3_BUS_SPACE_PCMCIA_8BIT; + + if (pt != SH3_BUS_SPACE_PCMCIA_IO && + pt != SH3_BUS_SPACE_PCMCIA_MEM && + pt != SH3_BUS_SPACE_PCMCIA_ATT) { + return ; + } + + ex = iomem_ex; + + va = sh3_trunc_page(bsh); + endva = sh3_round_page(bsh + size); + +#ifdef DIAGNOSTIC + if (endva <= va) + panic("sh3_pcmcia_memio_unmap: overflow"); +#endif + + bpa = pmap_extract(pmap_kernel(), va) + (bsh & PGOFSET); + + /* + * Free the kernel virtual mapping. + */ + uvm_km_free(kernel_map, va, endva - va); + +#if 0 + if (extent_free(ex, bpa, size, + EX_NOWAIT | EX_MALLOCOK)) { + printf("sh3_pcmcia_memio_unmap: %s 0x%lx, size 0x%lx\n", + "pa", bpa, size); + printf("sh3_pcmcia_memio_unmap: can't free region\n"); + } +#endif +} + +void +shpcmcia_memio_free(t, bsh, size) + bus_space_tag_t t; + bus_space_handle_t bsh; + bus_size_t size; +{ + + /* sh3_pcmcia_memio_unmap() does all that we need to do. */ + shpcmcia_memio_unmap(t, bsh, size); +} + +int +shpcmcia_memio_subregion(t, bsh, offset, size, nbshp) + bus_space_tag_t t; + bus_space_handle_t bsh; + bus_size_t offset, size; + bus_space_handle_t *nbshp; +{ + + *nbshp = bsh + offset; + return (0); +} + +#endif /* SH4_PCMCIA */ + +#if !defined(DONT_INIT_BSC) +/* + * InitializeBsc + * : BSC(Bus State Controler) + */ +void InitializeBsc __P((void)); + +void +InitializeBsc() +{ + + /* + * Drive RAS,CAS in stand by mode and bus release mode + * Area0 = Normal memory, Area5,6=Normal(no burst) + * Area2 = Normal memory, Area3 = SDRAM, Area5 = Normal memory + * Area4 = Normal Memory + * Area6 = Normal memory + */ + SHREG_BCR1 = BSC_BCR1_VAL; + + /* + * Bus Width + * Area4: Bus width = 16bit + * Area6,5 = 16bit + * Area1 = 8bit + * Area2,3: Bus width = 32bit + */ + SHREG_BCR2 = BSC_BCR2_VAL; + + /* + * Idle cycle number in transition area and read to write + * Area6 = 3, Area5 = 3, Area4 = 3, Area3 = 3, Area2 = 3 + * Area1 = 3, Area0 = 3 + */ + SHREG_WCR1 = BSC_WCR1_VAL; + + /* + * Wait cycle + * Area 6 = 6 + * Area 5 = 2 + * Area 4 = 10 + * Area 3 = 3 + * Area 2,1 = 3 + * Area 0 = 6 + */ + SHREG_WCR2 = BSC_WCR2_VAL; + +#if defined(SH4) && defined(BSC_WCR3_VAL) + SHREG_WCR3 = BSC_WCR3_VAL; +#endif + + /* + * RAS pre-charge = 2cycle, RAS-CAS delay = 3 cycle, + * write pre-charge=1cycle + * CAS before RAS refresh RAS assert time = 3 cycle + * Disable burst, Bus size=32bit, Column Address=10bit, Refresh ON + * CAS before RAS refresh ON, EDO DRAM + */ + SHREG_MCR = BSC_MCR_VAL; + +#if defined(BSC_SDMR2_VAL) +#define SDMR2 (*(volatile unsigned char *)BSC_SDMR2_VAL) + + SDMR2 = 0; +#endif + +#if defined(BSC_SDMR3_VAL) +#if !(defined(COMPUTEXEVB) && defined(SH7709A)) +#define SDMR3 (*(volatile unsigned char *)BSC_SDMR3_VAL) + + SDMR3 = 0; +#else +#define ADDSET (*(volatile unsigned short *)0x1A000000) +#define ADDRST (*(volatile unsigned short *)0x18000000) +#define SDMR3 (*(volatile unsigned char *)BSC_SDMR3_VAL) + + ADDSET = 0; + SDMR3 = 0; + ADDRST = 0; +#endif +#endif + + /* + * PCMCIA Control Register + * OE/WE assert delay 3.5 cycle + * OE/WE negate-address delay 3.5 cycle + */ +#ifdef BSC_PCR_VAL + SHREG_PCR = BSC_PCR_VAL; +#endif + + /* + * Refresh Timer Control/Status Register + * Disable interrupt by CMF, closk 1/16, Disable OVF interrupt + * Count Limit = 1024 + * In following statement, the reason why high byte = 0xa5(a4 in RFCR) + * is the rule of SH3 in writing these register. + */ + SHREG_RTCSR = BSC_RTCSR_VAL; + + + /* + * Refresh Timer Counter + * Initialize to 0 + */ +#ifdef BSC_RTCNT_VAL + SHREG_RTCNT = BSC_RTCNT_VAL; +#endif + + /* set Refresh Time Constant Register */ + SHREG_RTCOR = BSC_RTCOR_VAL; + + /* init Refresh Count Register */ +#ifdef BSC_RFCR_VAL + SHREG_RFCR = BSC_RFCR_VAL; +#endif + + /* Set Clock mode (make internal clock double speed) */ + + SHREG_FRQCR = FRQCR_VAL; + +#ifndef MMEYE_NO_CACHE + /* Cache ON */ + SHREG_CCR = CCR_CE; +#endif +} +#endif + +void +sh3_cache_on(void) +{ +#ifndef MMEYE_NO_CACHE + /* Cache ON */ + SHREG_CCR = CCR_CE; + SHREG_CCR = CCR_CF | CCR_CE; /* cache clear */ + SHREG_CCR = CCR_CE; /* cache on */ +#endif +} + +#ifdef SH4 +void +sh4_cache_flush(addr) + vaddr_t addr; +{ +#if 1 +#define SH_ADDR_ARRAY_BASE_ADDR 0xf4000000 +#define WRITE_ADDR_ARRAY( entry ) \ + (*(volatile u_int32_t *)(SH_ADDR_ARRAY_BASE_ADDR|(entry)|0x00)) + + int entry; + + entry = ((u_int32_t)addr) & 0x3fe0; + + WRITE_ADDR_ARRAY(entry) = 0; +#else + volatile int *p = (int *)IOM_RAM_BEGIN; + int i; + /* volatile */int d; + + for(i = 0; i < 512; i++){ + d = *p; + p += 8; + } +#endif +} +#endif + +#include + + /* XXX This value depends on physical available memory */ +#define OSIMAGE_BUF_ADDR (IOM_RAM_BEGIN + 0x00400000) + +void +LoadAndReset(osimage) + char *osimage; +{ + void *buf_addr; + u_long size; + u_long *src; + u_long *dest; + u_long csum = 0; + u_long csum2 = 0; + u_long size2; + + printf("LoadAndReset: copy start\n"); + buf_addr = (void *)OSIMAGE_BUF_ADDR; + + size = *(u_long *)osimage; + src = (u_long *)osimage; + dest = buf_addr; + + size = (size + sizeof(u_long) * 2 + 3) >> 2; + size2 = size; + + while (size--) { + csum += *src; + *dest++ = *src++; + } + + dest = buf_addr; + while (size2--) + csum2 += *dest++; + + printf("LoadAndReset: copy end[%lx,%lx]\n", csum, csum2); + printf("start XLoadAndReset\n"); + + /* mask all externel interrupt (XXX) */ + + XLoadAndReset(buf_addr); +} diff --git a/sys/arch/dreamcast/dreamcast/shb.c b/sys/arch/dreamcast/dreamcast/shb.c new file mode 100644 index 000000000000..35bec18025fa --- /dev/null +++ b/sys/arch/dreamcast/dreamcast/shb.c @@ -0,0 +1,849 @@ +/* $NetBSD: shb.c,v 1.1 2000/12/11 18:19:13 marcus Exp $ */ + +/*- + * Copyright (c) 1993, 1994 Charles Hannum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles Hannum. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#if 0 +#include +#include +#include +#endif + +#include + +int shbmatch __P((struct device *, struct cfdata *, void *)); +void shbattach __P((struct device *, struct device *, void *)); +int shbprint __P((void *, const char *)); +void intr_calculatemasks __P((void)); +int fakeintr __P((void *)); +void *shb_intr_establish __P((int irq, int type, + int level, int (*ih_fun)(void *), void *ih_arg)); +int intrhandler __P((int, int, int, int, struct trapframe)); +int check_ipending __P((int, int, int, int, struct trapframe)); +void mask_irq __P((int)); +void unmask_irq __P((int)); +void Xsoftserial __P((void)); +void Xsoftnet __P((void)); +void Xsoftclock __P((void)); +void init_soft_intr_handler __P((void)); + +struct cfattach shb_ca = { + sizeof(struct shb_softc), shbmatch, shbattach +}; + +int shbsearch __P((struct device *, struct cfdata *, void *)); + +int +shbmatch(parent, cf, aux) + struct device *parent; + struct cfdata *cf; + void *aux; +{ + struct shbus_attach_args *iba = aux; + + if (strcmp(iba->iba_busname, cf->cf_driver->cd_name)) + return (0); + + return (1); +} + +void +shbattach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct shb_softc *sc = (struct shb_softc *)self; + struct shbus_attach_args *iba = aux; + + printf("\n"); + + sc->sc_iot = iba->iba_iot; + sc->sc_memt = iba->iba_memt; + + TAILQ_INIT(&sc->sc_subdevs); + config_search(shbsearch, self, NULL); + + init_soft_intr_handler(); +} + +int +shbprint(aux, isa) + void *aux; + const char *isa; +{ + struct shb_attach_args *ia = aux; + + if (ia->ia_iosize) + printf(" port 0x%x", ia->ia_iobase); + if (ia->ia_iosize > 1) + printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1); + if (ia->ia_msize) + printf(" iomem 0x%x", ia->ia_maddr); + if (ia->ia_msize > 1) + printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1); + if (ia->ia_irq != IRQUNK) + printf(" irq %d", ia->ia_irq); + if (ia->ia_drq != DRQUNK) + printf(" drq %d", ia->ia_drq); + if (ia->ia_drq2 != DRQUNK) + printf(" drq2 %d", ia->ia_drq2); + return (UNCONF); +} + +int +shbsearch(parent, cf, aux) + struct device *parent; + struct cfdata *cf; + void *aux; +{ + struct shb_softc *sc = (struct shb_softc *)parent; + struct shb_attach_args ia; + int tryagain; + + do { + ia.ia_iot = sc->sc_iot; + ia.ia_memt = sc->sc_memt; + /* ia.ia_dmat = sc->sc_dmat; */ + /* ia.ia_ic = sc->sc_ic; */ + ia.ia_iobase = cf->cf_iobase; + ia.ia_iosize = 0x666; /* cf->cf_iosize; */ + ia.ia_maddr = cf->cf_maddr; + ia.ia_msize = cf->cf_msize; + ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq; + ia.ia_drq = cf->cf_drq; + ia.ia_drq2 = cf->cf_drq2; + /* ia.ia_delaybah = sc->sc_delaybah; */ + + tryagain = 0; + if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) { + config_attach(parent, cf, &ia, shbprint); + tryagain = (cf->cf_fstate == FSTATE_STAR); + } + } while (tryagain); + + return (0); +} + +char * +shb_intr_typename(type) + int type; +{ + + switch (type) { + case IST_NONE : + return ("none"); + case IST_PULSE: + return ("pulsed"); + case IST_EDGE: + return ("edge-triggered"); + case IST_LEVEL: + return ("level-triggered"); + default: + panic("shb_intr_typename: invalid type %d", type); + } +} +int intrtype[ICU_LEN], intrmask[ICU_LEN], intrlevel[ICU_LEN]; +struct intrhand *intrhand[ICU_LEN]; + +/* + * Recalculate the interrupt masks from scratch. + * We could code special registry and deregistry versions of this function that + * would be faster, but the code would be nastier, and we don't expect this to + * happen very much anyway. + */ +void +intr_calculatemasks() +{ + int irq, level; + struct intrhand *q; + + /* First, figure out which levels each IRQ uses. */ + for (irq = 0; irq < ICU_LEN; irq++) { + int levels = 0; + for (q = intrhand[irq]; q; q = q->ih_next) + levels |= 1 << q->ih_level; + intrlevel[irq] = levels; + } + + /* Then figure out which IRQs use each level. */ + for (level = 0; level < NIPL; level++) { + int irqs = 0; + for (irq = 0; irq < ICU_LEN; irq++) + if (intrlevel[irq] & (1 << level)) + irqs |= 1 << irq; + imask[level] = irqs; + } + + /* + * Initialize soft interrupt masks to block themselves. + */ + imask[IPL_SOFTCLOCK] |= 1 << SIR_CLOCK; + imask[IPL_SOFTNET] |= 1 << SIR_NET; + imask[IPL_SOFTSERIAL] |= 1 << SIR_SERIAL; + + /* + * IPL_NONE is used for hardware interrupts that are never blocked, + * and do not block anything else. + */ + imask[IPL_NONE] = 0; + + /* + * Enforce a hierarchy that gives slow devices a better chance at not + * dropping data. + */ + imask[IPL_SOFTCLOCK] |= imask[IPL_NONE]; + imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK]; + imask[IPL_BIO] |= imask[IPL_SOFTNET]; + imask[IPL_NET] |= imask[IPL_BIO]; + imask[IPL_SOFTSERIAL] |= imask[IPL_NET]; + imask[IPL_TTY] |= imask[IPL_SOFTSERIAL]; + + /* + * There are tty, network and disk drivers that use free() at interrupt + * time, so imp > (tty | net | bio). + */ + imask[IPL_IMP] |= imask[IPL_TTY]; + + imask[IPL_AUDIO] |= imask[IPL_IMP]; + + /* + * Since run queues may be manipulated by both the statclock and tty, + * network, and disk drivers, clock > imp. + */ + imask[IPL_CLOCK] |= imask[IPL_AUDIO]; + + /* + * IPL_HIGH must block everything that can manipulate a run queue. + */ + imask[IPL_HIGH] |= imask[IPL_CLOCK]; + + /* + * We need serial drivers to run at the absolute highest priority to + * avoid overruns, so serial > high. + */ + imask[IPL_SERIAL] |= imask[IPL_HIGH]; + + /* And eventually calculate the complete masks. */ + for (irq = 0; irq < ICU_LEN; irq++) { + int irqs = 1 << irq; + for (q = intrhand[irq]; q; q = q->ih_next) + irqs |= imask[q->ih_level]; + intrmask[irq] = irqs; + } + +#ifdef TODO + /* Lastly, determine which IRQs are actually in use. */ + { + int irqs = 0; + for (irq = 0; irq < ICU_LEN; irq++) + if (intrhand[irq]) + irqs |= 1 << irq; + if (irqs >= 0x100) /* any IRQs >= 8 in use */ + irqs |= 1 << IRQ_SLAVE; + imen = ~irqs; + SET_ICUS(); + } +#endif + +} + +/* + * Set up an interrupt handler to start being called. + * XXX PRONE TO RACE CONDITIONS, UGLY, 'INTERESTING' INSERTION ALGORITHM. + */ +void * +shb_intr_establish(irq, type, level, ih_fun, ih_arg) + int irq; + int type; + int level; + int (*ih_fun) __P((void *)); + void *ih_arg; +{ + struct intrhand **p, *q, *ih; + static struct intrhand fakehand = {fakeintr}; + + /* no point in sleeping unless someone can free memory. */ + ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK); + if (ih == NULL) + panic("shb_intr_establish: can't malloc handler info"); + +#ifdef TODO + if (type == IST_NONE) + panic("intr_establish: bogus irq or type"); + + switch (intrtype[irq]) { + case IST_NONE: + intrtype[irq] = type; + break; + case IST_EDGE: + case IST_LEVEL: + if (type == intrtype[irq]) + break; + case IST_PULSE: + if (type != IST_NONE) + panic("intr_establish: can't share %s with %s", + shb_intr_typename(intrtype[irq]), + shb_intr_typename(type)); + break; + } +#endif + + /* + * Figure out where to put the handler. + * This is O(N^2), but we want to preserve the order, and N is + * generally small. + */ + for (p = &intrhand[irq]; (q = *p) != NULL; p = &q->ih_next) + ; + + /* + * Actually install a fake handler momentarily, since we might be doing + * this with interrupts enabled and don't want the real routine called + * until masking is set up. + */ + fakehand.ih_level = level; + *p = &fakehand; + + intr_calculatemasks(); + + /* + * Poke the real handler in now. + */ + ih->ih_fun = ih_fun; + ih->ih_arg = ih_arg; + ih->ih_count = 0; + ih->ih_next = NULL; + ih->ih_level = level; + ih->ih_irq = irq; + *p = ih; + + /* unmask H/W interrupt mask register */ + if (irq < SHB_MAX_HARDINTR) + unmask_irq(irq); + + return (ih); +} + +int +fakeintr(arg) + void *arg; +{ + + return 0; +} + + +#define IRQ_BIT(irq_num) (1 << (irq_num)) + +/*ARGSUSED*/ +int /* 1 = check ipending on return, 0 = fast intr return */ +intrhandler(p1, p2, p3, p4, frame) + int p1, p2, p3, p4; /* dummy param */ + struct trapframe frame; +{ + unsigned int irl; + struct intrhand *ih; + unsigned int irq_num; + int ocpl; + +#if 0 + printf("intr_handler:int_no %x spc %x ssr %x r15 %x curproc %x\n", + frame.tf_trapno, frame.tf_spc, frame.tf_ssr, frame.tf_r15, + (int)curproc); +#endif + + irl = (unsigned int)frame.tf_trapno; + if (irl >= INTEVT_SOFT) { + /* This is software interrupt */ + irq_num = (irl - INTEVT_SOFT); + } else if (irl == INTEVT_TMU1) { + irq_num = TMU1_IRQ; + } else if (IS_INTEVT_SCI0(irl)) { /* XXX TOO DIRTY */ + irq_num = SCI_IRQ; +#ifdef SH4 + } else if ((irl & 0x0f00) == INTEVT_SCIF) { + irq_num = SCIF_IRQ; +#endif + } else + irq_num = (irl - 0x200) >> 5; + + mask_irq(irq_num); + + if (cpl & IRQ_BIT(irq_num)) { + ipending |= IRQ_BIT(irq_num); + return 0; + } + + ocpl = cpl; + cpl |= intrmask[irq_num]; + ih = intrhand[irq_num]; + if (ih == NULL) { + + /* this is stray interrupt */ + cpl = ocpl; + +#if 0 /* This is commented by T.Horiuchi */ + unmask_irq(irq_num); +#endif + return 1; + } + + enable_ext_intr(); + while (ih) { + if (ih->ih_arg) + (*ih->ih_fun)(ih->ih_arg); + else + (*ih->ih_fun)(&frame); + ih = ih->ih_next; + } + disable_ext_intr(); + + cpl = ocpl; + + unmask_irq(irq_num); + +#if 0 + printf("intr_handler:end\n"); +#endif + return 1; +} + +int /* 1 = resume ihandler on return, 0 = go to fast intr return */ +check_ipending(p1, p2, p3, p4, frame) + int p1, p2, p3, p4; /* dummy param */ + struct trapframe frame; +{ + int ir; + int i; + int mask; +#define MASK_LEN 32 + + restart: + ir = (~cpl) & ipending; + if (ir == 0) + return 0; + +#if 0 + mask = 1; + for (i = 0; i < MASK_LEN; i++, mask <<= 1) { + if (ir & mask) + break; + } +#else + mask = 1 << IRQ_LOW; + for (i = IRQ_LOW; i <= IRQ_HIGH; i++, mask <<= 1) { + if (ir & mask) + break; + } + if (IRQ_HIGH < i) { + mask = 1 << SIR_LOW; + for (i = SIR_LOW; i <= SIR_HIGH; i++, mask <<= 1) { + if (ir & mask) + break; + } + } +#endif + + if ((mask & ipending) == 0) + goto restart; + + ipending &= ~mask; + + if (i < SHB_MAX_HARDINTR) { + /* set interrupt event register, this value is referenced in ihandler */ + SHREG_INTEVT = (i << 5) + 0x200; + } else { + /* This is software interrupt */ + SHREG_INTEVT = INTEVT_SOFT+i; + } + + return 1; +} + +#if !defined(SH4) + +#ifdef SH7709A_BROKEN_IPR /* broken IPR patch */ + +#define IPRA 0 +#define IPRB 1 +#define IPRC 2 +#define IPRD 3 +#define IPRE 4 + +static unsigned short ipr[ 5 ]; + +#endif /* SH7709A_BROKEN_IPR */ + +void +mask_irq(irq) + int irq; +{ + switch (irq) { + case TMU1_IRQ: +#ifdef SH7709A_BROKEN_IPR + ipr[IPRA] &= ~((15)<<8); + SHREG_IPRA = ipr[IPRA]; +#else + SHREG_IPRA &= ~((15)<<8); +#endif + break; + case SCI_IRQ: +#ifdef SH7709A_BROKEN_IPR + ipr[IPRB] &= ~((15)<<4); + SHREG_IPRB = ipr[IPRB]; +#else + SHREG_IPRB &= ~((15)<<4); +#endif + break; +#if defined(SH7709) || defined(SH7709A) || defined(SH7729) + case SCIF_IRQ: +#ifdef SH7709A_BROKEN_IPR + ipr[IPRE] &= ~((15)<<4); + SHREG_IPRE = ipr[IPRE]; +#else + SHREG_IPRE &= ~((15)<<4); +#endif + break; +#endif +#if 0 + case IRQ0_IRQ: + SHREG_IPRC &= ~(15); + break; + case IRQ1_IRQ: + SHREG_IPRC &= ~((15)<<4); + break; + case IRQ2_IRQ: + SHREG_IPRC &= ~((15)<<8); + break; + case DMAC_IRQ: + SHREG_IPRE &= ~((15)<<12); + break; +#endif + default: + if (irq < SHB_MAX_HARDINTR) + printf("masked unknown irq(%d)!\n", irq); + } +} + +void +unmask_irq(irq) + int irq; +{ + + switch (irq) { + case TMU1_IRQ: +#ifdef SH7709A_BROKEN_IPR + ipr[ IPRA ] |= ((15 - irq)<<8); + SHREG_IPRA = ipr[ IPRA ]; +#else + SHREG_IPRA |= ((15 - irq)<<8); +#endif + break; + case SCI_IRQ: +#ifdef SH7709A_BROKEN_IPR + ipr[IPRB] |= ((15 - irq)<<4); + SHREG_IPRB = ipr[IPRB]; +#else + SHREG_IPRB |= ((15 - irq)<<4); +#endif + break; +#if defined(SH7709) || defined(SH7709A) || defined(SH7729) + case SCIF_IRQ: +#ifdef SH7709A_BROKEN_IPR + ipr[ IPRE ] |= ((15 - irq)<<4); + SHREG_IPRE = ipr[ IPRE ]; +#else + SHREG_IPRE |= ((15 - irq)<<4); +#endif + break; +#endif +#if 0 + case IRQ0_IRQ: + SHREG_IPRC |= (15 - irq); + break; + case IRQ1_IRQ: + SHREG_IPRC |= ((15 - irq)<<4); + break; + case IRQ2_IRQ: + SHREG_IPRC |= ((15 - irq)<<8); + break; + case DMAC_IRQ: + SHREG_IPRE |= ((15 - irq)<<12); + break; +#endif + default: + if (irq < SHB_MAX_HARDINTR) + printf("unmasked unknown irq(%d)!\n", irq); + } +} +#else +void +mask_irq(irq) + int irq; +{ + switch (irq) { + case TMU1_IRQ: + SHREG_IPRA &= ~((15)<<8); + break; + case SCI_IRQ: + SHREG_IPRB &= ~((15)<<4); + break; + case SCIF_IRQ: + SHREG_IPRC &= ~((15)<<4); + break; +#if 0 + case IRQ0_IRQ: + SHREG_IPRC &= ~(15); + break; + case IRQ1_IRQ: + SHREG_IPRC &= ~((15)<<4); + break; + case IRQ2_IRQ: + SHREG_IPRC &= ~((15)<<8); + break; + case DMAC_IRQ: + SHREG_IPRE &= ~((15)<<12); + break; +#endif + default: + if (irq < SHB_MAX_HARDINTR) + printf("masked unknown irq(%d)!\n", irq); + } +} + +void +unmask_irq(irq) + int irq; +{ + + switch (irq) { + case TMU1_IRQ: + SHREG_IPRA |= ((15 - irq)<<8); + break; + case SCI_IRQ: + SHREG_IPRB |= ((15 - irq)<<4); + break; + case SCIF_IRQ: + SHREG_IPRC |= ((15 - irq)<<4); + break; +#if 0 + case IRQ0_IRQ: + SHREG_IPRC |= (15 - irq); + break; + case IRQ1_IRQ: + SHREG_IPRC |= ((15 - irq)<<4); + break; + case IRQ2_IRQ: + SHREG_IPRC |= ((15 - irq)<<8); + break; + case DMAC_IRQ: + SHREG_IPRE |= ((15 - irq)<<12); + break; +#endif + default: + if (irq < SHB_MAX_HARDINTR) + printf("unmasked unknown irq(%d)!\n", irq); + } +} +#endif + +void +init_soft_intr_handler(void) +{ +#include "sci.h" +#include "scif.h" +#if ((NSCI > 0) || (NSCIF > 0)) + shb_intr_establish(SIR_SERIAL, IST_LEVEL, IPL_SOFTSERIAL, + (int (*) (void *))Xsoftserial, NULL); +#endif + + shb_intr_establish(SIR_NET, IST_LEVEL, IPL_SOFTNET, + (int (*) (void *))Xsoftnet, NULL); + + shb_intr_establish(SIR_CLOCK, IST_LEVEL, IPL_SOFTCLOCK, + (int (*) (void *))Xsoftclock, NULL); +} + +#if ((NSCI > 0) || (NSCIF > 0)) +void scisoft __P((void *)); +void scifsoft __P((void *)); + +void +Xsoftserial(void) +{ +#if (NSCI > 0) + scisoft(NULL); +#endif +#if (NSCIF > 0) + scifsoft(NULL); +#endif +} +#endif + +void +Xsoftnet(void) +{ + int s, ni; + + s = splhigh(); + ni = netisr; + netisr = 0; + splx(s); + +#define DONETISR(bit, fn) do { \ + if (ni & (1 << bit)) \ + fn(); \ +} while (0) + +#include + +#undef DONETISR +} + +void +Xsoftclock(void) +{ + + softclock(); +} + +#define LEGAL_IRQ(x) ((x) >= 0 && (x) < SHB_MAX_HARDINTR && (x) != 2) + +int +sh_intr_alloc(mask, type, irq) + int mask; + int type; + int *irq; +{ + int i, tmp, bestirq, count; + struct intrhand **p, *q; + + if (type == IST_NONE) + panic("intr_alloc: bogus type"); + + bestirq = -1; + count = -1; + + /* some interrupts should never be dynamically allocated */ + mask &= 0xdef8; + + /* + * XXX some interrupts will be used later (6 for fdc, 12 for pms). + * the right answer is to do "breadth-first" searching of devices. + */ + mask &= 0xefbf; + + for (i = 0; i < SHB_MAX_HARDINTR; i++) { + if (LEGAL_IRQ(i) == 0 || (mask & (1 << i)) == 0) + continue; + + switch(intrtype[i]) { + case IST_NONE: + /* + * if nothing's using the irq, just return it + */ + *irq = i; + return (0); + + case IST_EDGE: + case IST_LEVEL: + if (type != intrtype[i]) + continue; + /* + * if the irq is shareable, count the number of other + * handlers, and if it's smaller than the last irq like + * this, remember it + * + * XXX We should probably also consider the + * interrupt level and stick IPL_TTY with other + * IPL_TTY, etc. + */ + for (p = &intrhand[i], tmp = 0; (q = *p) != NULL; + p = &q->ih_next, tmp++) + ; + if ((bestirq == -1) || (count > tmp)) { + bestirq = i; + count = tmp; + } + break; + + case IST_PULSE: + /* this just isn't shareable */ + continue; + } + } + + if (bestirq == -1) + return (1); + + *irq = bestirq; + + return (0); +} + +/* + * Deregister an interrupt handler. + */ +void +shb_intr_disestablish(ic, arg) + void *ic; + void *arg; +{ + struct intrhand *ih = arg; + int irq = ih->ih_irq; + struct intrhand **p, *q; + + mask_irq(irq); + + /* + * Remove the handler from the chain. + * This is O(n^2), too. + */ + for (p = &intrhand[irq]; (q = *p) != NULL && q != ih; p = &q->ih_next) + ; + if (q) + *p = q->ih_next; + else + panic("shb_intr_disestablish: handler not registered"); + free(ih, M_DEVBUF); +} diff --git a/sys/arch/dreamcast/include/Makefile b/sys/arch/dreamcast/include/Makefile new file mode 100644 index 000000000000..c6bd6843d75e --- /dev/null +++ b/sys/arch/dreamcast/include/Makefile @@ -0,0 +1,14 @@ +# $NetBSD: Makefile,v 1.1 2000/12/11 18:19:13 marcus Exp $ + +KDIR= /sys/arch/dreamcast/include +INCSDIR= /usr/include/dreamcast + +INCS= ansi.h aout_machdep.h asm.h bootinfo.h bswap.h bus.h cdefs.h \ + coff_machdep.h conf.h cpu.h cpufunc.h cputypes.h db_machdep.h \ + disklabel.h elf_machdep.h endian.h endian_machdep.h float.h frame.h \ + ieee.h ieeefp.h int_types.h intr.h limits.h lock.h math.h mmeye.h \ + param.h pcb.h pio.h pmap.h proc.h profile.h psl.h pte.h ptrace.h \ + reg.h segments.h setjmp.h shbvar.h signal.h stdarg.h \ + trap.h types.h varargs.h vmparam.h + +.include diff --git a/sys/arch/dreamcast/include/ansi.h b/sys/arch/dreamcast/include/ansi.h new file mode 100644 index 000000000000..7bbbf0a89684 --- /dev/null +++ b/sys/arch/dreamcast/include/ansi.h @@ -0,0 +1,7 @@ +/* $NetBSD: ansi.h,v 1.1 2000/12/11 18:19:13 marcus Exp $ */ +#ifndef _DREAMCAST_ANSI_H_ +#define _DREAMCAST_ANSI_H_ + +#include + +#endif /* _DREAMCAST_ANSI_H_ */ diff --git a/sys/arch/dreamcast/include/aout_machdep.h b/sys/arch/dreamcast/include/aout_machdep.h new file mode 100644 index 000000000000..6b57168affd1 --- /dev/null +++ b/sys/arch/dreamcast/include/aout_machdep.h @@ -0,0 +1,7 @@ +/* $NetBSD: aout_machdep.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_AOUT_MACHDEP_H_ +#define _DREAMCAST_AOUT_MACHDEP_H_ + +#include + +#endif /* _DREAMCAST_AOUT_MACHDEP_H_ */ diff --git a/sys/arch/dreamcast/include/asm.h b/sys/arch/dreamcast/include/asm.h new file mode 100644 index 000000000000..97e9b98fd3e8 --- /dev/null +++ b/sys/arch/dreamcast/include/asm.h @@ -0,0 +1,7 @@ +/* $NetBSD: asm.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_ASM_H_ +#define _DREAMCAST_ASM_H_ + +#include + +#endif /* _DREAMCAST_ASM_H_ */ diff --git a/sys/arch/dreamcast/include/bootinfo.h b/sys/arch/dreamcast/include/bootinfo.h new file mode 100644 index 000000000000..2b803804dd62 --- /dev/null +++ b/sys/arch/dreamcast/include/bootinfo.h @@ -0,0 +1,7 @@ +/* $NetBSD: bootinfo.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_BOOTINFO_H_ +#define _DREAMCAST_BOOTINFO_H_ + +#include + +#endif /* _DREAMCAST_BOOTINFO_H_ */ diff --git a/sys/arch/dreamcast/include/bswap.h b/sys/arch/dreamcast/include/bswap.h new file mode 100644 index 000000000000..7cf1033d8b71 --- /dev/null +++ b/sys/arch/dreamcast/include/bswap.h @@ -0,0 +1,7 @@ +/* $NetBSD: bswap.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_BSWAP_H_ +#define _DREAMCAST_BSWAP_H_ + +#include + +#endif /* _DREAMCAST_BSWAP_H_ */ diff --git a/sys/arch/dreamcast/include/bus.h b/sys/arch/dreamcast/include/bus.h new file mode 100644 index 000000000000..5d1149c4c756 --- /dev/null +++ b/sys/arch/dreamcast/include/bus.h @@ -0,0 +1,7 @@ +/* $NetBSD: bus.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_BUS_H_ +#define _DREAMCAST_BUS_H_ + +#include + +#endif /* _DREAMCAST_BUS_H_ */ diff --git a/sys/arch/dreamcast/include/cdefs.h b/sys/arch/dreamcast/include/cdefs.h new file mode 100644 index 000000000000..c6fab5d89a7e --- /dev/null +++ b/sys/arch/dreamcast/include/cdefs.h @@ -0,0 +1,7 @@ +/* $NetBSD: cdefs.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_CDEFS_H_ +#define _DREAMCAST_CDEFS_H_ + +#include + +#endif /* _DREAMCAST_CDEFS_H_ */ diff --git a/sys/arch/dreamcast/include/coff_machdep.h b/sys/arch/dreamcast/include/coff_machdep.h new file mode 100644 index 000000000000..7dbb3dd2fa2a --- /dev/null +++ b/sys/arch/dreamcast/include/coff_machdep.h @@ -0,0 +1,7 @@ +/* $NetBSD: coff_machdep.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_COFF_MACHDEP_H_ +#define _DREAMCAST_COFF_MACHDEP_H_ + +#include + +#endif /* _DREAMCAST_COFF_MACHDEP_H_ */ diff --git a/sys/arch/dreamcast/include/conf.h b/sys/arch/dreamcast/include/conf.h new file mode 100644 index 000000000000..ba8b5e259b78 --- /dev/null +++ b/sys/arch/dreamcast/include/conf.h @@ -0,0 +1,47 @@ +/* $NetBSD: conf.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +bdev_decl(fd); +cdev_decl(fd); + +/* open, close, ioctl */ +#define cdev_wdog_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, seltrue, (dev_type_mmap((*))) enodev } + +cdev_decl(wdog); diff --git a/sys/arch/dreamcast/include/cpu.h b/sys/arch/dreamcast/include/cpu.h new file mode 100644 index 000000000000..3132f681079a --- /dev/null +++ b/sys/arch/dreamcast/include/cpu.h @@ -0,0 +1,7 @@ +/* $NetBSD: cpu.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_CPU_H_ +#define _DREAMCAST_CPU_H_ + +#include + +#endif /* _DREAMCAST_CPU_H_ */ diff --git a/sys/arch/dreamcast/include/cpufunc.h b/sys/arch/dreamcast/include/cpufunc.h new file mode 100644 index 000000000000..4aad6aaa4a97 --- /dev/null +++ b/sys/arch/dreamcast/include/cpufunc.h @@ -0,0 +1,7 @@ +/* $NetBSD: cpufunc.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_CPUFUNC_H_ +#define _DREAMCAST_CPUFUNC_H_ + +#include + +#endif /* _DREAMCAST_CPUFUNC_H_ */ diff --git a/sys/arch/dreamcast/include/cputypes.h b/sys/arch/dreamcast/include/cputypes.h new file mode 100644 index 000000000000..46fa40aee847 --- /dev/null +++ b/sys/arch/dreamcast/include/cputypes.h @@ -0,0 +1,7 @@ +/* $NetBSD: cputypes.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_CPUTYPES_H_ +#define _DREAMCAST_CPUTYPES_H_ + +#include + +#endif /* _DREAMCAST_CPUTYPES_H_ */ diff --git a/sys/arch/dreamcast/include/db_machdep.h b/sys/arch/dreamcast/include/db_machdep.h new file mode 100644 index 000000000000..29ae90eef2d8 --- /dev/null +++ b/sys/arch/dreamcast/include/db_machdep.h @@ -0,0 +1,7 @@ +/* $NetBSD: db_machdep.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_DB_MACHDEP_H_ +#define _DREAMCAST_DB_MACHDEP_H_ + +#include + +#endif /* _DREAMCAST_DB_MACHDEP_H_ */ diff --git a/sys/arch/dreamcast/include/disklabel.h b/sys/arch/dreamcast/include/disklabel.h new file mode 100644 index 000000000000..ee81bee47f8e --- /dev/null +++ b/sys/arch/dreamcast/include/disklabel.h @@ -0,0 +1,7 @@ +/* $NetBSD: disklabel.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_DISKLABEL_H_ +#define _DREAMCAST_DISKLABEL_H_ + +#include + +#endif /* _DREAMCAST_DISKLABEL_H_ */ diff --git a/sys/arch/dreamcast/include/elf_machdep.h b/sys/arch/dreamcast/include/elf_machdep.h new file mode 100644 index 000000000000..0676cff520be --- /dev/null +++ b/sys/arch/dreamcast/include/elf_machdep.h @@ -0,0 +1,7 @@ +/* $NetBSD: elf_machdep.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_ELF_MACHDEP_H_ +#define _DREAMCAST_ELF_MACHDEP_H_ + +#include + +#endif /* _DREAMCAST_ELF_MACHDEP_H_ */ diff --git a/sys/arch/dreamcast/include/endian.h b/sys/arch/dreamcast/include/endian.h new file mode 100644 index 000000000000..fff4f5438552 --- /dev/null +++ b/sys/arch/dreamcast/include/endian.h @@ -0,0 +1,3 @@ +/* $NetBSD: endian.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ + +#include diff --git a/sys/arch/dreamcast/include/endian_machdep.h b/sys/arch/dreamcast/include/endian_machdep.h new file mode 100644 index 000000000000..8aedd9bdc7b8 --- /dev/null +++ b/sys/arch/dreamcast/include/endian_machdep.h @@ -0,0 +1,8 @@ +/* $NetBSD: endian_machdep.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ + +#if 0 +#define _BYTE_ORDER _BIG_ENDIAN +#else +#define _BYTE_ORDER _LITTLE_ENDIAN +#endif +#include diff --git a/sys/arch/dreamcast/include/float.h b/sys/arch/dreamcast/include/float.h new file mode 100644 index 000000000000..7050a6fadae2 --- /dev/null +++ b/sys/arch/dreamcast/include/float.h @@ -0,0 +1,7 @@ +/* $NetBSD: float.h,v 1.1 2000/12/11 18:19:14 marcus Exp $ */ +#ifndef _DREAMCAST_FLOAT_H_ +#define _DREAMCAST_FLOAT_H_ + +#include + +#endif /* _DREAMCAST_FLOAT_H_ */ diff --git a/sys/arch/dreamcast/include/frame.h b/sys/arch/dreamcast/include/frame.h new file mode 100644 index 000000000000..0cb082a3e899 --- /dev/null +++ b/sys/arch/dreamcast/include/frame.h @@ -0,0 +1,7 @@ +/* $NetBSD: frame.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_FRAME_H_ +#define _DREAMCAST_FRAME_H_ + +#include + +#endif /* _DREAMCAST_FRAME_H_ */ diff --git a/sys/arch/dreamcast/include/ieee.h b/sys/arch/dreamcast/include/ieee.h new file mode 100644 index 000000000000..4a102aeb15ad --- /dev/null +++ b/sys/arch/dreamcast/include/ieee.h @@ -0,0 +1,7 @@ +/* $NetBSD: ieee.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_IEEE_H_ +#define _DREAMCAST_IEEE_H_ + +#include + +#endif /* _DREAMCAST_IEEE_H_ */ diff --git a/sys/arch/dreamcast/include/ieeefp.h b/sys/arch/dreamcast/include/ieeefp.h new file mode 100644 index 000000000000..0b08989874c1 --- /dev/null +++ b/sys/arch/dreamcast/include/ieeefp.h @@ -0,0 +1,7 @@ +/* $NetBSD: ieeefp.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_IEEEFP_H_ +#define _DREAMCAST_IEEEFP_H_ + +#include + +#endif /* _DREAMCAST_IEEEFP_H_ */ diff --git a/sys/arch/dreamcast/include/int_types.h b/sys/arch/dreamcast/include/int_types.h new file mode 100644 index 000000000000..9044574e7a74 --- /dev/null +++ b/sys/arch/dreamcast/include/int_types.h @@ -0,0 +1,3 @@ +/* $NetBSD: int_types.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ + +#include diff --git a/sys/arch/dreamcast/include/intr.h b/sys/arch/dreamcast/include/intr.h new file mode 100644 index 000000000000..f455f0db0b0a --- /dev/null +++ b/sys/arch/dreamcast/include/intr.h @@ -0,0 +1,39 @@ +/* $NetBSD: intr.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_INTR_H_ +#define _DREAMCAST_INTR_H_ + +/* Interrupt priority `levels'. */ +#define IPL_NONE 9 /* nothing */ +#define IPL_SOFTCLOCK 8 /* timeouts */ +#define IPL_SOFTNET 7 /* protocol stacks */ +#define IPL_BIO 6 /* block I/O */ +#define IPL_NET 5 /* network */ +#define IPL_SOFTSERIAL 4 /* serial */ +#define IPL_TTY 3 /* terminal */ +#define IPL_IMP 3 /* memory allocation */ +#define IPL_AUDIO 2 /* audio */ +#define IPL_CLOCK 1 /* clock */ +#define IPL_HIGH 1 /* everything */ +#define IPL_SERIAL 0 /* serial */ +#define NIPL 10 + +#include + +/* Soft interrupt masks. */ +#define SIR_CLOCK 31 +#define SIR_NET 30 +#define SIR_SERIAL 29 + +#define SIR_LOW 29 +#define SIR_HIGH 31 + +/* IRQ */ +#define TMU1_IRQ 2 +#define SCI_IRQ 6 +#define SCIF_IRQ 7 +#define WDOG_IRQ 1 + +#define IRQ_LOW 1 +#define IRQ_HIGH 15 + +#endif /* _DREAMCAST_INTR_H_ */ diff --git a/sys/arch/dreamcast/include/limits.h b/sys/arch/dreamcast/include/limits.h new file mode 100644 index 000000000000..9f383e89d15c --- /dev/null +++ b/sys/arch/dreamcast/include/limits.h @@ -0,0 +1,7 @@ +/* $NetBSD: limits.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_LIMITS_H_ +#define _DREAMCAST_LIMITS_H_ + +#include + +#endif /* _DREAMCAST_LIMITS_H_ */ diff --git a/sys/arch/dreamcast/include/lock.h b/sys/arch/dreamcast/include/lock.h new file mode 100644 index 000000000000..972ad56dc89a --- /dev/null +++ b/sys/arch/dreamcast/include/lock.h @@ -0,0 +1,4 @@ +/* $NetBSD: lock.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ + +/* Just use the common sh3 definition */ +#include diff --git a/sys/arch/dreamcast/include/math.h b/sys/arch/dreamcast/include/math.h new file mode 100644 index 000000000000..39b0b2560e5a --- /dev/null +++ b/sys/arch/dreamcast/include/math.h @@ -0,0 +1,3 @@ +/* $NetBSD: math.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ + +#include diff --git a/sys/arch/dreamcast/include/mmeye.h b/sys/arch/dreamcast/include/mmeye.h new file mode 100644 index 000000000000..771b2dbd10ee --- /dev/null +++ b/sys/arch/dreamcast/include/mmeye.h @@ -0,0 +1,23 @@ +/* + * Brains mmEye specific register definition + */ + +#ifndef _MMEYE_H_ +#define _MMEYE_H_ + +#ifdef _KERNEL +#include "opt_led_addr.h" + +#define MMEYE_LED (*(volatile unsigned char *)LED_ADDR) + +#if 0 +#if 1 +#define MMEYE_LED (*(volatile unsigned char *)0xa8000000) +#else +#define MMEYE_LED (*(volatile unsigned char *)0xb8000000) +#endif +#endif + +#endif /* _KERNEL */ + +#endif /* _MMEYE_H_ */ diff --git a/sys/arch/dreamcast/include/param.h b/sys/arch/dreamcast/include/param.h new file mode 100644 index 000000000000..32100c43294b --- /dev/null +++ b/sys/arch/dreamcast/include/param.h @@ -0,0 +1,186 @@ +/* $NetBSD: param.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)param.h 5.8 (Berkeley) 6/28/91 + */ + +/* + * Machine dependent constants for Intel 386. + */ + +#ifndef _DREAMCAST_PARAM_H_ +#define _DREAMCAST_PARAM_H_ + +#ifdef _KERNEL +#ifdef _LOCORE +#include +#else +#include +#endif +#endif + +#define _MACHINE dreamcast +#define MACHINE "dreamcast" + + +#if 1 +#define _MACHINE_ARCH sh3 +#define MACHINE_ARCH "sh3" +#define MID_MACHINE MID_SH3 +#else /* XXX (msaioth) */ +#include +#endif + +/* + * Round p (pointer or byte index) up to a correctly-aligned value + * for all data types (int, long, ...). The result is u_int and + * must be cast to any desired pointer type. + * + * ALIGNED_POINTER is a boolean macro that checks whether an address + * is valid to fetch data elements of type t from on this architecture. + * This does not reflect the optimal alignment, just the possibility + * (within reasonable limits). + * + */ +#define ALIGNBYTES (sizeof(int) - 1) +#define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES) +#define ALIGNED_POINTER(p, t) ((((u_long)(p)) & (sizeof(t)-1)) == 0) +/* #define ALIGNED_POINTER(p, t) 1 */ + +#define PGSHIFT 12 /* LOG2(NBPG) */ +#define NBPG (1 << PGSHIFT) /* bytes/page */ +#define PGOFSET (NBPG-1) /* byte offset into page */ +#define NPTEPG (NBPG/(sizeof (pt_entry_t))) + +#ifdef _KERNEL +#ifndef _LOCORE +extern vaddr_t ram_start; +#define KERNBASE ram_start /* start of kernel virtual space */ +#define KERNTEXTOFF ram_start /* start of kernel text */ +#else +#define KERNBASE IOM_RAM_BEGIN /* start of kernel virtual space */ +#define KERNTEXTOFF IOM_RAM_BEGIN /* start of kernel text */ +#endif +#endif +#define KERNSIZE 0x01800000 /* size of kernel virtual space */ +#define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT) + +#define NPGDIR (1*NBPG) +#define SYSMAP (5*NBPG) /* page table area offset from _end */ + +#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#define DEV_BSIZE (1 << DEV_BSHIFT) +#define BLKDEV_IOSIZE 2048 +#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ + +#define SSIZE 1 /* initial stack size/NBPG */ +#define SINCR 1 /* increment of stack/NBPG */ +#if 0 +#define UPAGES 2 /* pages of u-area */ +#else +#define UPAGES 4 /* pages of u-area */ +#endif +#define USPACE (UPAGES * NBPG) /* total size of u-area */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE NBPG /* default message buffer size */ +#endif + +/* + * Constants related to network buffer management. + * MCLBYTES must be no larger than CLBYTES (the software page size), and, + * on machines that exchange pages of input or output buffers with mbuf + * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple + * of the hardware page size. + */ +#define MSIZE 256 /* size of an mbuf */ + +#ifndef MCLSHIFT +# define MCLSHIFT 11 /* convert bytes to m_buf clusters */ +#endif /* MCLSHIFT */ + +#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */ +#define MCLOFSET (MCLBYTES - 1) /* offset within a m_buf cluster */ + +#ifndef NMBCLUSTERS +#ifdef GATEWAY +#define NMBCLUSTERS 512 /* map size, max cluster allocation */ +#else +#define NMBCLUSTERS 256 /* map size, max cluster allocation */ +#endif +#endif + +/* + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) + +/* pages ("clicks") to disk blocks */ +#define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) +#define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT)) + +/* bytes to pages */ +#define ctob(x) ((x) << PGSHIFT) +#define btoc(x) (((x) + PGOFSET) >> PGSHIFT) + +/* bytes to disk blocks */ +#define dbtob(x) ((x) << DEV_BSHIFT) +#define btodb(x) ((x) >> DEV_BSHIFT) + +/* + * Map a ``block device block'' to a file system block. + * This should be device dependent, and should use the bsize + * field from the disk label. + * For now though just use DEV_BSIZE. + */ +#define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE / DEV_BSIZE)) + +/* + * Mach derived conversion macros + */ +#define sh3_round_pdr(x) ((((unsigned)(x)) + PDOFSET) & ~PDOFSET) +#define sh3_trunc_pdr(x) ((unsigned)(x) & ~PDOFSET) +#define sh3_btod(x) ((unsigned)(x) >> PDSHIFT) +#define sh3_dtob(x) ((unsigned)(x) << PDSHIFT) +#define sh3_round_page(x) ((((unsigned)(x)) + PGOFSET) & ~PGOFSET) +#define sh3_trunc_page(x) ((unsigned)(x) & ~PGOFSET) +#define sh3_btop(x) ((unsigned)(x) >> PGSHIFT) +#define sh3_ptob(x) ((unsigned)(x) << PGSHIFT) + +#endif /* _DREAMCAST_PARAM_H_ */ diff --git a/sys/arch/dreamcast/include/pcb.h b/sys/arch/dreamcast/include/pcb.h new file mode 100644 index 000000000000..b90c856a8476 --- /dev/null +++ b/sys/arch/dreamcast/include/pcb.h @@ -0,0 +1,7 @@ +/* $NetBSD: pcb.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PCB_H_ +#define _DREAMCAST_PCB_H_ + +#include + +#endif /* _DREAMCAST_PCB_H_ */ diff --git a/sys/arch/dreamcast/include/pio.h b/sys/arch/dreamcast/include/pio.h new file mode 100644 index 000000000000..6261dde131fe --- /dev/null +++ b/sys/arch/dreamcast/include/pio.h @@ -0,0 +1,7 @@ +/* $NetBSD: pio.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PIO_H_ +#define _DREAMCAST_PIO_H_ + +#include + +#endif /* _DREAMCAST_PIO_H_ */ diff --git a/sys/arch/dreamcast/include/pmap.h b/sys/arch/dreamcast/include/pmap.h new file mode 100644 index 000000000000..770f83f1ef48 --- /dev/null +++ b/sys/arch/dreamcast/include/pmap.h @@ -0,0 +1,7 @@ +/* $NetBSD: pmap.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PMAP_H_ +#define _DREAMCAST_PMAP_H_ + +#include + +#endif /* _DREAMCAST_PMAP_H_ */ diff --git a/sys/arch/dreamcast/include/proc.h b/sys/arch/dreamcast/include/proc.h new file mode 100644 index 000000000000..335c4d58868c --- /dev/null +++ b/sys/arch/dreamcast/include/proc.h @@ -0,0 +1,7 @@ +/* $NetBSD: proc.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PROC_H_ +#define _DREAMCAST_PROC_H_ + +#include + +#endif /* _DREAMCAST_PROC_H_ */ diff --git a/sys/arch/dreamcast/include/profile.h b/sys/arch/dreamcast/include/profile.h new file mode 100644 index 000000000000..2f312dec636b --- /dev/null +++ b/sys/arch/dreamcast/include/profile.h @@ -0,0 +1,7 @@ +/* $NetBSD: profile.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PROFILE_H_ +#define _DREAMCAST_PROFILE_H_ + +#include + +#endif /* _DREAMCAST_PROFILE_H_ */ diff --git a/sys/arch/dreamcast/include/psl.h b/sys/arch/dreamcast/include/psl.h new file mode 100644 index 000000000000..28c3c2125a00 --- /dev/null +++ b/sys/arch/dreamcast/include/psl.h @@ -0,0 +1,7 @@ +/* $NetBSD: psl.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PSL_H_ +#define _DREAMCAST_PSL_H_ + +#include + +#endif /* _DREAMCAST_PSL_H_ */ diff --git a/sys/arch/dreamcast/include/pte.h b/sys/arch/dreamcast/include/pte.h new file mode 100644 index 000000000000..f3fcb610900c --- /dev/null +++ b/sys/arch/dreamcast/include/pte.h @@ -0,0 +1,7 @@ +/* $NetBSD: pte.h,v 1.1 2000/12/11 18:19:15 marcus Exp $ */ +#ifndef _DREAMCAST_PTE_H_ +#define _DREAMCAST_PTE_H_ + +#include + +#endif /* _DREAMCAST_PTE_H_ */ diff --git a/sys/arch/dreamcast/include/ptrace.h b/sys/arch/dreamcast/include/ptrace.h new file mode 100644 index 000000000000..3f0203c6ddd2 --- /dev/null +++ b/sys/arch/dreamcast/include/ptrace.h @@ -0,0 +1,7 @@ +/* $NetBSD: ptrace.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_PTRACE_H_ +#define _DREAMCAST_PTRACE_H_ + +#include + +#endif /* _DREAMCAST_PTRACE_H_ */ diff --git a/sys/arch/dreamcast/include/reg.h b/sys/arch/dreamcast/include/reg.h new file mode 100644 index 000000000000..00811facd462 --- /dev/null +++ b/sys/arch/dreamcast/include/reg.h @@ -0,0 +1,7 @@ +/* $NetBSD: reg.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_REG_H_ +#define _DREAMCAST_REG_H_ + +#include + +#endif /* _DREAMCAST_REG_H_ */ diff --git a/sys/arch/dreamcast/include/segments.h b/sys/arch/dreamcast/include/segments.h new file mode 100644 index 000000000000..7ead0884aaf7 --- /dev/null +++ b/sys/arch/dreamcast/include/segments.h @@ -0,0 +1,7 @@ +/* $NetBSD: segments.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_SEGMENTS_H_ +#define _DREAMCAST_SEGMENTS_H_ + +#include + +#endif /* _DREAMCAST_SEGMENTS_H_ */ diff --git a/sys/arch/dreamcast/include/setjmp.h b/sys/arch/dreamcast/include/setjmp.h new file mode 100644 index 000000000000..053242d4a749 --- /dev/null +++ b/sys/arch/dreamcast/include/setjmp.h @@ -0,0 +1,7 @@ +/* $NetBSD: setjmp.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_SETJMP_H_ +#define _DREAMCAST_SETJMP_H_ + +#include + +#endif /* _DREAMCAST_SETJMP_H_ */ diff --git a/sys/arch/dreamcast/include/shbvar.h b/sys/arch/dreamcast/include/shbvar.h new file mode 100644 index 000000000000..7af4f1fc96e2 --- /dev/null +++ b/sys/arch/dreamcast/include/shbvar.h @@ -0,0 +1,7 @@ +/* $NetBSD: shbvar.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_SHBVAR_H_ +#define _DREAMCAST_SHBVAR_H_ + +#include + +#endif /* _DREAMCAST_SHBVAR_H_ */ diff --git a/sys/arch/dreamcast/include/signal.h b/sys/arch/dreamcast/include/signal.h new file mode 100644 index 000000000000..deb18291731d --- /dev/null +++ b/sys/arch/dreamcast/include/signal.h @@ -0,0 +1,7 @@ +/* $NetBSD: signal.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_SIGNAL_H_ +#define _DREAMCAST_SIGNAL_H_ + +#include + +#endif /* _DREAMCAST_SIGNAL_H_ */ diff --git a/sys/arch/dreamcast/include/stdarg.h b/sys/arch/dreamcast/include/stdarg.h new file mode 100644 index 000000000000..b2a40488b9f6 --- /dev/null +++ b/sys/arch/dreamcast/include/stdarg.h @@ -0,0 +1,7 @@ +/* $NetBSD: stdarg.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_STDARG_H_ +#define _DREAMCAST_STDARG_H_ + +#include + +#endif /* _DREAMCAST_STDARG_H_ */ diff --git a/sys/arch/dreamcast/include/trap.h b/sys/arch/dreamcast/include/trap.h new file mode 100644 index 000000000000..0b2c2f2d8cc9 --- /dev/null +++ b/sys/arch/dreamcast/include/trap.h @@ -0,0 +1,7 @@ +/* $NetBSD: trap.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_TRAP_H_ +#define _DREAMCAST_TRAP_H_ + +#include + +#endif /* _DREAMCAST_TRAP_H_ */ diff --git a/sys/arch/dreamcast/include/types.h b/sys/arch/dreamcast/include/types.h new file mode 100644 index 000000000000..4ec9205f059a --- /dev/null +++ b/sys/arch/dreamcast/include/types.h @@ -0,0 +1,7 @@ +/* $NetBSD: types.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_TYPES_H_ +#define _DREAMCAST_TYPES_H_ + +#include + +#endif /* _DREAMCAST_TYPES_H_ */ diff --git a/sys/arch/dreamcast/include/varargs.h b/sys/arch/dreamcast/include/varargs.h new file mode 100644 index 000000000000..0e725f4a5094 --- /dev/null +++ b/sys/arch/dreamcast/include/varargs.h @@ -0,0 +1,7 @@ +/* $NetBSD: varargs.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_VARARGS_H_ +#define _DREAMCAST_VARARGS_H_ + +#include + +#endif /* _DREAMCAST_VARARGS_H_ */ diff --git a/sys/arch/dreamcast/include/vmparam.h b/sys/arch/dreamcast/include/vmparam.h new file mode 100644 index 000000000000..9b408c3f0fc5 --- /dev/null +++ b/sys/arch/dreamcast/include/vmparam.h @@ -0,0 +1,7 @@ +/* $NetBSD: vmparam.h,v 1.1 2000/12/11 18:19:16 marcus Exp $ */ +#ifndef _DREAMCAST_VMPARAM_H_ +#define _DREAMCAST_VMPARAM_H_ + +#include + +#endif /* _DREAMCAST_VMPARAM_H_ */