TX39xx support.

- startproc.c is divided into 3 files, mips.c, vr41xx.c and tx39xx.c
  - add systeminfo.c
Version of pbsdboot.exe is 1.6.0.
This commit is contained in:
takemura 1999-09-26 02:42:50 +00:00
parent 75e3195cad
commit 9759fc2177
10 changed files with 2239 additions and 1957 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: disptest.c,v 1.1.1.1 1999/09/16 12:23:30 takemura Exp $ */
/* $NetBSD: disptest.c,v 1.2 1999/09/26 02:42:50 takemura Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura.
@ -67,10 +67,10 @@ gpio_test()
volatile unsigned short *giuselh;
volatile unsigned short *giupiodl;
volatile unsigned short *giupiodh;
unsigned long sell = 0;
unsigned long selh = 0;
unsigned long piodl = 0;
unsigned long piodh = 0;
unsigned short sell = 0;
unsigned short selh = 0;
unsigned short piodl = 0;
unsigned short piodh = 0;
int res, i;
unsigned short regs[16];
unsigned short prev_regs[16];

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.3 1999/09/23 08:30:59 takemura Exp $ */
/* $NetBSD: main.c,v 1.4 1999/09/26 02:42:50 takemura Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura.
@ -383,7 +383,7 @@ BOOL CALLBACK DlgProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_INITDIALOG:
SetDlgItemText(hWnd, IDC_ABOUT_EDIT,
TEXT("PocketBSD boot loader\r\n")
TEXT("Version 1.5.0 1999.09.23\r\n")
TEXT("Version 1.6.0 1999.09.26\r\n")
TEXT("\r\n")
TEXT("Copyright(C) 1999 Shin Takemura,\r\n")
TEXT("All rights reserved.\r\n")
@ -869,12 +869,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
if (pref.serial_port) {
SerialPort(TRUE);
}
/*
* boot !
/*
* Set system infomation
*/
pbsdboot(wkernel_name, argc, argv, &bi);
if (set_system_info()) {
/*
* boot !
*/
pbsdboot(wkernel_name, argc, argv, &bi);
}
/*
* Not return.
*/

View File

@ -0,0 +1,85 @@
/* $NetBSD: mips.c,v 1.1 1999/09/26 02:42:50 takemura Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura.
* All rights reserved.
*
* This software is part of the PocketBSD.
*
* 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 PocketBSD project
* and its contributors.
* 4. Neither the name of the project 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.
*
*/
#include <pbsdboot.h>
int
mips_boot(caddr_t map)
{
unsigned char *mem;
unsigned long jump_instruction, phys_mem;
/*
* allocate physical memory for startup program.
*/
if ((mem = (unsigned char*)vmem_alloc()) == NULL) {
debug_printf(TEXT("can't allocate final page.\n"));
msg_printf(MSG_ERROR, whoami, TEXT("can't allocate root page.\n"));
return (-1);
}
/*
* copy startup program code
*/
memcpy(mem, system_info.si_asmcode, system_info.si_asmcodelen);
/*
* set map address (override target field ofasmcode
* "lui a0, 0x0; ori a0, 0x0;".
*/
*(unsigned short*)&mem[0] = (unsigned short)(((long)map) >> 16);
*(unsigned short*)&mem[4] = (unsigned short)map;
/*
* construct start instruction
*/
phys_mem = (unsigned long)vtophysaddr(mem);
jump_instruction = (0x08000000 | ((phys_mem >> 2) & 0x03ffffff));
/*
* map interrupt vector
*/
mem = (unsigned char*)VirtualAlloc(0, 0x400, MEM_RESERVE, PAGE_NOACCESS);
VirtualCopy((LPVOID)mem, (LPVOID)(system_info.si_dramstart >> 8), 0x400,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL);
/*
* GO !
*/
*(unsigned long*)&mem[0x0] = jump_instruction;
return (0); /* not reachable */
}

View File

@ -310,6 +310,57 @@ DEP_CPP_MAIN_=\
".\pbsdboot.h"\
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\mips.c
!IF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Release"
!ELSEIF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Debug"
DEP_CPP_MIPS_=\
"..\..\..\..\lib\libsa\saerrno.h"\
"..\..\..\..\lib\libsa\saioctl.h"\
"..\..\..\..\lib\libsa\stand.h"\
"..\..\..\..\sys\bswap.h"\
"..\..\..\..\sys\cdefs.h"\
"..\..\..\..\sys\cdefs_aout.h"\
"..\..\..\..\sys\cdefs_elf.h"\
"..\..\..\..\sys\endian.h"\
"..\..\..\..\sys\errno.h"\
"..\..\..\..\sys\featuretest.h"\
"..\..\..\..\sys\stat.h"\
"..\..\..\..\sys\time.h"\
"..\..\..\..\sys\types.h"\
"..\..\..\mips\include\ansi.h"\
"..\..\..\mips\include\bswap.h"\
"..\..\..\mips\include\cdefs.h"\
"..\..\..\mips\include\endian.h"\
"..\..\include\ansi.h"\
"..\..\include\bootinfo.h"\
"..\..\include\cdefs.h"\
"..\..\include\endian.h"\
"..\..\include\platid.h"\
"..\..\include\platid_generated.h"\
"..\include\machine\ansi.h"\
"..\include\machine\bootinfo.h"\
"..\include\machine\bswap.h"\
"..\include\machine\cdefs.h"\
"..\include\machine\endian.h"\
"..\include\machine\platid.h"\
"..\include\machine\types.h"\
"..\include\mips\ansi.h"\
"..\include\mips\cdefs.h"\
"..\include\mips\endian.h"\
"..\include\mips\types.h"\
"..\libsa\compat.h"\
"..\libsa\stand.h"\
".\pbsdboot.h"\
!ENDIF
# End Source File
@ -479,13 +530,64 @@ DEP_CPP_PRINT=\
# End Source File
# Begin Source File
SOURCE=.\startprog.c
SOURCE=.\systeminfo.c
!IF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Release"
!ELSEIF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Debug"
DEP_CPP_START=\
DEP_CPP_SYSTE=\
"..\..\..\..\lib\libsa\saerrno.h"\
"..\..\..\..\lib\libsa\saioctl.h"\
"..\..\..\..\lib\libsa\stand.h"\
"..\..\..\..\sys\bswap.h"\
"..\..\..\..\sys\cdefs.h"\
"..\..\..\..\sys\cdefs_aout.h"\
"..\..\..\..\sys\cdefs_elf.h"\
"..\..\..\..\sys\endian.h"\
"..\..\..\..\sys\errno.h"\
"..\..\..\..\sys\featuretest.h"\
"..\..\..\..\sys\stat.h"\
"..\..\..\..\sys\time.h"\
"..\..\..\..\sys\types.h"\
"..\..\..\mips\include\ansi.h"\
"..\..\..\mips\include\bswap.h"\
"..\..\..\mips\include\cdefs.h"\
"..\..\..\mips\include\endian.h"\
"..\..\include\ansi.h"\
"..\..\include\bootinfo.h"\
"..\..\include\cdefs.h"\
"..\..\include\endian.h"\
"..\..\include\platid.h"\
"..\..\include\platid_generated.h"\
"..\include\machine\ansi.h"\
"..\include\machine\bootinfo.h"\
"..\include\machine\bswap.h"\
"..\include\machine\cdefs.h"\
"..\include\machine\endian.h"\
"..\include\machine\platid.h"\
"..\include\machine\types.h"\
"..\include\mips\ansi.h"\
"..\include\mips\cdefs.h"\
"..\include\mips\endian.h"\
"..\include\mips\types.h"\
"..\libsa\compat.h"\
"..\libsa\stand.h"\
".\pbsdboot.h"\
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\tx39xx.c
!IF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Release"
!ELSEIF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Debug"
DEP_CPP_TX39X=\
"..\..\..\..\lib\libsa\saerrno.h"\
"..\..\..\..\lib\libsa\saioctl.h"\
"..\..\..\..\lib\libsa\stand.h"\
@ -576,6 +678,57 @@ DEP_CPP_VMEM_=\
".\pbsdboot.h"\
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\vr41xx.c
!IF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Release"
!ELSEIF "$(CFG)" == "pbsdboot - Win32 (WCE MIPS) Debug"
DEP_CPP_VR41X=\
"..\..\..\..\lib\libsa\saerrno.h"\
"..\..\..\..\lib\libsa\saioctl.h"\
"..\..\..\..\lib\libsa\stand.h"\
"..\..\..\..\sys\bswap.h"\
"..\..\..\..\sys\cdefs.h"\
"..\..\..\..\sys\cdefs_aout.h"\
"..\..\..\..\sys\cdefs_elf.h"\
"..\..\..\..\sys\endian.h"\
"..\..\..\..\sys\errno.h"\
"..\..\..\..\sys\featuretest.h"\
"..\..\..\..\sys\stat.h"\
"..\..\..\..\sys\time.h"\
"..\..\..\..\sys\types.h"\
"..\..\..\mips\include\ansi.h"\
"..\..\..\mips\include\bswap.h"\
"..\..\..\mips\include\cdefs.h"\
"..\..\..\mips\include\endian.h"\
"..\..\include\ansi.h"\
"..\..\include\bootinfo.h"\
"..\..\include\cdefs.h"\
"..\..\include\endian.h"\
"..\..\include\platid.h"\
"..\..\include\platid_generated.h"\
"..\include\machine\ansi.h"\
"..\include\machine\bootinfo.h"\
"..\include\machine\bswap.h"\
"..\include\machine\cdefs.h"\
"..\include\machine\endian.h"\
"..\include\machine\platid.h"\
"..\include\machine\types.h"\
"..\include\mips\ansi.h"\
"..\include\mips\cdefs.h"\
"..\include\mips\endian.h"\
"..\include\mips\types.h"\
"..\libsa\compat.h"\
"..\libsa\stand.h"\
".\pbsdboot.h"\
!ENDIF
# End Source File

View File

@ -1,4 +1,4 @@
/* $NetBSD: pbsdboot.h,v 1.2 1999/09/22 12:49:49 uch Exp $ */
/* $NetBSD: pbsdboot.h,v 1.3 1999/09/26 02:42:50 takemura Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura.
@ -84,6 +84,20 @@ struct preference_s {
BOOL load_debug_info;
BOOL serial_port;
};
/*
* Machine dependent information
*/
struct system_info {
unsigned int si_dramstart;
unsigned int si_drammaxsize;
DWORD si_pagesize;
unsigned char *si_asmcode;
int si_asmcodelen;
int (*si_boot) __P((caddr_t));
};
extern struct system_info system_info;
extern struct preference_s pref;
extern TCHAR* where_pref_load_from;
@ -102,7 +116,6 @@ int CreateMainWindow(HINSTANCE hInstance, HWND hWnd, LPCTSTR name, int cmdbar_he
* vmem.c
*/
int vmem_exec(caddr_t entry, int argc, char *argv[], struct bootinfo *bi);
DWORD getpagesize(void);
caddr_t vmem_get(caddr_t phys_addr, int *length);
int vmem_init(caddr_t start, caddr_t end);
void vmem_dump_map(void);
@ -117,9 +130,9 @@ int getinfo(int fd, caddr_t *start, caddr_t *end);
int loadfile(int fd, caddr_t *entry);
/*
* startprog.c
* mips.c
*/
int startprog(caddr_t map);
int mips_boot(caddr_t map);
/*
* pbsdboot.c
@ -149,3 +162,21 @@ void pref_dump(struct preference_s* pref);
int pref_read(TCHAR* filename, struct preference_s* pref);
int pref_load(TCHAR* load_path[], int pathlen);
int pref_write(TCHAR* filename, struct preference_s* buf);
/*
* systeminfo.c
*/
int set_system_info(void);
/*
* vr41xx.c
*/
void vr41xx_init(SYSTEM_INFO *info);
/*
* tx39xx.c
*/
void tx39xx_init(SYSTEM_INFO *info);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,111 @@
/* $NetBSD: systeminfo.c,v 1.1 1999/09/26 02:42:51 takemura Exp $ */
/*
* Copyright (c) 1999, by UCHIYAMA Yasushi
* 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. The name of the developer 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 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 AUTHOR 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.
*
*/
#include <pbsdboot.h>
#define PROCESSOR_LEVEL_R4000 4
#define PROCESSOR_LEVEL_R3000 3
#define PROCESSOR_REVMAJOR_VR41XX 0x0c
#define PROCESSOR_REVMAJOR_TX39XX 0x22
struct system_info system_info;
static void dump_archinfo(SYSTEM_INFO*);
int
set_system_info()
{
SYSTEM_INFO info;
/*
* Set machine dependent information.
*/
GetSystemInfo(&info);
switch (info.wProcessorArchitecture) {
default:
dump_archinfo(&info);
return 0;
break;
case PROCESSOR_ARCHITECTURE_MIPS:
switch (info.wProcessorLevel) {
default:
dump_archinfo(&info);
return 0;
break;
case PROCESSOR_LEVEL_R4000:
switch (info.wProcessorRevision >> 8) {
default:
dump_archinfo(&info);
return 0;
break;
case PROCESSOR_REVMAJOR_VR41XX:
vr41xx_init(&info);
break;
}
break;
case PROCESSOR_LEVEL_R3000:
switch (info.wProcessorRevision >> 8) {
default:
dump_archinfo(&info);
return 0;
break;
case PROCESSOR_REVMAJOR_TX39XX:
tx39xx_init(&info);
break;
}
break;
}
break;
case PROCESSOR_ARCHITECTURE_SHx:
dump_archinfo(&info);
return 0;
break;
case PROCESSOR_ARCHITECTURE_ARM:
dump_archinfo(&info);
return 0;
break;
}
if (system_info.si_asmcodelen > (signed)system_info.si_pagesize) {
msg_printf(MSG_ERROR, whoami,
TEXT("asmcodelen=%d > pagesize=%d\n"),
system_info.si_asmcodelen,
system_info.si_pagesize);
return 0;
}
return 1;
}
static void
dump_archinfo(SYSTEM_INFO *info)
{
msg_printf(MSG_ERROR, whoami,
TEXT("Unknown machine ARCHITECTURE %#x, LEVEL %#x REVISION %#x.\n LCD(%dx%d)\n"),
info->wProcessorArchitecture, info->wProcessorLevel,
info->wProcessorRevision,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN));
}

View File

@ -0,0 +1,199 @@
/* $NetBSD: */
/*-
* Copyright (c) 1999 Shin Takemura, UCHIYAMA Yasushi
* All rights reserved.
*
* This software is part of the PocketBSD.
*
* 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 PocketBSD project
* and its contributors.
* 4. Neither the name of the project 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.
*
*/
#include <pbsdboot.h>
extern void tx39xx_asm_code();
extern void tx39xx_asm_code_end();
void tx39xx_asm_code_holder __P((void));
void
tx39xx_init(SYSTEM_INFO *info)
{
/* 4KByte page */
system_info.si_pagesize = info->dwPageSize;
/* DRAM Bank 0/1 physical addr range */
system_info.si_dramstart = 0x04000000;
system_info.si_drammaxsize = 0x04000000;
/* Pointer for bootstrap code */
system_info.si_asmcode = (unsigned char*)tx39xx_asm_code;
system_info.si_asmcodelen = (unsigned char*)tx39xx_asm_code_end
- system_info.si_asmcode;
system_info.si_boot = mips_boot;
}
void
tx39xx_asm_code_holder()
{
/*
* void
* startprog(register struct map_s *map)
* {
* register unsigned char *addr;
* register unsigned char *p;
* register int i;
*
* addr = map->base;
* i = 0;
* while (p = map->leaf[i / map->leafsize][i % map->leafsize]) {
* register unsigned char *pe = p + map->pagesize;
* while (p < pe) {
* *addr++ = *p++;
* }
* i++;
* }
* }
*
* register assignment:
* struct map_s *map a0
* unsigned char *addr a1
* unsigned char *p a2
* unsigned char *pe a3
* int i t0
*
* struct map_s {
* caddr_t entry; +0
* caddr_t base; +4
* int pagesize; +8
* int leafsize; +12
* int nleaves; +16
* caddr_t arg0; +20
* caddr_t arg1; +24
* caddr_t arg2; +28
* caddr_t arg3; +32
* caddr_t *leaf[32]; +36
*
*/
__asm(
" .set noreorder; "
" .globl tx39xx_asm_code;"
"tx39xx_asm_code:"
" lui a0, 0x0000; "
" ori a0, 0x0000; "
/* addr = map->base; */
"lw a1, 4(a0);"
/* i = 0; */
"ori t0, zero, 0;"
" loop_start:"
/* while (p = map->leaf[i / map->leafsize][i % map->leafsize]) { */
/* t1 = map->leafsize */
"lw t1, 12(a0);"
/* lo = i / map->leafsize, hi = i % map->leafsize */
"addu t3, zero, t0;"
"div t3, t1;"
/* t2 = map->leaf */
"addiu t2, a0, 36;"
/* t3 = i / map->leafsize */
"nop;"
"mflo t3;"
/* t2 = map->leaf[i / map->leafsize] */
"sll t3, t3, 2;"
"addu t2, t2, t3;"
"lw t2, 0(t2);"
/* t3 = i % map->leafsize */
"mfhi t3;"
/* p = map->leaf[i / map->leafsize][i % map->leafsize] */
"sll t3, t3, 2;"
"addu t2, t2, t3;"
"lw a2, 0(t2);"
/* if (p == NULL) { */
/* break; */
/* } */
"beq a2, zero, loop_end;"
"nop;"
/* register unsigned char *pe = p + map->pagesize; */
"lw t1, 8(a0);"
"add a3, a2, t1;"
/* while (p < pe) { */
"loop_start2:"
"sltu t1, a2, a3;"
"beq zero,t1,loop_end2;"
"nop;"
/* *addr++ = *p++; */
"lw t1, 0(a2);"
"sw t1, 0(a1);"
"addi a2, a2, 4;"
"addi a1, a1, 4;"
/* } */
"beq zero, zero, loop_start2;"
"nop;"
/* i++; */
"loop_end2:"
"addi t0, t0, 1;"
"beq zero, zero, loop_start;"
"nop;"
" loop_end:"
/*
* Flush D-cache. TX3912 is write-through cache. no need to flush.
*/
#if notyet
/* Flush I-cache */
".space 32768;"
#endif
/* Jump to kernel entry */
"lw t0, 0(a0);" /* entry addr */
"lw a1, 24(a0);" /* arg1 */
"lw a2, 28(a0);" /* arg2 */
"lw a3, 32(a0);" /* arg3 */
"lw a0, 20(a0);" /* arg0 */
"jr t0;"
"nop;"
".globl tx39xx_asm_code_end;"
"tx39xx_asm_code_end: nop;"
".set reorder; "
);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmem.c,v 1.2 1999/09/22 12:49:50 uch Exp $ */
/* $NetBSD: vmem.c,v 1.3 1999/09/26 02:42:52 takemura Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura.
@ -37,10 +37,6 @@
*/
#include <pbsdboot.h>
#define MAX_MEMORY (1024*1024*32) /* 32 MB */
#define MEM_BLOCKS 8
#define MEM_BLOCK_SIZE (1024*1024*4)
struct addr_s {
caddr_t addr;
int in_use;
@ -117,30 +113,18 @@ vmem_exec(caddr_t entry, int argc, char *argv[], struct bootinfo *bi)
debug_printf(TEXT("execute startprog()\n"));
//return (-1);
return (startprog(vtophysaddr((caddr_t)map)));
}
DWORD
getpagesize()
{
static int init = 0;
static SYSTEM_INFO info;
if (!init) {
GetSystemInfo(&info);
init = 1;
}
return (info.dwPageSize);
return ((*system_info.si_boot)(vtophysaddr((caddr_t)map)));
}
caddr_t
vmem_alloc()
{
int i;
int i, pagesize;
struct page_header_s *page;
pagesize = system_info.si_pagesize;
for (i = 0; i < npages; i++) {
page = (struct page_header_s*)&heap[getpagesize() * i];
page = (struct page_header_s*)&heap[pagesize * i];
if (!phys_addrs[i].in_use &&
!(kernel_start <= phys_addrs[i].addr &&
phys_addrs[i].addr < kernel_end)) {
@ -154,10 +138,12 @@ vmem_alloc()
static caddr_t
alloc_kpage(caddr_t phys_addr)
{
int i;
int i, pagesize;
struct page_header_s *page;
pagesize = system_info.si_pagesize;
for (i = 0; i < npages; i++) {
page = (struct page_header_s*)&heap[getpagesize() * i];
page = (struct page_header_s*)&heap[pagesize * i];
if (phys_addrs[i].addr == phys_addr) {
if (phys_addrs[i].in_use) {
debug_printf(TEXT("page %d (phys addr=0x%x) is already in use\n"),
@ -177,14 +163,15 @@ alloc_kpage(caddr_t phys_addr)
caddr_t
vmem_get(caddr_t phys_addr, int *length)
{
int pageno = (phys_addr - kernel_start) / getpagesize();
int offset = (phys_addr - kernel_start) % getpagesize();
int pagesize = system_info.si_pagesize;
int pageno = (phys_addr - kernel_start) / pagesize;
int offset = (phys_addr - kernel_start) % pagesize;
if (map == NULL || pageno < 0 || npages <= pageno) {
return (NULL);
}
if (length) {
*length = getpagesize() - offset;
*length = pagesize - offset;
}
return (map->leaf[pageno / map->leafsize][pageno % map->leafsize] + offset);
}
@ -192,8 +179,8 @@ vmem_get(caddr_t phys_addr, int *length)
caddr_t
vtophysaddr(caddr_t page)
{
int pageno = (page - heap) / getpagesize();
int offset = (page - heap) % getpagesize();
int pageno = (page - heap) / system_info.si_pagesize;
int offset = (page - heap) % system_info.si_pagesize;
if (map == NULL || pageno < 0 || npages <= pageno) {
return (NULL);
@ -204,17 +191,22 @@ vtophysaddr(caddr_t page)
int
vmem_init(caddr_t start, caddr_t end)
{
int i, N, pageno;
#define MEM_BLOCK_SIZE (1024*1024*4) /* must be greater than page size */
int i, m, pageno;
unsigned long magic0;
unsigned long magic1;
int nfounds;
struct page_header_s *page;
long size;
int nleaves;
int pagesize, memblocks;
pagesize = system_info.si_pagesize;
memblocks = (system_info.si_drammaxsize) / MEM_BLOCK_SIZE;
/* align with page size */
start = (caddr_t)(((long)start / getpagesize()) * getpagesize());
end = (caddr_t)((((long)end + getpagesize() - 1) / getpagesize()) * getpagesize());
start = (caddr_t)(((long)start / pagesize) * pagesize);
end = (caddr_t)((((long)end + pagesize - 1) / pagesize) * pagesize);
kernel_start = start;
kernel_end = end;
@ -223,13 +215,13 @@ vmem_init(caddr_t start, caddr_t end)
/*
* program image pages.
*/
npages = (size + getpagesize() - 1) / getpagesize();
npages = (size + pagesize - 1) / pagesize;
/*
* map leaf pages.
* npages plus one for end mark.
*/
npages += (nleaves = ((npages * sizeof(caddr_t) + getpagesize()) / getpagesize()));
npages += (nleaves = ((npages * sizeof(caddr_t) + pagesize) / pagesize));
/*
* map root page, startprg code page, argument page and bootinfo page.
@ -242,7 +234,7 @@ vmem_init(caddr_t start, caddr_t end)
debug_printf(TEXT("allocate %d pages\n"), npages);
heap = (unsigned char*)
VirtualAlloc(0,
npages * getpagesize(),
npages * pagesize,
MEM_COMMIT,
PAGE_READWRITE | PAGE_NOCACHE);
if (heap == NULL) {
@ -273,7 +265,7 @@ vmem_init(caddr_t start, caddr_t end)
debug_printf(TEXT("magic=%08x%08x\n"), magic0, magic1);
for (i = 0; i < npages; i++) {
page = (struct page_header_s*)&heap[getpagesize() * i];
page = (struct page_header_s*)&heap[pagesize * i];
page->magic0 = magic0;
page->pageno = i;
page->magic1 = magic1;
@ -285,30 +277,32 @@ vmem_init(caddr_t start, caddr_t end)
* Scan whole physical memory.
*/
nfounds = 0;
for (N = 0; N < MEM_BLOCKS && nfounds < npages; N++) {
for (m = 0; (m < memblocks) && (nfounds < npages); m++) {
unsigned char* mem;
int res;
mem = (unsigned char*)
VirtualAlloc(0,
MEM_BLOCK_SIZE,
MEM_RESERVE,
PAGE_NOACCESS);
res = VirtualCopy((LPVOID)mem,
//(LPVOID)((0xa0000000 + MEM_BLOCK_SIZE * N) >> 8),
(LPVOID)((0x80000000 + MEM_BLOCK_SIZE * N) >> 8),
MEM_BLOCK_SIZE,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL);
for (i = 0; i < (int)(MEM_BLOCK_SIZE/getpagesize()); i++) {
page = (struct page_header_s*)&mem[getpagesize() * i];
/* Map physical memory block */
mem = (unsigned char*)VirtualAlloc(0, MEM_BLOCK_SIZE,
MEM_RESERVE, PAGE_NOACCESS);
if(!VirtualCopy((LPVOID)mem, (LPVOID)
((system_info.si_dramstart + MEM_BLOCK_SIZE * m) >> 8),
MEM_BLOCK_SIZE,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL)) {
VirtualFree(mem, 0, MEM_RELEASE);
continue;
}
/* Find preliminary allocated pages */
for (i = 0; i < (int)(MEM_BLOCK_SIZE / pagesize); i++) {
page = (struct page_header_s*)&mem[pagesize * i];
if (page->magic0 == magic0 &&
page->magic1 == magic1) {
pageno = page->pageno;
if (0 <= pageno && pageno < npages &&
phys_addrs[pageno].addr == 0) {
phys_addrs[pageno].addr =
(unsigned char*)(0x80000000 + MEM_BLOCK_SIZE * N +
getpagesize() * i);
/* Set kernel virtual addr. XXX mips dependent */
phys_addrs[pageno].addr = (unsigned char*)
((0x80000000 |
system_info.si_dramstart) +
MEM_BLOCK_SIZE * m +
pagesize * i);
page->magic0 = 0;
page->magic1 = 0;
if (npages <= ++nfounds) {
@ -326,7 +320,9 @@ vmem_init(caddr_t start, caddr_t end)
if (nfounds < npages) {
debug_printf(TEXT("lost %d pages\n"), npages - nfounds);
msg_printf(MSG_ERROR, whoami, TEXT("lost %d pages\n"), npages - nfounds);
msg_printf(MSG_ERROR, whoami,
TEXT("lost %d pages (allocated %d pages)\n"),
npages - nfounds, npages);
goto error_cleanup;
}
@ -339,8 +335,8 @@ vmem_init(caddr_t start, caddr_t end)
goto error_cleanup;
}
map->nleaves = nleaves;
map->leafsize = getpagesize() / sizeof(caddr_t);
map->pagesize = getpagesize();
map->leafsize = pagesize / sizeof(caddr_t);
map->pagesize = pagesize;
/*
* allocate leaf pages
@ -356,7 +352,7 @@ vmem_init(caddr_t start, caddr_t end)
/*
* allocate kernel pages
*/
for (i = 0; start < kernel_end; start += getpagesize(), i++) {
for (i = 0; start < kernel_end; start += pagesize, i++) {
caddr_t *leaf = map->leaf[i / map->leafsize];
if ((leaf[i % map->leafsize] = alloc_kpage(start)) == NULL) {
debug_printf(TEXT("can't allocate page 0x%x.\n"), start);
@ -398,7 +394,7 @@ vmem_dump_map()
return;
}
for (addr = kernel_start; addr < kernel_end; addr += getpagesize()) {
for (addr = kernel_start; addr < kernel_end; addr += system_info.si_pagesize) {
page = vmem_get(addr, NULL);
paddr = vtophysaddr(page);
debug_printf(TEXT("%08X: vaddr=%08X paddr=%08X %s\n"),

View File

@ -1,4 +1,4 @@
/* $NetBSD: startprog.c,v 1.3 1999/09/23 08:30:59 takemura Exp $ */
/* $NetBSD: */
/*-
* Copyright (c) 1999 Shin Takemura.
@ -37,107 +37,27 @@
*/
#include <pbsdboot.h>
extern void asm_code();
extern void asm_code_end();
extern void vr41xx_asm_code();
extern void vr41xx_asm_code_end();
void vr41xx_asm_code_holder __P((void));
#if 0
static void clear_screen()
void
vr41xx_init(SYSTEM_INFO *info)
{
unsigned char* mem;
/*
* clear screen
*/
mem = (unsigned char*)VirtualAlloc(
0,
0x4b00,
MEM_RESERVE,
PAGE_NOACCESS);
VirtualCopy(
(LPVOID)mem,
(LPVOID)(0xaa000000 >> 8),
0x4b00,
// PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL);
PAGE_READWRITE | PAGE_PHYSICAL);
memset(mem, 0, 0x4b00);
VirtualFree(mem, 0, MEM_RELEASE);
}
static void flush_data()
{
unsigned char* mem;
mem = (unsigned char*)malloc(0x4000);
memset(mem, 0, 0x4000);
free(mem);
}
#endif
int
startprog(caddr_t map)
{
int i;
unsigned char *mem;
unsigned long jump_instruction, phys_mem;
unsigned char *codep = (unsigned char*)asm_code;
int code_len = (unsigned char*)asm_code_end - codep;
#if 0
clear_screen();
//flush_data();
#endif
/*
* allocate physical memory
*/
if ((mem = (unsigned char*)vmem_alloc()) == NULL) {
debug_printf(TEXT("can't allocate final page.\n"));
msg_printf(MSG_ERROR, whoami, TEXT("can't allocate root page.\n"));
return (-1);
}
/*
* copy startup program code
*/
for (i = 0; i < code_len; i++) {
mem[i] = *codep++;
}
/*
* set map address
*/
*(unsigned short*)&mem[0] = (unsigned short)(((long)map) >> 16);
*(unsigned short*)&mem[4] = (unsigned short)map;
/*
* construct start instruction
*/
phys_mem = (unsigned long)vtophysaddr(mem);
jump_instruction = (0x08000000 | ((phys_mem >> 2) & 0x03ffffff));
/*
* map interrupt vector
*/
mem = (unsigned char*)VirtualAlloc(
0,
0x400,
MEM_RESERVE,
PAGE_NOACCESS);
VirtualCopy(
(LPVOID)mem,
(LPVOID)(0x80000000 >> 8),
0x400,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL);
/*
* GO !
*/
*(unsigned long*)&mem[0x0] = jump_instruction;
return (0); /* not reachable */
/* 1KByte page */
system_info.si_pagesize = info->dwPageSize;
/* DRAM Bank 0/1 physical addr range */
system_info.si_dramstart = 0x80000000;
system_info.si_drammaxsize = 0x08000000;
/* Pointer for bootstrap code */
system_info.si_asmcode = (unsigned char*)vr41xx_asm_code;
system_info.si_asmcodelen = (unsigned char*)vr41xx_asm_code_end
- system_info.si_asmcode;
system_info.si_boot = mips_boot;
}
void
asm_code_holder()
vr41xx_asm_code_holder()
{
/*
* void
@ -184,8 +104,8 @@ asm_code_holder()
*/
__asm(
" .set noreorder; "
" .globl asm_code;"
"asm_code:"
" .globl vr41xx_asm_code;"
"vr41xx_asm_code:"
" lui a0, 0x0000; "
" ori a0, 0x0000; "
@ -305,8 +225,8 @@ __asm(
" jr t0;"
" nop;"
" .globl asm_code_end;"
"asm_code_end: nop;"
" .globl vr41xx_asm_code_end;"
"vr41xx_asm_code_end: nop;"
" .set reorder; "
);
}