summaryrefslogtreecommitdiff
path: root/system/alpha/console
diff options
context:
space:
mode:
Diffstat (limited to 'system/alpha/console')
-rw-r--r--system/alpha/console/Makefile44
-rw-r--r--system/alpha/console/console.c1126
-rw-r--r--system/alpha/console/dbmentry.s213
-rw-r--r--system/alpha/console/paljtokern.s155
-rw-r--r--system/alpha/console/paljtoslave.s150
-rw-r--r--system/alpha/console/paljtoslave.tmp92
-rw-r--r--system/alpha/console/printf.c298
7 files changed, 2078 insertions, 0 deletions
diff --git a/system/alpha/console/Makefile b/system/alpha/console/Makefile
new file mode 100644
index 000000000..9b8748f13
--- /dev/null
+++ b/system/alpha/console/Makefile
@@ -0,0 +1,44 @@
+
+all: console
+
+DBMENTRY = fffffc0000010000
+INCLUDES = -I$(PALCODE) -I$(INCLUDEH) -I$(SIMTOOLS)/cpus-alpha/simos
+#-I/udir/bugnion/ebfw/h -I/udir/bugnion/ebfw/palcode/xxm
+
+SOURDIR = ./
+EB_TOOLBOX = /wrl/proj/simos/bin/tools/osf
+PALCODE = ../palcode
+INCLUDEH = ../h
+
+dbmentry.o: dbmentry.s
+ $(AS) $(INCLUDES) -o $*.o $*.s
+
+console.o: console.c
+ $(CC) -g3 $(INCLUDES) -o $*.o -c $*.c
+
+printf.o: printf.c
+ $(CC) -g3 $(INCLUDES) -o $*.o -c $*.c
+
+paljtokern.o: $(SOURCEDIR)paljtokern.s
+ rm $(OBJDIR)paljtokern.i
+ cpp -I$(PALCODE) $(SOURCEDIR)paljtokern.s $(OBJDIR)paljtokern.i
+ $(EB_TOOLBOX)/gas -21164 -o $(OBJDIR)paljtokern.aout.o $(OBJDIR)paljtokern.i
+ $(EB_TOOLBOX)/astrip -a $(OBJDIR)paljtokern.aout.o $(OBJDIR)paljtokern.strip
+ $(EB_TOOLBOX)/strip2array $(OBJDIR)paljtokern.strip $(OBJDIR)paljtokern.c
+ $(CC) $(CCFLAGS) -o $(OBJDIR)paljtokern.o -c $(INCLUDES) $(OBJDIR)paljtokern.c
+
+paljtoslave.o: $(SOURCEDIR)paljtoslave.s
+ rm $(OBJDIR)paljtoslave.i
+ cpp -I$(PALCODE) $(SOURCEDIR)paljtoslave.s $(OBJDIR)paljtoslave.i
+ $(EB_TOOLBOX)/gas -21164 -o $(OBJDIR)paljtoslave.aout.o $(OBJDIR)paljtoslave.i
+ $(EB_TOOLBOX)/astrip -a $(OBJDIR)paljtoslave.aout.o $(OBJDIR)paljtoslave.strip
+ $(EB_TOOLBOX)/strip2array $(OBJDIR)paljtoslave.strip $(OBJDIR)paljtoslave.tmp
+ sed -e 's/palJToKern/palJToSlave/' $(OBJDIR)paljtoslave.tmp >$(OBJDIR)paljtoslave.c
+ $(CC) $(CCFLAGS) -o $(OBJDIR)paljtoslave.o -c $(INCLUDES) $(OBJDIR)paljtoslave.c
+
+console: console.o dbmentry.o printf.o paljtokern.o paljtoslave.o
+ $(LD) -o console -N -T $(DBMENTRY) -non_shared dbmentry.o console.o \
+ printf.o paljtokern.o paljtoslave.o -lc
+
+clean:
+ rm *.o; rm console; rm *.strip; rm paljtokern.c paljtoslave.c; touch paljtokern.i paljtoslave.i
diff --git a/system/alpha/console/console.c b/system/alpha/console/console.c
new file mode 100644
index 000000000..c6a61a10e
--- /dev/null
+++ b/system/alpha/console/console.c
@@ -0,0 +1,1126 @@
+
+
+/* ******************************************
+ * SimOS SRM Console
+ *
+ * Derived from Lance Berc's SRM console
+ * for the SRC XXM Machine
+ * ******************************************/
+
+
+/* from simos */
+typedef unsigned long long uint64;
+#include "machine_defs.h"
+#include "new_aouthdr.h"
+#include "alpha_access.h"
+#if 0
+#include "srcmax.h"
+#endif
+
+/* from ../h */
+#include "lib.h"
+#include "rpb.h"
+#include "cserve.h"
+
+
+#define CONS_INT_TX 0x01 /* interrupt enable / state bits */
+#define CONS_INT_RX 0x02
+
+#define KSEG 0xfffffc0000000000
+#define K1BASE 0xfffffc8000000000
+#define KSEG_TO_PHYS(x)(((ul)x) & ~KSEG)
+
+#define CDR ((volatile DevConsoleRegisters *) \
+ (__MAGIC_ZONE(0, 0, MAGIC_ZONE_BDOOR_DEV) + __MAGIC_BDOOR_CNSLE_OFFS))
+
+
+#define PHYS_TO_K1(_x) (K1BASE|(_x))
+
+#define AOUT_LOAD_ADDR (KSEG|0xf000)
+
+#define ROUNDUP8(x) ((ul)(((ul)x)+7) & ~7)
+#define ROUNDUP128(x) ((ul)(((ul)x)+127) & ~127)
+#define ROUNDUP8K(x) ((ul)(((ul)(x))+8191) & ~8191)
+
+#define FIRST(x) ((((ul)(x)) >> 33) & 0x3ff)
+#define SECOND(x) ((((ul)(x)) >> 23) & 0x3ff)
+#define THIRD(x) ((((ul)(x)) >> 13) & 0x3ff)
+#define THIRD_XXX(x) ((((ul)(x)) >> 13) & 0xfff)
+#define PFN(x) ((((ul)(x) & ~KSEG) >> 13))
+
+/* Kernel write | kernel read | valid */
+#define KPTE(x) ((ul)((((ul)(x)) << 32) | 0x1101))
+
+#define HWRPB_PAGES 4
+#define MDT_BITMAP_PAGES 4
+
+#define CSERVE_K_JTOKERN 0x18
+
+#define NUM_KERNEL_THIRD (4)
+
+
+static unixBoot(int go, int argc, char **argv);
+void jToPal(ul bootadr);
+void SlaveLoop(int cpu);
+
+
+AlphaAccess simosConf;
+
+/* **************************************************************
+ * Console callbacks use VMS calling conventions
+ * read AXP manual, 2-64.
+ * ***************************************************************/
+typedef struct OpenVMSFunc {
+ long dummy;
+ long func;
+}OpenVMSFunc;
+
+OpenVMSFunc callbackFunc, fixupFunc;
+
+
+
+
+ul theLock;
+
+
+extern void SpinLock(ul *lock);
+#define SpinUnlock(_x) *(_x) = 0;
+
+struct _kernel_params {
+ char *bootadr;
+ ul rpb_percpu;
+ ul free_pfn;
+ ul argc;
+ ul argv;
+ ul envp; /* NULL */
+};
+
+
+extern consoleCallback[];
+extern consoleFixup[];
+long CallBackDispatcher();
+long CallBackFixup();
+
+/*
+ * simos console output
+ */
+
+void InitConsole(void)
+{
+#if 0
+ CDR->intr_status =(DevRegister)(DEV_CNSLE_RX_INTR |DEV_CNSLE_TX_INTR);
+#endif
+}
+
+void PutChar(char c)
+{
+#if 0
+ CDR->data = c;
+#endif
+#if 0
+ *(int*) PHYS_TO_K1(SLOT_D_COM1<<5) = c;
+#endif
+ AlphaAccess *k1Conf = (AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
+ k1Conf->outputChar = c;
+
+}
+
+
+int passArgs(int argc)
+{
+ ;
+}
+
+
+main(int argc, char **argv)
+{
+ int x,i;
+ AlphaAccess *k1Conf = (AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
+ ui *k1ptr,*ksegptr;
+
+
+ InitConsole();
+ printf("SimOS console \n");
+ /*
+ * get configuration from backdoor
+ */
+ simosConf.last_offset = k1Conf->last_offset;
+ printf(" Got simosConfiguration %d \n",simosConf.last_offset);
+
+ for (i=1;i<=simosConf.last_offset/4;i++) {
+ ui *k1ptr = (ui*)k1Conf + i;
+ ui *ksegptr = (ui*)(&simosConf.last_offset)+i;
+ *ksegptr = *k1ptr;
+
+ }
+
+ if (simosConf.version != ALPHA_ACCESS_VERSION) {
+ panic("Console version mismatch. Console expects %d. SimOS has %d \n",
+ ALPHA_ACCESS_VERSION,simosConf.version);
+ }
+
+
+ /*
+ * setup arguments to kernel
+ */
+ unixBoot(1,argc,argv);
+
+ x = *(volatile int *)(K1BASE-4);
+ while(1) continue;
+ return x;
+}
+
+/*
+ * BOOTING
+ */
+struct rpb xxm_rpb = {
+ NULL, /* 000: physical self-reference */
+ 'H'|('W'<<8)|('R'<<16)|('P'<<24)|('B'<<32), /* 008: contains string "HWRPB" */
+ 6, /* 010: HWRPB version number */
+ /* the byte count is wrong, but who needs it? - lance */
+ 0, /* 018: bytes in RPB perCPU CTB CRB MEDSC */
+ 0, /* 020: primary cpu id */
+ 8192, /* 028: page size in bytes */
+ 43, /* 030: number of phys addr bits */
+ 127, /* 038: max valid ASN */
+ {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}, /* 040: system serial num: 10 ascii chars */
+#ifdef undef
+/* To be legitimate, the following system type and variation are correct for the XXM.
+ But there are too many #ifdefs etc to deal with in Unix, so we tell the kernel
+ that we're an Avanti, which is similar enough.
+ */
+ 31, /* 050: system type - XXM is now in the Alpha SRM */
+ (1 << 10) | (2<<1),/* 058: system variation - XXM w/EV5 & embeded console */
+#endif
+#if 0
+ 0x12, /* 050: system type - masquarade as some random 21064 */
+#endif
+ 12, /* masquerade a DEC_3000_500 (bugnion) */
+ (2<<1), /* 058: system variation */
+ 'c'|('o'<<8)|('o'<<16)|('l'<< 24), /* 060: system revision */
+ 1024*4096, /* 068: scaled interval clock intr freq OVERRIDEN*/
+ 0, /* 070: cycle counter frequency */
+ 0x200000000, /* 078: virtual page table base */
+ 0, /* 080: reserved */
+ 0, /* 088: offset to translation buffer hint */
+ 1, /* 090: number of processor slots OVERRIDDEN*/
+ sizeof(struct rpb_percpu), /* 098: per-cpu slot size. OVERRIDDEN */
+ 0, /* 0A0: offset to per_cpu slots */
+ 1, /* 0A8: number of CTBs */
+#ifdef bugnion_gone
+ sizeof(struct rpb_ctb), /* 0B0: bytes in largest CTB */
+#else
+ sizeof(struct ctb_tt),
+#endif
+ 0, /* 0B8: offset to CTB (cons term block) */
+ 0, /* 0C0: offset to CRB (cons routine block) */
+ 0, /* 0C8: offset to memory descriptor table */
+ 0, /* 0D0: offset to config data block */
+ 0, /* 0D8: offset to FRU table */
+ 0, /* 0E0: virt addr of save term routine */
+ 0, /* 0E8: proc value for save term routine */
+ 0, /* 0F0: virt addr of restore term routine */
+ 0, /* 0F8: proc value for restore term routine */
+ 0, /* 100: virt addr of CPU restart routine */
+ 0, /* 108: proc value for CPU restart routine */
+ 0, /* 110: used to determine presence of kdebug */
+ 0, /* 118: reserved for hardware */
+/* the checksum is wrong, but who needs it? - lance */
+ 0, /* 120: checksum of prior entries in rpb */
+ 0, /* 128: receive ready bitmask */
+ 0, /* 130: transmit ready bitmask */
+ 0, /* 138: Dynamic System Recog. offset */
+};
+
+ul xxm_tbb[] = { 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
+ 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e};
+
+struct rpb_percpu xxm_rpb_percpu = {
+ {0,0,0,0,0,0,0,{0,0},{0,0,0,0,0,0,0,0}}, /* 000: boot/restart HWPCB */
+ (STATE_PA | STATE_PP | STATE_CV | STATE_PV | STATE_PMV | STATE_PL), /* 080: per-cpu state bits */
+ 0xc000, /* 088: palcode memory length */
+ 0x2000, /* 090: palcode scratch length */
+ 0x4000, /* 098: phys addr of palcode mem space */
+ 0x2000, /* 0A0: phys addr of palcode scratch space */
+ (2 << 16) | (5 << 8) | 1, /* 0A8: PALcode rev required */
+ 5|(2<<32), /* 0B0: processor type */
+ 7, /* 0B8: processor variation */
+ 'D'|('a'<<8)|('v'<<16)|('e'<<24), /* 0C0: processor revision */
+ {'D','a','v','e','C','o','n','r','o','y',0,0,0,0,0,0}, /* 0C8: proc serial num: 10 ascii chars */
+ 0, /* 0D8: phys addr of logout area */
+ 0, /* 0E0: length in bytes of logout area */
+ 0, /* 0E8: halt pcb base */
+ 0, /* 0F0: halt pc */
+ 0, /* 0F8: halt ps */
+ 0, /* 100: halt arg list (R25) */
+ 0, /* 108: halt return address (R26) */
+ 0, /* 110: halt procedure value (R27) */
+ 0, /* 118: reason for halt */
+ 0, /* 120: for software */
+ {0}, /* 128: inter-console communications buffer */
+ {1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* 1D0: PALcode revs available */
+ 0 /* 250: reserved for arch use */
+/* the dump stack grows from the end of the rpb page not to reach here */
+};
+
+struct _xxm_rpb_mdt {
+ long rpb_checksum; /* 000: checksum of entire mem desc table */
+ long rpb_impaddr; /* 008: PA of implementation dep info */
+ long rpb_numcl; /* 010: number of clusters */
+ struct rpb_cluster rpb_cluster[3]; /* first instance of a cluster */
+};
+
+struct _xxm_rpb_mdt xxm_rpb_mdt = {
+ 0, /* 000: checksum of entire mem desc table */
+ 0, /* 008: PA of implementation dep info */
+ 0, /* 010: number of clusters */
+ {{ 0, /* 000: starting PFN of this cluster */
+ 0, /* 008: count of PFNs in this cluster */
+ 0, /* 010: count of tested PFNs in cluster */
+ 0, /* 018: va of bitmap */
+ 0, /* 020: pa of bitmap */
+ 0, /* 028: checksum of bitmap */
+ 1 /* 030: usage of cluster */
+ },
+ { 0, /* 000: starting PFN of this cluster */
+ 0, /* 008: count of PFNs in this cluster */
+ 0, /* 010: count of tested PFNs in cluster */
+ 0, /* 018: va of bitmap */
+ 0, /* 020: pa of bitmap */
+ 0, /* 028: checksum of bitmap */
+ 0 /* 030: usage of cluster */
+ },
+ { 0, /* 000: starting PFN of this cluster */
+ 0, /* 008: count of PFNs in this cluster */
+ 0, /* 010: count of tested PFNs in cluster */
+ 0, /* 018: va of bitmap */
+ 0, /* 020: pa of bitmap */
+ 0, /* 028: checksum of bitmap */
+ 0 /* 030: usage of cluster */
+ }}
+};
+
+/* constants for slotinfo bus_type subfield */
+#define SLOTINFO_TC 0
+#define SLOTINFO_ISA 1
+#define SLOTINFO_EISA 2
+#define SLOTINFO_PCI 3
+
+struct rpb_ctb xxm_rpb_ctb = {
+ CONS_DZ, /* 000: console type */
+ 0, /* 008: console unit */
+ 0, /* 010: reserved */
+ 0 /* 018: byte length of device dep portion */
+};
+
+/* we don't do any fixup (aka relocate the console) - we hope */
+struct rpb_crb xxm_rpb_crb = {
+ 0, /* va of call-back dispatch rtn */
+ 0, /* pa of call-back dispatch rtn */
+ 0, /* va of call-back fixup rtn */
+ 0, /* pa of call-back fixup rtn */
+ 0, /* number of entries in phys/virt map */
+ 0 /* Number of pages to be mapped */
+};
+
+struct _rpb_name {
+ unsigned long length;
+ char name[16];
+};
+
+extern struct _rpb_name xxm_name;
+
+struct rpb_dsr xxm_rpb_dsr = {
+ 0,
+ 0,
+ 0,
+};
+
+struct _rpb_name xxm_name = {
+ 16,
+ {'D','E','C',' ','S','R','C',' ','X','X','M',' ','D','G','C',0},
+};
+
+/* XXM has one LURT entry - 1050 is for workstations, 1100 is servers (and is needed for CXX) */
+long xxm_lurt[10] = { 9, 12, -1, -1, -1, -1, -1, -1, 1100, 1100 };
+
+ul unix_boot_mem;
+unsigned long bootadr;
+#if 0
+unsigned long aout_bss_addr, aout_bss_size, aout_entry, aout_text_start, aout_data_addr;
+#endif
+char **kargv;
+int kargc;
+ul free_pfn;
+struct rpb_percpu *rpb_percpu;
+
+
+#define MAX_CPUS 32
+
+ul bootStrapImpure[MAX_CPUS];
+
+
+char *unix_boot_alloc(int pages)
+{
+ char *ret = (char *) unix_boot_mem;
+ unix_boot_mem += (pages * 8192);
+ return ret;
+}
+
+ul *first = 0;
+ul *third_rpb = 0;
+ul *reservedFixup = 0;
+
+struct rpb *rpb;
+
+unixBoot(int go, int argc, char **argv)
+{
+ ul *second, *third_kernel, ptr, *tbb, size, *percpu_logout;
+ unsigned char *mdt_bitmap;
+ long *lp1, *lp2, sum;
+ int i, cl;
+ int kern_first_page;
+ int mem_size = simosConf.mem_size;
+
+ int mem_pages = mem_size / 8192, cons_pages;
+ ul kernel_bytes, ksp, kernel_end, *unix_kernel_stack, bss, ksp_bottom, ksp_top;
+ struct rpb_ctb *rpb_ctb;
+ struct ctb_tt *ctb_tt;
+ struct rpb_dsr *rpb_dsr;
+ struct rpb_crb *rpb_crb;
+ struct _xxm_rpb_mdt *rpb_mdt;
+ int *rpb_lurt;
+ char *rpb_name;
+ ul nextPtr;
+
+ printf( "memsize %x pages %x \n",mem_size,mem_pages);
+
+
+
+#ifdef notnow
+ if (unixArgs()) return;
+#endif
+
+ /* Allocate:
+ * two pages for the HWRPB
+ * five page table pages:
+ * 1: First level page table
+ * 1: Second level page table
+ * 1: Third level page table for HWRPB
+ * 2: Third level page table for kernel (for up to 16MB)
+ * set up the page tables
+ * load the kernel at the physical address 0x230000
+ * build the HWRPB
+ * set up memory descriptor table to give up the
+ * physical memory between the end of the page
+ * tables and the start of the kernel
+ * enable kseg addressing
+ * jump to the kernel
+ */
+
+ unix_boot_mem = ROUNDUP8K(&_end);
+
+ printf("First free page after ROM 0x%x\n", unix_boot_mem);
+
+ rpb = (struct rpb *) unix_boot_alloc( HWRPB_PAGES);
+
+ mdt_bitmap = (unsigned char *) unix_boot_alloc(MDT_BITMAP_PAGES);
+ first = (ul *)unix_boot_alloc(1);
+ second = (ul *)unix_boot_alloc(1);
+ third_rpb = (ul *)unix_boot_alloc(1);
+ reservedFixup = (ul*) unix_boot_alloc(1);
+ third_kernel = (ul *)unix_boot_alloc(NUM_KERNEL_THIRD);
+ percpu_logout = (ul*)unix_boot_alloc(1);
+
+
+ cons_pages = KSEG_TO_PHYS(unix_boot_mem) / 8192;
+
+ /* Set up the page tables */
+ bzero((char *)first, 8192);
+ bzero((char *)second, 8192);
+ bzero((char *)reservedFixup,8192);
+ bzero((char *)third_rpb, HWRPB_PAGES * 8192);
+ bzero((char *)third_kernel, 8192 * NUM_KERNEL_THIRD);
+
+ first[0] = KPTE(PFN(second));
+ first[1] = KPTE(PFN(first)); /* Region 3 */
+
+ second[SECOND(0x10000000)] = KPTE(PFN(third_rpb)); /* Region 0 */
+ for (i=0;i<NUM_KERNEL_THIRD;i++) {
+ second[SECOND(0x20000000)+i] = KPTE(PFN(third_kernel)+i); /* Region 1 */
+ }
+ second[SECOND(0x40000000)] = KPTE(PFN(second)); /* Region 2 */
+
+
+ {
+
+ /* For some obscure reason, Dec Unix's database read
+ * from /etc/sysconfigtab is written to this fixed
+ * mapped memory location. Go figure, since it is
+ * not initialized by the console. Maybe it is
+ * to look at the database from the console
+ * after a boot/crash.
+ *
+ * Black magic to estimate the max size. SEGVs on overflow
+ * bugnion
+ */
+
+#define DATABASE_BASE 0x20000000
+#ifdef not_not
+#define DATABASE_END 0x20230000 /* don't need all that */
+#endif
+
+#define DATABASE_END 0x20020000
+
+ int i;
+ ul *dbPage = (ul*)unix_boot_alloc(1);
+ second[SECOND(DATABASE_BASE)] = KPTE(PFN(dbPage));
+ for (i=DATABASE_BASE; i <DATABASE_END ; i+= 8096) {
+ ul *db = (ul*)unix_boot_alloc(1);
+ dbPage[THIRD(i)] = KPTE(PFN(db));
+ }
+ }
+
+ /* Region 0 */
+ /* Map the HWRPB */
+ for (i = 0; i < HWRPB_PAGES; i++) third_rpb[i] = KPTE(PFN(rpb) + i);
+
+ /* Map the MDT bitmap table */
+ for (i=0;i<MDT_BITMAP_PAGES;i++) {
+ third_rpb[HWRPB_PAGES+i] = KPTE(PFN(mdt_bitmap)+i);
+ }
+
+ /* Protect the PAL pages */
+ for (i = 1; i < PFN(first); i++) third_rpb[HWRPB_PAGES + MDT_BITMAP_PAGES + i] = KPTE(i);
+
+ /* Set up third_kernel after it's loaded, when we know where it is */
+
+#ifdef original__xxm
+ if (unixLoadKernel(AOUT_LOAD_ADDR, argv[1]) == -1) return;
+ aoutfixup(AOUT_LOAD_ADDR);
+#else
+ /* aoutfixup(simosConf.kernelFileHdr); */
+#endif
+#if 0
+ bss = aout_bss_addr;
+
+ kern_first_page = (KSEG_TO_PHYS(aout_text_start) / 8192);
+ kernel_end = ksp_top = ROUNDUP8K(aout_bss_addr + aout_bss_size);
+ bootadr = aout_entry;
+#endif
+
+ kern_first_page = (KSEG_TO_PHYS(simosConf.kernStart)/8192);
+ kernel_end = ksp_top = ROUNDUP8K(simosConf.kernEnd);
+ bootadr = simosConf.entryPoint;
+
+
+ printf("HWRPB 0x%x l1pt 0x%x l2pt 0x%x l3pt_rpb 0x%x l3pt_kernel 0x%x l2reserv 0x%x\n",
+ rpb, first, second, third_rpb, third_kernel,reservedFixup);
+ if (kernel_end - simosConf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
+ printf("Kernel is more than 8MB 0x%x - 0x%x = 0x%x\n",
+ kernel_end, simosConf.kernStart,
+ kernel_end -simosConf.kernStart );
+ panic("kernel too big\n");
+
+ }
+ /* Map the kernel's pages into the third level of region 2 */
+
+ for (ptr = simosConf.kernStart; ptr < kernel_end; ptr += 8192) {
+
+ third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr));
+ }
+ /* blow 2 pages of phys mem for guards since it maintains 1-to-1 mapping */
+ ksp = ksp_top + (3 * 8192);
+ if (ksp - simosConf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
+ printf("Kernel stack pushd us over 8MB\n");
+ panic("ksp too big\n");
+ }
+ if (THIRD_XXX((ul)ksp_top) > NUM_KERNEL_THIRD * 1024) {
+ panic("increase NUM_KERNEL_THIRD, and change THIRD_XXX\n");
+ }
+ ptr = (ul) ksp_top;
+ bzero((char *)ptr, 8192 * 2);
+ third_kernel[THIRD_XXX(ptr)] = 0; /* Stack Guard Page */
+ ptr += 8192;
+ third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr)); /* Kernel Stack Pages */
+ ptr += 8192;
+ third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr));
+ ptr += 8192;
+ third_kernel[THIRD_XXX(ptr)] = 0; /* Stack Guard Page */
+
+ /* put argv into the bottom of the stack - argv starts at 1 because
+ * the command thatr got us here (i.e. "unixboot) is in argv[0].
+ */
+ ksp -= 8; /* Back up one longword */
+ ksp -= argc * sizeof(char *); /* Make room for argv */
+ kargv = (char **) ksp;
+ for (i = 1; i < argc; i++) { /* Copy arguments to stack */
+ ksp -= ((strlen(argv[i]) + 1) + 7) & ~0x7;
+ kargv[i-1] = (char *) ksp;
+ strcpy(kargv[i-1], argv[i]);
+ }
+ kargc = i - 1;
+ kargv[kargc] = NULL; /* just to be sure; doesn't seem to be used */
+ ksp -= sizeof(char *); /* point above last arg for no real reason */
+
+ free_pfn = PFN(ptr);
+
+ bcopy((char *)&xxm_rpb, (char *)rpb, sizeof(struct rpb));
+
+ rpb->rpb_selfref = (struct rpb *) KSEG_TO_PHYS(rpb);
+ rpb->rpb_string = 0x0000004250525748;
+
+ tbb = (ul *) (((char *) rpb) + ROUNDUP8(sizeof(struct rpb)));
+ rpb->rpb_trans_off = (ul)tbb - (ul)rpb;
+ bcopy((char *)xxm_tbb, (char *)tbb, sizeof(xxm_tbb));
+
+
+ /*
+ * rpb_counter. Use to determine timeouts in OS.
+ * XXX must be patched after a checkpoint restore (I guess)
+ */
+
+ printf("CPU Clock at %d MHz IntrClockFrequency=%d \n", simosConf.cpuClock,simosConf.intrClockFrequency);
+ rpb->rpb_counter = simosConf.cpuClock * 1000 * 1000;
+
+ /*
+ * By definition, the rpb_clock is scaled by 4096 (in hz)
+ */
+ rpb->rpb_clock = simosConf.intrClockFrequency * 4096;
+
+
+
+ /*
+ * Per CPU Slots. Multiprocessor support.
+ */
+ {
+ int i;
+ int size = ROUNDUP128(sizeof(struct rpb_percpu));
+
+ printf("Booting with %d processor(s) \n",simosConf.numCPUs);
+
+ rpb->rpb_numprocs = simosConf.numCPUs;
+ rpb->rpb_slotsize = size;
+ rpb_percpu = (struct rpb_percpu *)
+ ROUNDUP128(((ul) tbb) +(sizeof(xxm_tbb)));
+
+ rpb->rpb_percpu_off = (ul)rpb_percpu - (ul)rpb;
+
+ for (i=0;i<simosConf.numCPUs;i++) {
+ struct rpb_percpu *thisCPU = (struct rpb_percpu*)
+ ((ul)rpb_percpu + size*i);
+
+ bzero((char *)thisCPU, size);
+ bcopy((char *)&xxm_rpb_percpu,
+ (char *)thisCPU,
+ sizeof(struct rpb_percpu));
+
+ thisCPU->rpb_pcb.rpb_ksp = ksp;
+ thisCPU->rpb_pcb.rpb_ptbr = PFN(first);
+
+ thisCPU->rpb_logout = KSEG_TO_PHYS(percpu_logout);
+ thisCPU->rpb_logout_len = 8192;
+
+/* thisCPU->rpb_pcb.rpb_ptbr = PFN(second);*/
+
+ printf("KSP: 0x%x PTBR 0x%x\n", thisCPU->rpb_pcb.rpb_ksp, thisCPU->rpb_pcb.rpb_ptbr);
+
+ if (i) {
+ bootStrapImpure[i] = (ul)unix_boot_alloc(1);
+ }
+
+ }
+
+ nextPtr = (ul)rpb_percpu + size*simosConf.numCPUs;
+ }
+
+ /*
+ * Console Terminal Block
+ */
+
+
+ rpb_ctb = (struct rpb_ctb *) nextPtr;
+ ctb_tt = (struct ctb_tt*) rpb_ctb;
+
+ rpb->rpb_ctb_off = ((ul)rpb_ctb) - (ul)rpb;
+ rpb->rpb_ctb_size = sizeof(struct rpb_ctb);
+
+ bzero((char *)rpb_ctb, sizeof(struct ctb_tt));
+
+#ifdef original_xxm
+ if (tga_slot == -1)
+ rpb_ctb->rpb_type = CONS_DZ;
+ else {
+ rpb_ctb->rpb_type = CONS_GRPH;
+ rpb_ctb->rpb_unit = (SLOTINFO_PCI << 16) | (0 << 8) | tga_slot;
+ }
+#else
+ rpb_ctb->rpb_type = CONS_DZ;
+#endif
+
+ rpb_ctb->rpb_length = sizeof(ctb_tt)-sizeof(rpb_ctb);
+
+ /*
+ * uart initizliation
+ */
+ ctb_tt->ctb_csr = 0;
+ ctb_tt->ctb_tivec = 0x6c0; /* matches tlaser pal code */
+ ctb_tt->ctb_rivec = 0x680; /* matches tlaser pal code */
+ ctb_tt->ctb_baud = 9600;
+ ctb_tt->ctb_put_sts = 0;
+ ctb_tt->ctb_get_sts = 0;
+
+
+ rpb_crb = (struct rpb_crb *) (((ul)rpb_ctb) + sizeof(struct ctb_tt));
+ rpb->rpb_crb_off = ((ul)rpb_crb) - (ul)rpb;
+
+ bzero((char *)rpb_crb, sizeof(struct rpb_crb));
+ /*
+ * console callback stuff (simos)
+ */
+
+ rpb_crb->rpb_num = 1;
+ rpb_crb->rpb_mapped_pages = HWRPB_PAGES;
+ rpb_crb->rpb_map[0].rpb_virt = 0x10000000;
+ rpb_crb->rpb_map[0].rpb_phys = ((ul)rpb) & ~0x1fff;
+ rpb_crb->rpb_map[0].rpb_pgcount = HWRPB_PAGES;
+
+
+ printf("Console Callback at 0x%x, fixup at 0x%x \n",
+ rpb_crb->rpb_va_disp,
+ rpb_crb->rpb_va_fixup );
+
+ rpb_mdt = (struct _xxm_rpb_mdt *) (((ul)rpb_crb) + sizeof(struct rpb_crb));
+ rpb->rpb_mdt_off = (ul)rpb_mdt - (ul)rpb;
+ bcopy((char *)&xxm_rpb_mdt, (char *)rpb_mdt, sizeof(struct _xxm_rpb_mdt));
+
+
+ cl = 0;
+#ifdef undef
+ /* Until Digital Unix can handle it, account all pages below the kernel
+ * as "console" memory. */
+ rpb_mdt->rpb_cluster[cl].rpb_pfncount = cons_pages;
+#endif
+ rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page;
+ cl++;
+
+ rpb_mdt->rpb_cluster[cl].rpb_pfn = kern_first_page;
+ rpb_mdt->rpb_cluster[cl].rpb_pfncount = mem_pages - kern_first_page;
+ rpb_mdt->rpb_cluster[cl].rpb_pfntested=rpb_mdt->rpb_cluster[cl].rpb_pfncount;
+ rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
+ rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * 8192;
+ cl++;
+
+#ifdef undef
+ /* The stupid Unix kernel needs to have all mdt clusters in ascending
+ * order, and the last cluster is used to compute the top of memory.
+ * It can't make use of memory between the console and the kernel.
+ */
+ rpb_mdt->rpb_cluster[cl].rpb_pfn = cons_pages;
+ rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page - cons_pages;
+ rpb_mdt->rpb_cluster[cl].rpb_pfntested=rpb_mdt->rpb_cluster[cl].rpb_pfncount;
+ rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
+ rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * 8192;
+ cl++;
+#endif
+
+ rpb_mdt->rpb_numcl = cl;
+
+ for (i = 0; i < cl; i++)
+ printf("Memory cluster %d [%d - %d]\n", i, rpb_mdt->rpb_cluster[i].rpb_pfn, rpb_mdt->rpb_cluster[i].rpb_pfncount);
+
+
+
+ /* Checksum the rpb for good luck */
+ sum = 0;
+ lp1 = (long *)&rpb_mdt->rpb_impaddr;
+ lp2 = (long *)&rpb_mdt->rpb_cluster[cl];
+ while (lp1 < lp2) sum += *lp1++;
+ rpb_mdt->rpb_checksum = sum;
+
+ /* XXX should checksum the cluster descriptors */
+
+ bzero((char *)mdt_bitmap, MDT_BITMAP_PAGES * 8192);
+ for (i = 0; i < mem_pages/8; i++) ((unsigned char *)mdt_bitmap)[i] = 0xff;
+
+ printf("Initalizing mdt_bitmap addr 0x%x mem_pages %x \n",
+ (long)mdt_bitmap,(long)mem_pages);
+
+ xxm_rpb.rpb_config_off = 0;
+ xxm_rpb.rpb_fru_off = 0;
+
+ rpb_dsr = (struct rpb_dsr *) (((ul)rpb_mdt) + sizeof(struct _xxm_rpb_mdt));
+ rpb->rpb_dsr_off = ((ul)rpb_dsr) - (ul)rpb;
+ bzero((char *)rpb_dsr, sizeof(struct rpb_dsr));
+ rpb_dsr->rpb_smm = 1578; /* Official XXM SMM number as per SRM */
+ rpb_dsr->rpb_smm = 1089; /* Official Alcor SMM number as per SRM */
+
+ rpb_lurt = (int *) ROUNDUP8(((ul)rpb_dsr) + sizeof(struct rpb_dsr));
+ rpb_dsr->rpb_lurt_off = ((ul) rpb_lurt) - (ul) rpb_dsr;
+ bcopy((char *)xxm_lurt, (char *)rpb_lurt, sizeof(xxm_lurt));
+
+ rpb_name = (char *) ROUNDUP8(((ul)rpb_lurt) + sizeof(xxm_lurt));
+ rpb_dsr->rpb_sysname_off = ((ul) rpb_name) - (ul) rpb_dsr;
+#define THENAME " SimOS ALPHA/EV5"
+ sum = sizeof(THENAME);
+ bcopy(THENAME, rpb_name, sum);
+ *(ul *)rpb_name = sizeof(THENAME); /* put in length field */
+
+ /* calculate size of rpb */
+ rpb->rpb_size = ((ul) &rpb_name[sum]) - (ul)rpb;
+
+ if (rpb->rpb_size > 8192*HWRPB_PAGES) {
+ panic("HWRPB_PAGES=%d too small for HWRPB !!! \n");
+ }
+
+
+ {
+ ul *ptr = (ul*)((char*)rpb_dsr + sizeof(struct rpb_dsr ));
+ rpb_crb->rpb_pa_disp = KSEG_TO_PHYS(ptr);
+ rpb_crb->rpb_va_disp = 0x10000000 + ((ul)ptr&(0x2000*HWRPB_PAGES-1));
+ printf("ConsoleDispatch at virt %x phys %x val %x\n",
+ rpb_crb->rpb_va_disp,
+ rpb_crb->rpb_pa_disp,
+ consoleCallback);
+ *ptr++ = 0;
+ *ptr++ = (ul) consoleCallback;
+ rpb_crb->rpb_pa_fixup = KSEG_TO_PHYS(ptr);
+ rpb_crb->rpb_va_fixup = 0x10000000 + ((ul)ptr& (0x2000*HWRPB_PAGES-1));
+ *ptr++ = 0;
+ *ptr++ = (ul) consoleFixup;
+ }
+
+
+ /* Checksum the rpb for good luck */
+ sum = 0;
+ lp1 = (long *)rpb;
+ lp2 = &rpb->rpb_checksum;
+ while (lp1 < lp2)
+ sum += *lp1++;
+ *lp2 = sum;
+
+
+ /*
+ * MP bootstrap
+ */
+
+ {
+ int i;
+ for (i=1;i<simosConf.numCPUs;i++) {
+ volatile AlphaAccess *k1Conf = (volatile AlphaAccess *)
+ (__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
+ SpinLock(&theLock);
+ printf("Bootstraping CPU %d with sp=0x%x \n",
+ i,bootStrapImpure[i]);
+ SpinUnlock(&theLock);
+ k1Conf->bootStrapImpure = bootStrapImpure[i];
+ k1Conf->bootStrapCPU = i;
+ }
+ }
+
+ /*
+ * Make sure that we are not stepping on the kernel
+ */
+ if ((ul)unix_boot_mem >= (ul)simosConf.kernStart) {
+ panic("CONSOLE: too much memory. Smashing kernel \n");
+ } else {
+ SpinLock(&theLock);
+ printf("unix_boot_mem ends at %x \n",unix_boot_mem);
+ SpinUnlock(&theLock);
+ }
+
+
+#ifdef undef
+#define CSERVE_K_JTOKERN 0x18
+ cServe(bootadr, (ul) rpb_percpu, CSERVE_K_JTOKERN, free_pfn);
+#endif
+
+ if (go) JToKern(bootadr, rpb_percpu, free_pfn, kargc, kargv, NULL);
+}
+
+
+#if 0
+aoutfixup(char *p)
+{
+ int i;
+ unsigned long rem, len, off, dst;
+
+
+ struct new_aouthdr *ao = (struct new_aouthdr *) &p[NEW_FILHSZ];
+#if 0
+ struct scnhdr *s = (struct scnhdr *) &p[FILHSZ + AOUTHSZ];
+ struct scnhdr *t, *d, *b;
+ printf("aoutfixup: %d sections \n",fh->f_nscns);
+#endif
+
+
+ aout_text_start = ((ul)ao->text_start_hi<<32) + ao->text_start;
+ aout_data_addr = ((ul)ao->data_start_hi<<32) + ao->data_start;
+ aout_bss_addr = ((ul)ao->bss_start_hi<<32) + ao->bss_start;
+ aout_bss_size = ((ul)ao->bsize_hi<<32) + ao->bsize;
+ aout_entry = ((ul)ao->entry_hi<<32) + ao->entry;
+
+ printf("_text 0x%16x %8d @ %08d\n", aout_text_start, ao->tsize,0 /* t->s_scnptr*/);
+ printf("_data 0x%16x %8d @ %08d\n", aout_data_addr, ao->dsize,0/* d->s_scnptr*/);
+ printf("_bss 0x%16x %8d\n", aout_bss_addr, ao->bsize);
+ printf("entry 0x%16x\n", aout_entry);
+#if 0
+ for (i = 0; i < fh->f_nscns; i++) {
+ printf("section %d %s \n",i,s[i].s_name);
+ if (!strcmp(s[i].s_name, ".text")) t = &s[i];
+ else if (!strcmp(s[i].s_name, ".data")) d = &s[i];
+ else if (!strcmp(s[i].s_name, ".bss")) b = &s[i];
+ }
+ bcopy(&p[t->s_scnptr], (char *)ao->text_start, ao->tsize);
+ bcopy(&p[d->s_scnptr], (char *)ao->data_start, ao->dsize);
+#endif
+}
+#endif
+
+extern ui palJToKern[];
+
+JToKern(bootadr, rpb_percpu, free_pfn, k_argc, k_argv, envp)
+char * bootadr;
+ul rpb_percpu;
+ul free_pfn;
+ul k_argc;
+char **k_argv;
+char **envp;
+{
+ struct _kernel_params *kernel_params = (struct _kernel_params *) KSEG;
+ int i;
+
+ printf("k_argc = %d ", k_argc);
+ for (i = 0; i < k_argc; i++) {
+ printf("'%s' ", k_argv[i]);
+ }
+ printf("\n");
+
+/* rpb_percpu |= 0xfffffc0000000000;*/
+ kernel_params->bootadr = bootadr;
+ kernel_params->rpb_percpu = KSEG_TO_PHYS(rpb_percpu);
+ kernel_params->free_pfn = free_pfn;
+ kernel_params->argc = k_argc;
+ kernel_params->argv = (ul)k_argv;
+ kernel_params->envp = (ul)envp;
+ printf("jumping to kernel at 0x%x, (PCBB 0x%x pfn %d)\n", bootadr, rpb_percpu, free_pfn);
+ jToPal(KSEG_TO_PHYS((ul)palJToKern));
+ printf("returned from jToPal. Looping\n");
+ while(1) continue;
+}
+
+
+void jToPal(ul bootadr)
+{
+ cServe(bootadr, 0, CSERVE_K_JTOPAL);
+
+/*
+ * Make sure that floating point is enabled incase
+ * it was disabled by the user program.
+ */
+ wrfen(1);
+}
+
+
+int strcpy(char *dst, char *src)
+{
+ int i=0;
+ while(*src) {
+ *dst++ = *src++;
+ i++;
+ }
+ return i;
+}
+
+
+
+
+/* *****************************************
+ * Console I/O
+ * ******************************************/
+
+int numOpenDevices = 11;
+struct {
+ char name[128];
+} deviceState[32];
+
+#define BOOTDEVICE_NAME "SCSI 1 0 0 1 100"
+
+void DeviceOperation(long op,long channel, long count, long address, long block)
+{
+ AlphaAccess *k1Conf = (AlphaAccess *)
+ (__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
+
+ long pAddr;
+
+#if 0
+ printf("Console::DeviceRead count=0x%x address=0x%x block=0x%x\n",
+ count,address,block);
+#endif
+
+ if (strcmp(deviceState[channel].name, BOOTDEVICE_NAME )) {
+ panic("DeviceRead: only implemented for root disk \n");
+ }
+ pAddr = KSEG_TO_PHYS(address);
+ if (pAddr + count > simosConf.mem_size) {
+ panic("DeviceRead: request out of range \n");
+ }
+
+ k1Conf->diskCount = count;
+ k1Conf->diskPAddr = pAddr;
+ k1Conf->diskBlock = block;
+ k1Conf->diskOperation = op; /* launch */
+}
+
+
+
+/* *************************************************************************
+ * SimoS Console callbacks
+ * **************************************************/
+
+/* AXP manual 2-31 */
+#define CONSCB_GETC 0x1
+#define CONSCB_PUTS 0x2
+#define CONSCB_RESET_TERM 0x3
+#define CONSCB_SET_TERM_INT 0x4
+#define CONSCB_SET_TERM_CTL 0x5
+#define CONSCB_PROCESS_KEY 0x6
+
+#define CONSCB_OPEN 0x10
+#define CONSCB_CLOSE 0x11
+#define CONSCB_READ 0x13
+
+#define CONSCB_GETENV 0x22
+
+/* AXP manual 2-26 */
+
+#define ENV_BOOTED_DEV 0x4
+#define ENV_BOOTED_OSFLAGS 0x8
+
+long CallBackDispatcher(long a0, long a1, long a2, long a3, long a4)
+{
+ int i;
+ switch (a0) {
+ case CONSCB_PUTS:
+ for(i=0;i<a3;i++) {
+ PutChar(*(char *)a2+i);
+ }
+ return a3;
+ case CONSCB_GETENV:
+ switch (a1) {
+ case ENV_BOOTED_DEV:
+ i = strcpy((char*)a2,BOOTDEVICE_NAME);
+ break;
+ case ENV_BOOTED_OSFLAGS:
+ /*
+ * 'c':ignores the sysconfigtab
+ *
+ * i= strcpy((char*)a2,"c");
+ */
+ i = strcpy((char*)a2,"");
+ break;
+ default:
+ i = strcpy((char*)a2,"");
+ printf ("GETENV unsupported option %d\n", a1);
+ break;
+ }
+ if (i > a3) {
+ panic("CONSCB_GETENV overwrote buffer \n");
+ }
+ return i;
+ case CONSCB_OPEN:
+ bcopy((char*)a1,deviceState[numOpenDevices].name,a2);
+ deviceState[numOpenDevices].name[a2] = '\0';
+ printf("CONSOLE OPEN : %s --> success \n",
+ deviceState[numOpenDevices].name);
+ return numOpenDevices++;
+
+ case CONSCB_READ:
+ DeviceOperation(a0,a1,a2,a3,a4);
+ break;
+ case CONSCB_CLOSE:
+ break;
+ default:
+ panic("cher (%x,%x,%x,%x) \n",
+ a0,a1,a2,a3);
+ }
+ return 0;
+}
+
+long CallBackFixup(int a0, int a1, int a2)
+{
+ printf("CallbackFixup %x %x \n",a0,a1);
+
+#if 0
+ if (first[FIRST(a1)]==0) {
+ first[FIRST(a1)] = KPTE(PFN(reservedFixup));
+ } else {
+ panic("CallBakcfixup\n");
+ }
+ second[SECOND(a1)] = KPTE(PFN(third_rpb)); /* Region 0 */
+ printf("Fixup: FISRT(a1)=0x%x SECOND(a1)=0x%x THIRD(a1)=0x%x\n",
+ FIRST(a1),SECOND(a1),THIRD(a1));
+
+#endif
+ return 0;
+}
+
+
+
+
+
+void SlaveCmd(int cpu, struct rpb_percpu *my_rpb)
+{
+/* extern void palJToSlave[]; */
+ extern unsigned int palJToSlave[];
+
+
+ my_rpb->rpb_state |= STATE_BIP;
+ my_rpb->rpb_state &= ~STATE_RC;
+
+ SpinLock(&theLock);
+ printf("SlaveCmd: restart %x %x vptb %x my_rpb %x my_rpb_phys %x\n",
+ rpb->rpb_restart,
+ rpb->rpb_restart_pv,
+ rpb->rpb_vptb, my_rpb,
+ KSEG_TO_PHYS(my_rpb));
+ SpinUnlock(&theLock);
+
+ cServe(KSEG_TO_PHYS((ul)palJToSlave),
+ (ul)rpb->rpb_restart,
+ CSERVE_K_JTOPAL,
+ rpb->rpb_restart_pv,
+ rpb->rpb_vptb,
+ KSEG_TO_PHYS(my_rpb));
+}
+
+void SlaveLoop( int cpu)
+{
+ int size = ROUNDUP128(sizeof(struct rpb_percpu));
+ struct rpb_percpu *my_rpb = (struct rpb_percpu*)
+ ((ul)rpb_percpu + size*cpu);
+
+
+ SpinLock(&theLock);
+ if (cpu==0) {
+ panic("CPU 0 entering slaveLoop. Reenetering the console. HOSED \n");
+ } else {
+ printf("Entering slaveloop for cpu %d my_rpb=%x \n",cpu,my_rpb);
+ }
+ SpinUnlock(&theLock);
+ while(1) {
+ int i;
+ for (i=0; i < 1000000 ; i++) {
+ if (my_rpb->rpb_iccb.iccb_rxlen) {
+ SpinLock(&theLock);
+ printf("Slave CPU %d console command %s",
+ cpu,my_rpb->rpb_iccb.iccb_rxbuf);
+ SpinUnlock(&theLock);
+ SlaveCmd(cpu,my_rpb);
+ panic("SlaveCmd returned \n");
+ }
+ }
+ printf("*");
+ }
+}
+
diff --git a/system/alpha/console/dbmentry.s b/system/alpha/console/dbmentry.s
new file mode 100644
index 000000000..2ecb9ebd4
--- /dev/null
+++ b/system/alpha/console/dbmentry.s
@@ -0,0 +1,213 @@
+
+/* taken from ebfw/rom/dbmentry.s */
+
+#define EB164
+#ifndef LINT
+.data
+.asciiz "$Id: dbmentry.s,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $"
+.text
+#endif
+
+/*
+ * Debug Monitor Entry code
+ */
+
+#ifndef MAKEDEPEND
+#include "ev5_impure.h"
+#include "cserve.h"
+#include "osf.h"
+#endif
+
+#include "paldefs.h"
+#include "regdefs.h"
+#include "system.h"
+#include "ledcodes.h"
+
+ .text
+
+/* return address and padding to octaword align */
+#define STARTFRM 16
+
+ .globl __start
+ .ent __start, 0
+__start:
+_entry:
+ br t0, 2f # get the current PC
+2: ldgp gp, 0(t0) # init gp
+
+
+#ifdef original_xxm
+ lda a2, CSERVE_K_RD_IMPURE
+ call_pal PAL_CSERVE_ENTRY
+ lda v0, CNS_Q_BASE(v0)
+
+ # Add KSEG offset to the impure area
+ subq zero, 1, t0
+ sll t0, 42, t0
+ addq t0, v0, v0
+
+ lda t0, CNS_Q_SIGNATURE(v0)
+ bic t0, 0x07, t0 # Clear bottom 3 bits to avoid
+ # allignment errors if the
+ # impure area is total rubbish
+ ldq t0, 0x00(t0)
+ srl t0, 16, t0 # Shift signature into bottom 16 bits.
+ lda t6, 0xDECB(zero) # Load the expected valid signature.
+ zap t6, 0xFC, t6 # Clear the upper bits.
+ cmpeq t0, t6, t0 # Is this a valid signature?
+ beq t0, 1f # Not valid, don't trust input params.
+
+/*
+ * Init the stack at the first 8K boundary
+ * below the top of memory.
+ */
+ lda t0, CNS_Q_MEM_SIZE(v0)
+ ldq t0, 0x00(t0) # Load memory size.
+ subq t0, 1, t0 # Last address in memory
+ srl t0, 13, t0 # Align to first 8KB boundary
+ sll t0, 13, sp # below the top of memory.
+ br zero, 2f
+
+/*
+ * If memory size was not passed in via the
+ * PALcode impure data use the system specific
+ * MINIMUM_SYSTEM_MEMORY definition.
+ */
+1:
+ lda sp, (MINIMUM_SYSTEM_MEMORY&0xffff)(zero)
+ ldah sp, ((MINIMUM_SYSTEM_MEMORY+0x8000)>>16)(sp)
+ lda t0, (8*1024)(zero) # Allow for 8KB guard page.
+ subq sp, t0, sp
+
+2:
+
+#endif /* original_xxm */
+
+
+ /*
+ * SimOS. Stack pointer is start of a valid phys or KSEG page
+ */
+
+ bis sp,sp,s0 /* save sp */
+
+slave: lda v0,(8*1024)(sp) /* end of page */
+
+ subq zero, 1, t0
+ sll t0, 42, t0
+ bis t0, v0, sp
+
+#ifdef original_xxm
+ # Add KSEG offset to the stack pointer
+ subq zero, 1, t0
+ sll t0, 42, t0
+ addq t0, sp, sp
+#endif
+
+ lda sp, -STARTFRM(sp) # Create a stack frame
+ stq ra, 0(sp) # Place return address on the stack
+
+ .mask 0x84000000, -8
+ .frame sp, STARTFRM, ra
+
+/*
+ * Enable the Floating Point Unit
+ */
+ lda a0, 1(zero)
+ call_pal PAL_WRFEN_ENTRY
+
+/*
+ * Every good C program has a main()
+ */
+
+ beq s0,master
+
+ call_pal PAL_WHAMI_ENTRY
+ bis v0,v0,a0
+ jsr ra, SlaveLoop
+master:
+ jsr ra, main
+
+
+
+/*
+ * The Debug Monitor should never return.
+ * However, just incase...
+ */
+ ldgp gp, 0(ra)
+ bsr zero, _exit
+
+.end __start
+
+
+
+ .globl _exit
+ .ent _exit, 0
+_exit:
+
+ ldq ra, 0(sp) # restore return address
+ lda sp, STARTFRM(sp) # prune back the stack
+ ret zero, (ra) # Back from whence we came
+.end _exit
+
+ .globl cServe
+ .ent cServe 2
+cServe:
+ .option O1
+ .frame sp, 0, ra
+ call_pal PAL_CSERVE_ENTRY
+ ret zero, (ra)
+ .end cServe
+
+ .globl wrfen
+ .ent wrfen 2
+wrfen:
+ .option O1
+ .frame sp, 0, ra
+ call_pal PAL_WRFEN_ENTRY
+ ret zero, (ra)
+ .end wrfen
+ .globl consoleCallback
+ .ent consoleCallback 2
+consoleCallback:
+ br t0, 2f # get the current PC
+2: ldgp gp, 0(t0) # init gp
+ lda sp,-64(sp)
+ stq ra,0(sp)
+ jsr CallBackDispatcher
+ ldq ra,0(sp)
+ lda sp,64(sp)
+ ret zero,(ra)
+ .end consoleCallback
+
+
+ .globl consoleFixup
+ .ent consoleFixup 2
+consoleFixup:
+ br t0, 2f # get the current PC
+2: ldgp gp, 0(t0) # init gp
+ lda sp,-64(sp)
+ stq ra,0(sp)
+ jsr CallBackFixup
+ ldq ra,0(sp)
+ lda sp,64(sp)
+ ret zero,(ra)
+ .end consoleFixup
+
+
+
+ .globl SpinLock
+ .ent SpinLock 2
+SpinLock:
+1:
+ ldq_l a1,0(a0) # interlock complete lock state
+ subl ra,3,v0 # get calling addr[31:0] + 1
+ blbs a1,2f # branch if lock is busy
+ stq_c v0,0(a0) # attempt to acquire lock
+ beq v0,2f # branch if lost atomicity
+ mb # ensure memory coherence
+ ret zero,(ra) # return to caller (v0 is 1)
+2:
+ br zero,1b
+ .end SpinLock
+
+ \ No newline at end of file
diff --git a/system/alpha/console/paljtokern.s b/system/alpha/console/paljtokern.s
new file mode 100644
index 000000000..30497ef01
--- /dev/null
+++ b/system/alpha/console/paljtokern.s
@@ -0,0 +1,155 @@
+#include "dc21164.h" // DECchip 21164 specific definitions
+#include "osf.h" // OSF/1 specific definitions
+#include "macros.h" // Global macro definitions
+#include "ev5_impure.h" // Scratch & logout area data structures
+#include "platform.h" // Platform specific definitions
+
+ .global palJToKern
+ .text 3
+palJToKern:
+/* Jump to kernel
+args:
+ Kernel address - a0
+ PCBB - a1
+ First free PFN - a3?
+
+ Enable kseg addressing in ICSR
+ Enable kseg addressing in MCSR
+ Set VTBR -- Set to 1GB as per SRM, or maybe 8GB??
+ Set PCBB -- pass pointer in arg
+ Set PTBR -- get it out of PCB
+ Set KSP -- get it out of PCB
+
+ Jump to kernel address
+
+ Kernel args-
+ s0 first free PFN
+ s1 ptbr
+ s2 argc 0
+ s3 argv NULL
+ s5 osf_param (sysconfigtab) NULL
+ */
+
+ ALIGN_BRANCH
+
+ ldq_p a0, 0(zero)
+ ldq_p a1, 8(zero)
+ ldq_p a3, 16(zero)
+
+#ifdef undef
+ LDLI(t0,0x200000000) // 8GB, like the Mikasa
+ LDLI(t0,0x40000000) // 1GB, like the SRM
+ STALL // don't dual issue the load with mtpr -pb
+#endif
+ /* Point the Vptbr at 8GB */
+ lda t0, 0x1(zero)
+ sll t0, 33, t0
+
+ mtpr t0, mVptBr // Load Mbox copy
+ mtpr t0, iVptBr // Load Ibox copy
+ STALL // don't dual issue the load with mtpr -pb
+
+ /* Turn on superpage mapping in the mbox and icsr */
+ lda t0, (2<<MCSR_V_SP)(zero) // Get a '10' (binary) in MCSR<SP>
+ STALL // don't dual issue the load with mtpr -pb
+ mtpr t0, mcsr // Set the super page mode enable bit
+ STALL // don't dual issue the load with mtpr -pb
+
+ lda t0, 0(zero)
+ mtpr t0, dtbAsn
+ mtpr t0, itbAsn
+
+ LDLI (t1,0x20000000)
+ STALL // don't dual issue the load with mtpr -pb
+ mfpr t0, icsr // Enable superpage mapping
+ STALL // don't dual issue the load with mtpr -pb
+ bis t0, t1, t0
+ mtpr t0, icsr
+
+ STALL // Required stall to update chip ...
+ STALL
+ STALL
+ STALL
+ STALL
+
+ ldq_p s0, PCB_Q_PTBR(a1)
+ sll s0, VA_S_OFF, s0 // Shift PTBR into position
+ STALL // don't dual issue the load with mtpr -pb
+ mtpr s0, ptPtbr // PHYSICAL MBOX INST -> MT PT20 IN 0,1
+ STALL // don't dual issue the load with mtpr -pb
+ ldq_p sp, PCB_Q_KSP(a1)
+
+ mtpr a0, excAddr // Load the dispatch address.
+ STALL // don't dual issue the load with mtpr -pb
+ bis a3, zero, a0 // first free PFN
+ ldq_p a1, PCB_Q_PTBR(a1) // ptbr
+ ldq_p a2, 24(zero) // argc
+ ldq_p a3, 32(zero) // argv
+ ldq_p a4, 40(zero) // environ
+ lda a5, 0(zero) // osf_param
+ STALL // don't dual issue the load with mtpr -pb
+ mtpr zero, dtbIa // Flush all D-stream TB entries
+ mtpr zero, itbIa // Flush all I-stream TB entries
+ br zero, 2f
+
+ ALIGN_BLOCK
+
+2: NOP
+ mtpr zero, icFlush // Flush the icache.
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 1-10
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 11-20
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 21-30
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 31-40
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+
+
+ NOP // Required NOPs ... 41-44
+ NOP
+ NOP
+ NOP
+
+ hw_rei_stall // Dispatch to kernel
+
+
diff --git a/system/alpha/console/paljtoslave.s b/system/alpha/console/paljtoslave.s
new file mode 100644
index 000000000..c1809afb7
--- /dev/null
+++ b/system/alpha/console/paljtoslave.s
@@ -0,0 +1,150 @@
+#include "dc21164.h" // DECchip 21164 specific definitions
+#include "osf.h" // OSF/1 specific definitions
+#include "macros.h" // Global macro definitions
+#include "ev5_impure.h" // Scratch & logout area data structures
+#include "platform.h" // Platform specific definitions
+
+
+ .global palJToSlave
+ .text 3
+
+ /*
+ * args:
+ a0: here
+ a1: boot location
+ a2: CSERVE_J_KTOPAL
+ a3: restrart_pv
+ a4: vptb
+ a5: my_rpb
+
+ */
+palJToSlave:
+
+ /*
+ * SRM Console Architecture III 3-26
+ */
+
+ ALIGN_BRANCH
+
+ bis a3, zero, pv
+ bis zero, zero, t11
+ bis zero, zero, ra
+
+ /* Point the Vptbr to a2 */
+
+ mtpr a4, mVptBr // Load Mbox copy
+ mtpr a4, iVptBr // Load Ibox copy
+ STALL // don't dual issue the load with mtpr -pb
+
+ /* Turn on superpage mapping in the mbox and icsr */
+ lda t0, (2<<MCSR_V_SP)(zero) // Get a '10' (binary) in MCSR<SP>
+ STALL // don't dual issue the load with mtpr -pb
+ mtpr t0, mcsr // Set the super page mode enable bit
+ STALL // don't dual issue the load with mtpr -pb
+
+ lda t0, 0(zero)
+ mtpr t0, dtbAsn
+ mtpr t0, itbAsn
+
+ LDLI (t1,0x20000000)
+ STALL // don't dual issue the load with mtpr -pb
+ mfpr t0, icsr // Enable superpage mapping
+ STALL // don't dual issue the load with mtpr -pb
+ bis t0, t1, t0
+ mtpr t0, icsr
+
+ STALL // Required stall to update chip ...
+ STALL
+ STALL
+ STALL
+ STALL
+
+ ldq_p s0, PCB_Q_PTBR(a5)
+ sll s0, VA_S_OFF, s0 // Shift PTBR into position
+ STALL // don't dual issue the load with mtpr -pb
+ mtpr s0, ptPtbr // PHYSICAL MBOX INST -> MT PT20 IN 0,1
+ STALL // don't dual issue the load with mtpr -pb
+ ldq_p sp, PCB_Q_KSP(a5)
+
+ //mtpr a0, excAddr // Load the dispatch address.
+ //STALL // don't dual issue the load with mtpr -pb
+ //bis a3, zero, a0 // first free PFN
+ // ldq_p a1, PCB_Q_PTBR(a5) // ptbr
+
+ //ldq_p a2, 24(zero) // argc
+ //ldq_p a3, 32(zero) // argv
+ //ldq_p a4, 40(zero) // environ
+ //lda a5, 0(zero) // osf_param
+ //STALL // don't dual issue the load with mtpr -pb
+ mtpr zero, dtbIa // Flush all D-stream TB entries
+ mtpr zero, itbIa // Flush all I-stream TB entries
+
+
+ mtpr a1, excAddr // Load the dispatch address.
+
+ STALL // don't dual issue the load with mtpr -pb
+ STALL // don't dual issue the load with mtpr -pb
+ mtpr zero, dtbIa // Flush all D-stream TB entries
+ mtpr zero, itbIa // Flush all I-stream TB entries
+ br zero, 2f
+
+ ALIGN_BLOCK
+
+2: NOP
+ mtpr zero, icFlush // Flush the icache.
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 1-10
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 11-20
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 21-30
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+ NOP // Required NOPs ... 31-40
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+
+
+
+ NOP // Required NOPs ... 41-44
+ NOP
+ NOP
+ NOP
+
+ hw_rei_stall // Dispatch to kernel
+
diff --git a/system/alpha/console/paljtoslave.tmp b/system/alpha/console/paljtoslave.tmp
new file mode 100644
index 000000000..69d212b1e
--- /dev/null
+++ b/system/alpha/console/paljtoslave.tmp
@@ -0,0 +1,92 @@
+unsigned int palJToKern[] = {
+0x467f041b,
+0x47ff0419,
+0x47ff041a,
+0x76940208,
+0x76940113,
+0x67ff0140,
+0x203f0004,
+0x67ff0140,
+0x7421020f,
+0x67ff0140,
+0x203f0000,
+0x74210200,
+0x74210103,
+0x245f2000,
+0x20420000,
+0x67ff0140,
+0x64210118,
+0x67ff0140,
+0x44220401,
+0x74210118,
+0x67ff0140,
+0x67ff0140,
+0x67ff0140,
+0x67ff0140,
+0x67ff0140,
+0x6d359010,
+0x4921b729,
+0x67ff0140,
+0x75290154,
+0x67ff0140,
+0x6fd59000,
+0x77ff020a,
+0x77ff0105,
+0x7631010b,
+0x67ff0140,
+0x67ff0140,
+0x77ff020a,
+0x77ff0105,
+0xffffffffc3e00001,
+0x0,
+0x47ff041f,
+0x77ff0119,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x47ff041f,
+0x7bffc000,
+0x0,
+};
diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c
new file mode 100644
index 000000000..e0dc0426b
--- /dev/null
+++ b/system/alpha/console/printf.c
@@ -0,0 +1,298 @@
+/*****************************************************************************
+
+ Copyright İ 1993, 1994 Digital Equipment Corporation,
+ Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted, provided
+that the copyright notice and this permission notice appear in all copies
+of software and supporting documentation, and that the name of Digital not
+be used in advertising or publicity pertaining to distribution of the software
+without specific, written prior permission. Digital grants this permission
+provided that you prominently mark, as not part of the original, any
+modifications made to this software or documentation.
+
+Digital Equipment Corporation disclaims all warranties and/or guarantees
+with regard to this software, including all implied warranties of fitness for
+a particular purpose and merchantability, and makes no representations
+regarding the use of, or the results of the use of, the software and
+documentation in terms of correctness, accuracy, reliability, currentness or
+otherwise; and you rely on the software, documentation and results solely at
+your own risk.
+
+******************************************************************************/
+
+#ifndef LINT
+static char *rcsid = "$Id: printf.c,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $";
+#endif
+
+/*
+ * $Log: printf.c,v $
+ * Revision 1.1.1.1 1997/10/30 23:27:12 verghese
+ * current 10/29/97
+ *
+ * Revision 1.1 1995/06/26 21:09:35 berc
+ * Initial revision
+ *
+ * Revision 1.8 1994/10/06 20:29:08 fdh
+ * Corrected unsigned long declaration.
+ *
+ * Revision 1.7 1994/08/05 20:16:23 fdh
+ * Updated Copyright header and RCS $Id: identifier.
+ *
+ * Revision 1.6 1994/06/21 15:41:54 rusling
+ * fixedup WNT compiler warnings
+ *
+ * Revision 1.5 1994/06/17 19:35:37 fdh
+ * Clean-up...
+ *
+ * Revision 1.4 1994/01/19 10:40:08 rusling
+ * Ported to Alpha Windows NT.
+ *
+ * Revision 1.3 1993/11/02 21:57:45 fdh
+ * Fixed sign extension problem introduced in version 1.2
+ *
+ * Revision 1.2 1993/10/13 15:29:02 rusling
+ * Added floating point support in printf. This meant adding variable arguments to
+ * it and FormatItem() and including stdarg.h.
+ *
+ * Revision 1.1 1993/06/08 19:56:24 fdh
+ * Initial revision
+ *
+ */
+
+
+
+/* printf.c
+ L. S.
+ Sun Feb 10 20:18:22 1985
+ */
+
+#include "system.h"
+#include "lib.h"
+#include <stdarg.h>
+
+
+
+
+
+/* The string s is terminated by a '\0' */
+void PutString(char *s)
+{
+ while (*s) PutChar(*s++);
+}
+
+/* print c count times */
+void PutRepChar(char c, int count)
+{
+ while (count--) PutChar(c);
+}
+
+/* put string reverse */
+void PutStringReverse(char *s, int index)
+{
+ while ((index--) > 0) PutChar(s[index]);
+}
+
+/* prints value in radix, in a field width width, with fill
+ character fill
+ if radix is negative, print as signed quantity
+ if width is negative, left justify
+ if width is 0, use whatever is needed
+ if fill is 0, use ' '
+ */
+void PutNumber(sl value, int radix, int width, char fill)
+{
+ char buffer[40];
+ ui bufferindex = 0;
+ ul uvalue;
+ uw digit;
+ uw left = FALSE;
+ uw negative = FALSE;
+
+ if (fill == 0) fill = ' ';
+
+ if (width < 0) {
+ width = -width;
+ left = TRUE;
+ }
+ if (width < 0 || width > 80) width = 0;
+
+ if (radix < 0) {
+ radix = -radix;
+ if (value < 0) {
+ negative = TRUE;
+ value = -value;
+ }
+ }
+ switch (radix) {
+ case 8:
+ case 10:
+ case 16: break;
+ default: {
+ PutString("****");
+ return;
+ }
+ }
+ uvalue = value;
+ do {
+ if (radix != 16)
+ {
+ digit = (uw)(uvalue % radix);
+ uvalue /= radix;
+ }
+ else
+ {
+ digit = (uw)(uvalue & 0xf);
+ uvalue = uvalue >> 4;
+ }
+ buffer[bufferindex] = digit + ((digit <= 9) ? '0' : ('A' - 10));
+ bufferindex += 1;
+ } while (uvalue != 0);
+ /* fill # ' ' and negative cannot happen at once */
+ if (negative) {
+ buffer[bufferindex] = '-';
+ bufferindex += 1;
+ }
+ if ((ui)width <= bufferindex) PutStringReverse(buffer, bufferindex);
+ else {
+ width -= bufferindex;
+ if (!left) PutRepChar(fill, width);
+ PutStringReverse(buffer, bufferindex);
+ if (left) PutRepChar(fill, width);
+ }
+}
+
+ul power(long base, long n)
+{
+ ul p;
+
+ for (p = 1; n > 0; --n)
+ p = p * base;
+ return p;
+}
+
+void putFloat(double a, int fieldwidth, char fill)
+{
+ int i;
+ ul b;
+
+/*
+ * Put out everything before the decimal place.
+ */
+ PutNumber(((ul) a), 10, fieldwidth, fill);
+/*
+ * Output the decimal place.
+ */
+ PutChar('.' & 0x7f);
+/*
+ * Output the n digits after the decimal place.
+ */
+ for (i = 1; i < 6; i++) {
+ b = (ul)(power(10, i) * (double)(a - (ul) a));
+ PutChar((char)(b % 10) + '0');
+ }
+}
+char *FormatItem(char *f, va_list *ap)
+{
+ char c;
+ int fieldwidth = 0;
+ int leftjust = FALSE;
+ int radix = 0;
+ char fill = ' ';
+ if (*f == '0') fill = '0';
+ while (c = *f++) {
+ if (c >= '0' && c <= '9') {
+ fieldwidth = (fieldwidth * 10) + (c - '0');
+ }
+ else switch (c) {
+ case '\000': return(--f);
+ case '%': PutChar('%');
+ return(f);
+ case '-': leftjust = TRUE;
+ break;
+ case 'c': {
+ char a = va_arg(*ap, char);
+
+ if (leftjust) PutChar(a & 0x7f);
+ if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1);
+ if (!leftjust) PutChar(a & 0x7f);
+ return(f);
+ }
+ case 's': {
+ char *a = va_arg(*ap, char *);
+
+ if (leftjust) PutString((char *) a);
+ if (fieldwidth > strlen((char *) a))
+ PutRepChar(fill, fieldwidth - strlen((char *)a));
+ if (!leftjust) PutString((char *) a);
+ return(f);
+ }
+ case 'd': radix = -10;
+ break;
+ case 'u': radix = 10;
+ break;
+ case 'x': radix = 16;
+ break;
+ case 'X': radix = 16;
+ break;
+ case 'o': radix = 8;
+ break;
+ case 'f': {
+ double a = va_arg(*ap, double);
+
+ putFloat(a, fieldwidth, fill);
+ return(f);
+ }
+ default: /* unknown switch! */
+ radix = 3;
+ break;
+ }
+ if (radix) break;
+ }
+ if (leftjust) fieldwidth = -fieldwidth;
+ {
+ sl a = va_arg(*ap, sl);
+ PutNumber(a, radix, fieldwidth, fill);
+ }
+ return(f);
+}
+
+void printf(char *f, ...)
+{
+ va_list ap;
+
+ va_start(ap, f);
+
+ while (*f) {
+ if (*f == '%') f = FormatItem(f + 1, &ap);
+ else PutChar(*f++);
+ }
+
+ if (*(f-1)=='\n') {
+ /* add a line-feed (SimOS console output goes to shell */
+ PutChar('\r');
+ }
+
+ va_end(ap); /* clean up */
+}
+
+void panic(char *f, ...)
+{
+ va_list ap;
+
+ va_start(ap, f);
+
+ printf("CONSOLE PANIC (looping): ");
+ while (*f) {
+ if (*f == '%') f = FormatItem(f + 1, &ap);
+ else PutChar(*f++);
+ }
+
+ va_end(ap); /* clean up */
+ while(1);
+}
+
+