00001
00007
00008
00015 #include <kernel.h>
00016 #include <platform.h>
00017 #include <proc.h>
00018 #include <queue.h>
00019 #include <semaphore.h>
00020 #include <memory.h>
00021 #include <clock.h>
00022 #include <device.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <mips.h>
00026 #include <gpio.h>
00027
00028
00029 extern void _start(void);
00030 extern void *end;
00031
00032
00033 extern void main(void);
00034 extern void xdone(void);
00035 local platforminit(void);
00036 local sysinit(void);
00037
00038
00039 struct pentry proctab[NPROC];
00040 struct sentry semtab[NSEM];
00041 queue readylist;
00042 struct memblock freelist;
00043
00044
00045 ushort numproc;
00046 ushort currpid;
00047
00048
00049 void *minheap;
00050 ulong cpuid;
00051
00052 struct platform platform;
00053
00064 int nulluser()
00065 {
00066 kprintf(VERSION); kprintf("\r\n\r\n");
00067
00068 platforminit();
00069
00070 #ifdef DETAIL
00071
00072 kprintf("Processor identification: 0x%08X\r\n", cpuid);
00073 kprintf("Detected platform as: %s\r\n\r\n",platform.name);
00074 #endif
00075
00076 sysinit();
00077
00078
00079 kprintf("%10d bytes physical memory.\r\n",
00080 (ulong) platform.maxaddr & 0x7FFFFFFF );
00081 #ifdef DETAIL
00082 kprintf(" [0x%08X to 0x%08X]\r\n",
00083 (ulong) KSEG0_BASE, (ulong) (platform.maxaddr - 1));
00084 #endif
00085 kprintf("%10d bytes reserved system area.\r\n",
00086 (ulong) _start - KSEG0_BASE);
00087 #ifdef DETAIL
00088 kprintf(" [0x%08X to 0x%08X]\r\n",
00089 (ulong) KSEG0_BASE, (ulong) _start - 1);
00090 #endif
00091
00092 kprintf("%10d bytes XINU code.\r\n",
00093 (ulong) &end - (ulong) _start);
00094 #ifdef DETAIL
00095 kprintf(" [0x%08X to 0x%08X]\r\n",
00096 (ulong) _start, (ulong) &end - 1);
00097 #endif
00098
00099 kprintf("%10d bytes stack space.\r\n",
00100 (ulong) minheap - (ulong) &end);
00101 #ifdef DETAIL
00102 kprintf(" [0x%08X to 0x%08X]\r\n",
00103 (ulong) &end, (ulong) minheap - 1);
00104 #endif
00105
00106 kprintf("%10d bytes heap space.\r\n",
00107 (ulong) platform.maxaddr - (ulong) minheap);
00108 #ifdef DETAIL
00109 kprintf(" [0x%08X to 0x%08X]\r\n\r\n",
00110 (ulong) minheap, (ulong) platform.maxaddr - 1);
00111 #endif
00112
00113
00114 enable();
00115
00116 open(CONSOLE, SERIAL0);
00117
00118 ready(create((void *)main, INITSTK, INITPRIO, "MAIN", 2, 0, NULL),
00119 RESCHED_NO);
00120
00121 while(1)
00122 {
00123
00124 if (nonempty(readylist)) { resched(); }
00125
00126 if (numproc <= 1) { xdone(); }
00127 }
00128 }
00129
00134 local sysinit(void)
00135 {
00136 int i;
00137 pcb *ppcb;
00138 device *pdev;
00139 struct sentry *psem;
00140 struct memblock *pmblock;
00141
00142
00143
00144 numproc = 1;
00145
00146 freelist.next = pmblock = (struct memblock *) roundmb(minheap);
00147 freelist.length = (ulong)truncew((ulong)platform.maxaddr - (ulong)minheap);
00148 pmblock->next = NULL;
00149 pmblock->length = (ulong)truncew((ulong)platform.maxaddr - (ulong)minheap);
00150
00151
00152 for (i = 0; i < NPROC; i++)
00153 { proctab[i].state = PRFREE; }
00154
00155
00156 ppcb = &proctab[NULLPROC];
00157 ppcb->state = PRCURR;
00158 ppcb->prio = 0;
00159 strncpy(ppcb->name, "prnull", 7);
00160 ppcb->stkbase = (void *)&end;
00161 ppcb->stklen = (ulong)minheap - (ulong)&end;
00162 ppcb->stkptr = 0;
00163 currpid = NULLPROC;
00164
00165
00166 for (i = 0; i < NSEM; i++)
00167 {
00168 psem = &semtab[i];
00169 psem->state = SFREE;
00170 psem->count = 0;
00171 psem->queue = newqueue();
00172 }
00173
00174
00175 readylist = newqueue();
00176
00177 #ifdef RTCLOCK
00178
00179 clockinit();
00180 #endif
00181
00182 #ifdef NDEVS
00183 for (i = 0; i < NDEVS; i++)
00184 {
00185 if (!isbaddev(i))
00186 {
00187 pdev = &devtab[i];
00188 (pdev->init)(pdev);
00189 }
00190 }
00191 #endif
00192
00193 GPIO_CTRL_LED_ON(GPIO_LED_CISCOWHT);
00194
00195 return OK;
00196 }
00197
00202 local platforminit(void)
00203 {
00204 switch (cpuid & PRID_REV)
00205 {
00206 case PRID_REV_WRT54G:
00207 strncpy(platform.name, "Linksys WRT54G", 16);
00208 platform.maxaddr = (void *) (KSEG0_BASE | MAXADDR_WRT54G);
00209 platform.time_base_freq = TIME_BASE_FREQ_WRT54G;
00210 platform.uart_dll = UART_DLL_WRT54G;
00211 break;
00212 case PRID_REV_WRT54GL:
00213 strncpy(platform.name, "Linksys WRT54GL", 16);
00214 platform.maxaddr = (void *) (KSEG0_BASE | MAXADDR_WRT54GL);
00215 platform.time_base_freq = TIME_BASE_FREQ_WRT54GL;
00216 platform.uart_dll = UART_DLL_WRT54GL;
00217 break;
00218 case PRID_REV_WRT350N:
00219 strncpy(platform.name, "Linksys WRT350N", 16);
00220 platform.maxaddr = (void *) (KSEG0_BASE | MAXADDR_WRT350N);
00221 platform.time_base_freq = TIME_BASE_FREQ_WRT350N;
00222 platform.uart_dll = UART_DLL_WRT350N;
00223 break;
00224 default:
00225 strncpy(platform.name, "Unknown Platform", 16);
00226 platform.maxaddr = (void *) (KSEG0_BASE | MAXADDR_DEFAULT);
00227 platform.time_base_freq = TIME_BASE_FREQ_DEFAULT;
00228 return SYSERR;
00229 }
00230
00231 return OK;
00232 }
00233