tgt_machdep.c
来自「国产CPU-龙芯(loongson)BIOS源代码」· C语言 代码 · 共 1,971 行 · 第 1/3 页
C
1,971 行
/* $Id: tgt_machdep.c,v 1.4 2004/05/17 10:39:22 wlin Exp $ *//* * Copyright (c) 2001 Opsycon AB (www.opsycon.se) * * 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 Opsycon AB, Sweden. * 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 <sys/param.h>#include <sys/syslog.h>#include <machine/endian.h>#include <sys/device.h>#include <machine/cpu.h>#include <machine/pio.h>#include <machine/intr.h>#include <sys/types.h>#include <termio.h>#include <string.h>#include <time.h>#include <stdlib.h>#include <dev/ic/mc146818reg.h>#include <linux/io.h>#include <autoconf.h>#include <machine/cpu.h>#include <machine/pio.h>#include "pflash.h"#include "dev/pflash_tgt.h"#include <pmon/dev/ns16550.h>#include <pmon.h>#include <include/gfcr.h>#include "flash.h"#if (NMOD_FLASH_AMD + NMOD_FLASH_INTEL) == 0#ifdef HAVE_FLASH#undef HAVE_FLASH#endif#else#define HAVE_FLASH#endifextern struct trapframe DBGREG;extern void *memset(void *, int, size_t);extern void put32(unsigned int);int kbd_available = 0;int vga_available = 0;static int md_pipefreq = 0;static int md_cpufreq = 0;static int clk_invalid = 0;static int nvram_invalid = 0;static int cksum(void *p, size_t s, int set);static void _probe_frequencies(void);#ifndef NVRAM_IN_FLASHvoid nvram_get(char *);void nvram_put(char *);#endifvoid error(unsigned long *adr, unsigned long good, unsigned long bad);void modtst(int offset, int iter, unsigned long p1, unsigned long p2);void do_tick(void);void print_hdr(void);void ad_err2(unsigned long *adr, unsigned long bad);void ad_err1(unsigned long *adr1, unsigned long *adr2, unsigned long good, unsigned long bad);void mv_error(unsigned long *adr, unsigned long good, unsigned long bad);void print_err( unsigned long *adr, unsigned long good, unsigned long bad, unsigned long xor);ConfigEntry ConfigTable[] ={ { (char *)0xbf004090, 0, ns16550, 256, CONS_BAUD, NS16550HZ }, { 0 }};unsigned long _filebase;extern int memorysize;extern int memorysize_high;extern char MipsException[], MipsExceptionEnd[];unsigned char hwethadr[6];int fb_available = 0;unsigned long fbaddress = 0;unsigned long ioaddress = 0;void initmips(unsigned int memsz);void addr_tst1(void);void addr_tst2(void);void movinv1(int iter, ulong p1, ulong p2);voidinitmips(unsigned int memsz){ /* * Set up memory address decoders to map entire memory. * But first move away bootrom map to high memory. */ int i=0; memorysize = 0x8000000; memorysize_high=0; /* * Probe clock frequencys so delays will work properly. */ tgt_cpufreq(); SBD_DISPLAY("FREQ",0); /* * Init PMON and debug */ cpuinfotab[0] = &DBGREG; for (i=0;i<0x100000;i++); dbginit(NULL); /* * Set up exception vectors. */ SBD_DISPLAY("BEV1",0); bcopy(MipsException, (char *)TLB_MISS_EXC_VEC, MipsExceptionEnd - MipsException); bcopy(MipsException, (char *)GEN_EXC_VEC, MipsExceptionEnd - MipsException); CPU_FlushCache(); CPU_SetSR(0, SR_BOOT_EXC_VEC); SBD_DISPLAY("BEV0",0); printf("BEV in SR set to zero.\n"); #if 0 /* memtest */ addr_tst1(); addr_tst2(); movinv1(2,0,~0); movinv1(2,0xaa5555aa,~0xaa5555aa); printf("memtest done\n");#endif /* * Launch! */ main();}/* * Put all machine dependent initialization here. This call * is done after console has been initialized so it's safe * to output configuration and debug information with printf. */voidtgt_devconfig(){ config_init(); configure(); printf("devconfig done.\n");}extern int test_icache_1(short *addr);extern int test_icache_2(int addr);extern int test_icache_3(int addr);extern void godson1_cache_flush(void);#define tgt_putchar_uc(x) (*(void (*)(char)) (((long)tgt_putchar)|0x20000000)) (x)voidtgt_devinit(){ /* * Gather info about and configure caches. */ if(getenv("ocache_off")) { CpuOnboardCacheOn = 0; } else { CpuOnboardCacheOn = 1; } if(getenv("ecache_off")) { CpuExternalCacheOn = 0; } else { CpuExternalCacheOn = 1; }/* tgt_putchar('!'); tgt_putchar('@'); tgt_putchar('#'); tgt_putchar('$');*/ CPU_ConfigCache(); //godson2_cache_flush();/* tgt_putchar('^'); tgt_putchar('&'); tgt_putchar('*'); tgt_putchar('%'); tgt_putchar('^'); tgt_putchar('&'); tgt_putchar('*');*/ //test_icache_2(0); //test_icache_3(0); //tgt_putchar(0x30+i); //tgt_putchar('Y'); //tgt_test_memory(); //tgt_putchar('Z');// _pci_businit(1); /* PCI bus initialization */}voidtgt_reboot(){ void (*longreach) __P((void)); longreach = (void *)0xbfc00000; (*longreach)(); while(1);}/* * This function makes inital HW setup for debugger and * returns the apropriate setting for the status register. */register_ttgt_enable(int machtype){ /* XXX Do any HW specific setup */ return(SR_COP_1_BIT|SR_FR_32|SR_EXL);}/* * Target dependent version printout. * Printout available target version information. */voidtgt_cmd_vers(){}/* * Display any target specific logo. */voidtgt_logo(){ printf("\n"); printf("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n"); printf("[[[ [[[[ [[[[[[[[[[ [[[[ [[[[ [[[[[[[ [[\n"); printf("[[ [[[[[[[[ [[[ [[[[[[[[ [[[ [[[[[[[[ [[[ [[[[[[ [[\n"); printf("[[ [[[[[[[[[[ [[[ [ [[[[[[ [ [[[ [[[[[[[[[[ [[[ [ [[[[[ [[\n"); printf("[[ [[[[[[[[[[ [[[ [[ [[[[ [[ [[[ [[[[[[[[[[ [[[ [[ [[[[ [[\n"); printf("[[ [[[[[[[[ [[[ [[[ [[ [[[ [[[ [[[[[[[[[[ [[[ [[[ [[[ [[\n"); printf("[[ [[[[ [[[[ [[[[ [[[ [[[[[[[[[[ [[[ [[[[ [[ [[\n"); printf("[[ [[[[[[[[[[[[[[[ [[[[[ [[[[[ [[[ [[[[[[[[[[ [[[ [[[[[ [ [[\n"); printf("[[ [[[[[[[[[[[[[[[ [[[[[[[[[[[[ [[[ [[[[[[[[[[ [[[ [[[[[[ [[\n"); printf("[[ [[[[[[[[[[[[[[[ [[[[[[[[[[[[ [[[ [[[[[[[[ [[[ [[[[[[[ [[\n"); printf("[[ [[[[[[[[[[[[[[[ [[[[[[[[[[[[ [[[[ [[[[ [[[[[[[[ [[\n"); printf("[[[[[[[2000][[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n"); }static void_probe_frequencies(){ md_pipefreq = 33000000; /* Defaults */ md_cpufreq = 33000000; clk_invalid = 1;} /* * Returns the CPU pipelie clock frequency */inttgt_pipefreq(){ if(md_pipefreq == 0) { _probe_frequencies(); } return(md_pipefreq);}/* * Returns the external clock frequency, usually the bus clock */inttgt_cpufreq(){ if(md_cpufreq == 0) { _probe_frequencies(); } return(md_cpufreq);}time_ttgt_gettime(){ int t = 957960000; /* Wed May 10 14:00:00 2000 :-) */ return(t);} /* * Set the current time if a TOD clock is present */voidtgt_settime(time_t t){ if(!clk_invalid) { }}/* * Print out any target specific memory information */voidtgt_memprint(){ printf("Primary Instruction cache size %dkb (%d line, %d way)\n", CpuPrimaryInstCacheSize / 1024, CpuPrimaryInstCacheLSize, CpuNWayCache); printf("Primary Data cache size %dkb (%d line, %d way)\n", CpuPrimaryDataCacheSize / 1024, CpuPrimaryDataCacheLSize, CpuNWayCache); if(CpuSecondaryCacheSize != 0) { printf("Secondary cache size %dkb\n", CpuSecondaryCacheSize / 1024); } if(CpuTertiaryCacheSize != 0) { printf("Tertiary cache size %dkb\n", CpuTertiaryCacheSize / 1024); }}voidtgt_machprint(){ printf("Copyright 2000-2002, Opsycon AB, Sweden.\n"); printf("Copyright 2003, Michael and Pine, ICT CAS.\n"); printf("CPU %s @", md_cpuname());} /* * Return a suitable address for the client stack. * Usually top of RAM memory. */register_ttgt_clienttos(){ return((register_t)(int)PHYS_TO_UNCACHED(memorysize & ~7) - 64);}#ifdef HAVE_FLASH/* * Flash programming support code. *//* * Table of flash devices on target. See pflash_tgt.h. */struct fl_map tgt_fl_map_boot16[]={ TARGET_FLASH_DEVICES_16};struct fl_map *tgt_flashmap(){ return tgt_fl_map_boot16;} voidtgt_flashwrite_disable(){}inttgt_flashwrite_enable(){ return(1);}voidtgt_flashinfo(void *p, size_t *t){ struct fl_map *map; map = fl_find_map(p); if(map) { *t = map->fl_map_size; } else { *t = 0; }}voidtgt_flashprogram(void *p, int size, void *s, int endian){ printf("Programming flash %x:%x into %x\n", s, size, p); if(fl_erase_device(p, size, TRUE)) { printf("Erase failed!\n"); return; } if(fl_program_device(p, s, size, TRUE)) { printf("Programming failed!\n"); } fl_verify_device(p, s, size, TRUE);}#endif /* PFLASH *//* * Network stuff. */voidtgt_netinit(){}inttgt_ethaddr(char *p){ bcopy((void *)&hwethadr, p, 6); return(0);}voidtgt_netreset(){}/*************************************************************************//* * Target dependent Non volatile memory support code * ================================================= * * * On this target a part of the boot flash memory is used to store * environment. See EV64260.h for mapping details. (offset and size). *//* * Read in environment from NV-ram and set. */voidtgt_mapenv(int (*func) __P((char *, char *))){ char *ep; char env[512]; char *nvram; int i; /* * Check integrity of the NVRAM env area. If not in order * initialize it to empty. */#ifdef NVRAM_IN_FLASH nvram = (char *)(tgt_flashmap())->fl_map_base; put32((unsigned int)nvram); if(fl_devident(nvram, NULL) == 0 || cksum(nvram + NVRAM_OFFS, NVRAM_SIZE, 0) != 0) {#else nvram = (char *)malloc(512); nvram_get(nvram); if(cksum(nvram, NVRAM_SIZE, 0) != 0) {#endif printf("NVRAM is invalid!\n"); nvram_invalid = 1; } else { nvram += NVRAM_OFFS; ep = nvram+2;; while(*ep != 0) { char *val = 0, *p = env; i = 0; while((*p++ = *ep++) && (ep <= nvram + NVRAM_SIZE - 1) && i++ < 255) { if((*(p - 1) == '=') && (val == NULL)) { *(p - 1) = '\0'; val = p; } } if(ep <= nvram + NVRAM_SIZE - 1 && i < 255) { (*func)(env, val); } else { nvram_invalid = 2; break; } } } printf("NVRAM@%x\n",(u_int32_t)nvram); /* * Ethernet address for Galileo ethernet is stored in the last * six bytes of nvram storage. Set environment to it. */ bcopy(&nvram[ETHER_OFFS], hwethadr, 6); sprintf(env, "%02x:%02x:%02x:%02x:%02x:%02x", hwethadr[0], hwethadr[1], hwethadr[2], hwethadr[3], hwethadr[4], hwethadr[5]); (*func)("ethaddr", env);#ifndef NVRAM_IN_FLASH free(nvram);#endif#ifdef no_thank_you (*func)("vxWorks", env);#endif sprintf(env, "%d", memorysize / (1024 * 1024)); (*func)("memsize", env); sprintf(env, "%d", md_pipefreq); (*func)("cpuclock", env); sprintf(env, "%d", md_cpufreq); (*func)("busclock", env); (*func)("systype", SYSTYPE); printf("mapenv done\n");}inttgt_unsetenv(char *name){ char *ep, *np, *sp; char *nvram; char *nvrambuf; char *nvramsecbuf; int status; if(nvram_invalid) { return(0); } /* Use first defined flash device (we probably have only one) */#ifdef NVRAM_IN_FLASH nvram = (char *)(tgt_flashmap())->fl_map_base; /* Map. Deal with an entire sector even if we only use part of it */ nvram += NVRAM_OFFS & ~(NVRAM_SECSIZE - 1); nvramsecbuf = (char *)malloc(NVRAM_SECSIZE); if(nvramsecbuf == 0) { printf("Warning! Unable to malloc nvrambuffer!\n"); return(-1); } memcpy(nvramsecbuf, nvram, NVRAM_SECSIZE); nvrambuf = nvramsecbuf + (NVRAM_OFFS & (NVRAM_SECSIZE - 1));#else nvramsecbuf = nvrambuf = nvram = (char *)malloc(512); nvram_get(nvram);#endif ep = nvrambuf + 2; status = 0; while((*ep != '\0') && (ep <= nvrambuf + NVRAM_SIZE)) { np = name; sp = ep; while((*ep == *np) && (*ep != '=') && (*np != '\0')) { ep++; np++; } if((*np == '\0') && ((*ep == '\0') || (*ep == '='))) { while(*ep++); while(ep <= nvrambuf + NVRAM_SIZE) { *sp++ = *ep++; } if(nvrambuf[2] == '\0') { nvrambuf[3] = '\0'; } cksum(nvrambuf, NVRAM_SIZE, 1);#ifdef NVRAM_IN_FLASH if(fl_erase_device(nvram, NVRAM_SECSIZE, FALSE)) { status = -1; break; } if(fl_program_device(nvram, nvramsecbuf, NVRAM_SECSIZE, FALSE)) { status = -1; break; }#else nvram_put(nvram);#endif status = 1; break; } else if(*ep != '\0') { while(*ep++ != '\0'); } } free(nvramsecbuf); return(status);}inttgt_setenv(char *name, char *value){ char *ep; int envlen; char *nvrambuf; char *nvramsecbuf;#ifdef NVRAM_IN_FLASH char *nvram;#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?