📄 sh4-ipl.c
字号:
/* sh4-ipl: Initial Program Loader for SH7750 * * Copyright (C) 2001 KOMORIYA Takeru * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the file "GPL" for more details. * * Contact to author: * KOMORIYA Takeru, AAF Sendai Lab., Japan * E-mail: komoriya@chmodx.dyndns.org * URL: http://chmodx.dyndns.org/aaf/ */#include <stdio.h>#include <stddef.h>#include "sh7750.h"#include "sh-sci.h"#include "sh-intr.h"#include "sh-cache.h"/* Routines to handle hex data */static const char hexchars[] = "0123456789abcdef";char highhex(int x){ return hexchars[(x >> 4) & 0xf];}char lowhex(int x){ return hexchars[x & 0xf];}inthex (char ch){ if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10); if ((ch >= '0') && (ch <= '9')) return (ch - '0'); if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10); return (-1);}/* read srec format data */static intread_srec (void){ int i, mode, bytes, hi, low, addr; static int blink_ticks = 0; unsigned char data[32]; unsigned char checksum; char *mem; void (*startpoint)(void); mode = scif_getcw () - '0'; /* get bytes of line */ hi = scif_getcw (); low = scif_getcw (); bytes = hex (hi) * 16 + hex (low); data[0] = bytes; for (i=1; i<=bytes; i++) { hi = scif_getcw (); low = scif_getcw (); data[i] = hex (hi) * 16 + hex (low); } while (scif_getcw () != '\n'); /* Checksum */ checksum = 0; for(i=0 ; i<bytes ; i++) checksum += data[i]; checksum = 0xff - checksum; if(data[bytes] != checksum){ /* Checksum error */ scif_puts ("Checksum error\r\n"); return 1; } /* blink LED */ if( blink_ticks++ % 50 == 0) PDTRB = PDTRB ^ 0x0008; switch (mode) { case 0: /* header */ scif_puts ("\r\n"); break; case 1: /* 16bit address */ addr = ((int)data[1]<<8) + (int)data[2]; mem = (char *)addr; for (i=0; i<bytes-3; i++) *mem++ = data[i+3]; break; case 2: /* 24bit address */ addr = ((int)data[1]<<16) + ((int)data[2]<<8) + (int)data[3]; mem = (char *)addr; for (i=0; i<bytes-4; i++) *mem++ = data[i+4]; break; case 3: /* 32bit address */ addr = ((int)data[1]<<24) + ((int)data[2]<<16) + ((int)data[3]<<8) + (int)data[4]; mem = (char *)addr; for (i=0; i<bytes-5; i++) *mem++ = data[i+5]; break; case 7: /* start address(32bit) */ startpoint = (void*)( ((unsigned long)(data[1])<<24) + ((unsigned long)(data[2])<<16) + ((unsigned long)(data[3])<<8) + (unsigned long)(data[4]) ); scif_puts ("Start address: 0x"); for (i=1; i<5; i++){ scif_put_hex (data[i],2); } scif_puts ("\r\n"); sh_cache_control(CACHE_DISABLE); scif_disable(); PDTRB = PDTRB & ~0x0008; /* LED OFF */ startpoint (); /* jump to user program */ PDTRB = PDTRB | 0x0008; /* LED ON */ scif_init(); sh_cache_control(CACHE_ENABLE); return 1; case 8: /* start address(24bit) */ startpoint = (void*)( ((unsigned long)(data[1])<<16) + ((unsigned long)(data[2])<<8) + (unsigned long)(data[3]) ); scif_puts ("Start address: 0x"); for (i=1; i<4; i++){ scif_put_hex (data[i],2); } scif_puts ("\r\n"); sh_cache_control(CACHE_DISABLE); scif_disable(); PDTRB = PDTRB & ~0x0008; /* LED OFF */ startpoint (); /* jump to user program */ PDTRB = PDTRB | 0x0008; /* LED ON */ scif_init(); sh_cache_control(CACHE_ENABLE); return 1; case 9: /* start address(16bit) */ startpoint = (void*)( ((unsigned long)(data[1])<<8) + (unsigned long)(data[2]) ); scif_puts ("Start address: 0x"); for (i=1; i<3; i++){ scif_put_hex (data[i],2); } scif_puts ("\r\n"); sh_cache_control(CACHE_DISABLE); scif_disable(); PDTRB = PDTRB & ~0x0008; /* LED OFF */ startpoint (); /* jump to user program */ PDTRB = PDTRB | 0x0008; /* LED ON */ scif_init(); sh_cache_control(CACHE_ENABLE); return 1; } return 0;}static const char * const banner = "\r\n\SH4-IPL version 0.3, Copyright (C) 2001 KOMORIYA Takeru\r\n\\r\n\This software comes with ABSOLUTELY NO WARRANTY; for details type `w'.\r\n\This is free software, and you are welcome to redistribute it under\r\n\certain conditions; type `l' for details.\r\n\r\n";static const char * const license_message = "\r\n\SH4-IPL is free software; you can redistribute it and/or modify it under\r\n\the terms of the GNU General Public License as published by \r\n\the Free Software Foundatin; either version 2 of the License, or (at your \r\n\option) any later version.\r\n\r\n";static const char * const warranty_message = "\r\n\SH4-IPL is distributed in the hope that it will be useful, but\r\n\WITHOUT ANY WARRANTY; without even the implied warranty of\r\n\MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n\General Public License for more details.\r\n\r\n";static const char * const help_message = "\r\n\SH4-IPL version 0.3, Copyright (C) 2001 KOMORIYA Takeru\r\n\ Feed your program in Motrola 'srec' format.\r\n\ ? --- Show this message (HELP)\r\n\ l --- Show about license\r\n\ w --- Show about (no)warranty\r\n\r\n\";static const char * const prompt = "> ";voidstart_main (void){ char c; int showprompt = 1; /* initialize SCIF */ scif_init(); /* enable cache */ sh_cache_control(CACHE_ENABLE); /* show banner */ scif_puts (banner); /* LED ON */ PCTRB = 0x000000c0; PDTRB = 0x0008; while (1) { if (showprompt) scif_puts (prompt); c = scif_getcw (); switch (c) { case '?': /* Help */ scif_puts ("?"); scif_puts (help_message); break; case 'l': /* License */ scif_puts ("l"); scif_puts (license_message); break; case 'S': /* Read srec format data */ showprompt = read_srec(); break; case 'w': /* Warranty */ scif_puts ("w"); scif_puts (warranty_message); break; default: scif_puts ("\r\n"); break; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -