OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [common/] [common.c] - Blame information for rev 366

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
#include "common.h"
2
#include "uart.h"
3
#include "screen.h"
4
#include "support.h"
5
#include "keyboard.h"
6 246 julius
#include "spr-defs.h"
7
#include "spincursor.h"
8 2 marcus.erl
#include "int.h"
9
 
10
#include "build.h"
11
 
12
#define MAX_COMMANDS  100
13
 
14 246 julius
// Value from linker script
15 2 marcus.erl
extern unsigned long src_addr;
16
 
17
bd_t bd;
18
 
19
int num_commands = 0;
20
 
21
command_struct command[MAX_COMMANDS];
22
 
23
void putc (const char c)
24
{
25
  debug ("putc %i, %i = %c\n", bd.bi_console_type, c, c);
26
  switch (bd.bi_console_type) {
27
  case CT_NONE:
28
    break;
29
  case CT_UART:
30
    uart_putc (c);
31
    break;
32 140 julius
#if CRT_ENABLED==1
33 2 marcus.erl
  case CT_CRT:
34
    screen_putc (c);
35
    break;
36 140 julius
#endif
37 2 marcus.erl
  case CT_SIM:
38
    __printf ("%c", c);
39
    break;
40
  }
41
}
42
 
43
int getc ()
44
{
45
  int ch = 0;
46
  debug ("getc %i\n", bd.bi_console_type);
47
  switch (bd.bi_console_type) {
48 140 julius
#if KBD_ENABLED==1
49 2 marcus.erl
  case CT_CRT:
50
    while ((volatile int)kbd_head == (volatile int)kbd_tail);
51
    ch = kbd_buf[kbd_tail];
52
    kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE;
53
    return ch;
54
#endif
55
  case CT_UART:
56
    return uart_getc ();
57
    break;
58
  case CT_NONE: /* just to satisfy the compiler */
59
  case CT_SIM:
60
    break;
61
  }
62
  return -1;
63
}
64
 
65
int testc ()
66
{
67
  debug ("testc %i\n", bd.bi_console_type);
68
  switch (bd.bi_console_type) {
69
#if KBD_ENABLED
70
  case CT_CRT:
71
    if (kbd_head == kbd_tail) return 0;
72
    else return getc ();
73
#endif
74
  case CT_UART:
75
    return uart_testc ();
76
    break;
77
  case CT_NONE: /* just to satisfy the compiler */
78
  case CT_SIM:
79
    break;
80
  }
81
  return -1;
82
}
83
 
84
int ctrlc ()
85
{
86
  if (testc ()) {
87
    switch (getc ()) {
88
      case 0x03:    /* ^C - Control C */
89
        return 1;
90
      default:
91
        break;
92
    }
93
  }
94
  return 0;
95
}
96
 
97 246 julius
void
98
print_or1k_cache_info()
99
{
100
  // Read out UPR, check what modules we have
101
  unsigned long upr = mfspr(SPR_UPR);
102
  printf("Instruction cache:\t");
103
  if (upr & SPR_UPR_ICP)
104
    {
105
      // We have instruction cache, read out ICCFGR
106
 
107
      unsigned long iccfgr = mfspr(SPR_ICCFGR);
108
      unsigned int cbs; // cache block size
109
      unsigned long ncs = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
110
      if (iccfgr & SPR_ICCFGR_CBS)
111
        cbs = 32;
112
      else
113
        cbs = 16;
114
 
115
      printf("%dkB (BS: %d Sets: %d)\n",
116
             (cbs * ncs)/1024, cbs, ncs);
117
 
118
    }
119
  else
120
    printf(" not present\n");
121
 
122
  printf("Data cache:\t\t");
123
  if (upr & SPR_UPR_DCP)
124
    {
125
      // We have instruction cache, read out DCCFGR
126
 
127
      unsigned long iccfgr = mfspr(SPR_DCCFGR);
128
      unsigned int cbs; // cache block size
129
      unsigned long ncs = 1 << ((iccfgr & SPR_DCCFGR_NCS) >> 3);
130
      if (iccfgr & SPR_DCCFGR_CBS)
131
        cbs = 32;
132
      else
133
        cbs = 16;
134
 
135
      printf("%dkB (BS: %d Sets: %d)\n",
136
             (cbs * ncs)/1024, cbs, ncs);
137
 
138
    }
139
  else
140
    printf(" not present\n");
141
 
142
}
143
 
144 2 marcus.erl
unsigned long parse_ip (char *ip)
145
{
146
  unsigned long num;
147
  num = strtoul (ip, &ip, 10) & 0xff;
148
  if (*ip++ != '.') return 0;
149
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
150
  if (*ip++ != '.') return 0;
151
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
152
  if (*ip++ != '.') return 0;
153
  num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff);
154
  return num;
155
}
156
 
157
void change_console_type (enum bi_console_type_t con_type)
158
{
159
  debug ("Console change %i -> %i\n", bd.bi_console_type, con_type);
160
  /* Close previous */
161
  switch (bd.bi_console_type) {
162
  case CT_NONE:
163
  case CT_UART:
164
  case CT_CRT:
165
  case CT_SIM:
166
    break;
167
  }
168
  bd.bi_console_type = con_type;
169
  /* Initialize new */
170
  switch (bd.bi_console_type) {
171
  case CT_NONE:
172
    break;
173
  case CT_UART:
174
    uart_init ();
175
    break;
176
  case CT_CRT:
177 140 julius
#if CRT_ENABLED==1
178 2 marcus.erl
    screen_init ();
179
#endif
180
#if KBD_ENABLED
181
    kbd_init ();
182
#endif
183
    break;
184
  case CT_SIM:
185
    break;
186
  }
187
}
188
 
189
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]))
190
{
191
  debug ("register_command '%s'\n", name);
192
  if (num_commands < MAX_COMMANDS) {
193
    command[num_commands].name = name;
194
    command[num_commands].params = params;
195
    command[num_commands].help = help;
196
    command[num_commands].func = func;
197
    num_commands++;
198
  } else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name);
199
}
200
 
201
/* Process command and arguments by executing
202
   specific function. */
203
void mon_command(void)
204
{
205
  char c = '\0';
206
  char str[1000];
207
  char *pstr = str;
208
  char *command_str;
209
  char *argv[20];
210
  int argc = 0;
211 246 julius
  int chcnt = 0;
212 2 marcus.erl
 
213
  /* Show prompt */
214
  printf ("\n" BOARD_DEF_NAME"> ");
215
 
216 246 julius
  while(1)
217
    {
218
      c=getc();
219
      if (c == '\r' || c == '\f' || c == '\n')
220
        {
221
          // Mark end of string
222
          *pstr = '\0';
223
          putc('\n');
224
          break;
225
        }
226
      else if (c == '\b') // Backspace
227
        {
228
          if (chcnt > 0)
229
            {
230
              putc(c);
231
              putc(' '); // cover char with space
232
              putc(c);
233
              pstr--;
234
              chcnt--;
235
            }
236
        }
237
      else
238
        {
239
          putc(c);
240
          *pstr++ = c;
241
          chcnt++;
242
        }
243
    }
244 2 marcus.erl
 
245
  /* Skip leading blanks */
246
  pstr = str;
247
  while (*pstr == ' ' && *pstr != '\0') pstr++;
248
 
249
  /* Get command from the string */
250
  command_str = pstr;
251
 
252
  while (1) {
253
    /* Go to next argument */
254
    while (*pstr != ' ' && *pstr != '\0') pstr++;
255
    if (*pstr) {
256
      *pstr++ = '\0';
257
      while (*pstr == ' ') pstr++;
258
      argv[argc++] = pstr;
259
    }
260
    else
261
      break;
262
  }
263
 
264
  {
265
    int i, found = 0;
266
 
267
    for (i = 0; i < num_commands; i++)
268
      if (strcmp (command_str, command[i].name) == 0)
269
      {
270
        switch ( command[i].func(argc, &argv[0]) )
271
        {
272
          case -1:
273 246 julius
            printf ("Missing/wrong parameters, usage: %s %s\n",
274
                    command[i].name, command[i].params);
275 2 marcus.erl
            break;
276
        }
277
 
278
        found++;
279
        break;
280
      }
281
    /* 'built-in' build command */
282
    if(strcmp(command_str, "build") == 0) {
283
      printf("Build tag: %s", BUILD_VERSION);
284
      found++;
285
    }
286
    if (!found)
287
      printf ("Unknown command. Type 'help' for help.\n");
288
  }
289
 
290
}
291
 
292
#if HELP_ENABLED
293 246 julius
extern unsigned long src_addr; // Stack section ends here, will print it out
294 2 marcus.erl
/* Displays help screen */
295
int help_cmd (int argc, char *argv[])
296
{
297
  int i;
298
  for (i = 0; i < num_commands; i++)
299
    printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help);
300 140 julius
 
301
  // Build info....
302
  printf("\n");
303 246 julius
  printf("CPU info\n");
304
  printf("Frequency\t\t%dMHz\n", IN_CLK/1000000);
305
  print_or1k_cache_info();
306
  printf("\n");
307 140 julius
  printf("Info: Stack section addr 0x%x\n",(unsigned long) &src_addr);
308
  printf("Build tag: %s", BUILD_VERSION);
309
 
310 2 marcus.erl
  return 0;
311
}
312
#endif /* HELP_ENABLED */
313
 
314
void module_cpu_init (void);
315
void module_memory_init (void);
316
void module_eth_init (void);
317
void module_dhry_init (void);
318 355 julius
void module_coremark_init (void);
319 2 marcus.erl
void module_camera_init (void);
320
void module_load_init (void);
321
void tick_init(void);
322
void module_touch_init (void);
323
void module_ata_init (void);
324
void module_hdbug_init (void);
325
 
326
 
327
/* List of all initializations */
328
void mon_init (void)
329
{
330
  /* Set defaults */
331
  global.erase_method = 2; /* as needed */
332
  global.src_addr = (unsigned long)&src_addr;
333
  global.dst_addr = FLASH_BASE_ADDR;
334
  global.eth_add[0] = ETH_MACADDR0;
335
  global.eth_add[1] = ETH_MACADDR1;
336
  global.eth_add[2] = ETH_MACADDR2;
337
  global.eth_add[3] = ETH_MACADDR3;
338
  global.eth_add[4] = ETH_MACADDR4;
339
  global.eth_add[5] = ETH_MACADDR5;
340
  global.ip = BOARD_DEF_IP;
341
  global.gw_ip = BOARD_DEF_GW;
342
  global.mask = BOARD_DEF_MASK;
343 140 julius
 
344
#define CPU_CMDS
345
#define MEM_CMDS
346
#define DHRY_CMDS
347 355 julius
#define COREMARK_CMDS
348 140 julius
  //#define CAMERA_CMDS
349
#define LOAD_CMDS
350
    //#define TOUCHSCREEN_CMDS
351
    //#define ATA_CMDS
352
    //#define HDBUG_CMDS
353
#define TICK_CMDS
354
#define ETH_CMDS
355
#define LOAD_CMDS
356 2 marcus.erl
 
357
  /* Init modules */
358 140 julius
#ifdef CPU_CMDS
359 2 marcus.erl
  module_cpu_init ();
360 140 julius
#endif
361
#ifdef MEM_CMDS
362 2 marcus.erl
  module_memory_init ();
363 140 julius
#endif
364
#ifdef ETH_CMDS
365 2 marcus.erl
  module_eth_init ();
366 140 julius
#endif
367
#ifdef DHRY_CMDS
368 2 marcus.erl
  module_dhry_init ();
369 140 julius
#endif
370 355 julius
#ifdef COREMARK_CMDS
371
  module_coremark_init ();
372
#endif
373 140 julius
#ifdef CAMERA_CMDS
374 2 marcus.erl
  module_camera_init ();
375 140 julius
#endif
376
#ifdef LOAD_CMDS
377 2 marcus.erl
  module_load_init ();
378 140 julius
#endif
379
#ifdef TOUCHSCREEN_CMDS
380 2 marcus.erl
  module_touch_init ();
381 140 julius
#endif
382
#ifdef ATA_CMDS
383 2 marcus.erl
  module_ata_init ();
384 140 julius
#endif
385
#ifdef HDBUG_CMDS
386 2 marcus.erl
  module_hdbug_init ();
387 140 julius
#endif
388 2 marcus.erl
 
389 246 julius
#ifdef TICK_CMDS
390
#endif
391 140 julius
 
392 2 marcus.erl
}
393 140 julius
int tboot_cmd (int argc, char *argv[]);
394 2 marcus.erl
/* Main shell loop */
395
int main(int argc, char **argv)
396
{
397
  extern unsigned long calc_mycrc32 (void);
398 246 julius
 
399 2 marcus.erl
#if 0
400
  extern unsigned long mycrc32, mysize;
401
#endif
402 246 julius
 
403 140 julius
  timestamp = 0; // clear timer counter
404 2 marcus.erl
 
405
  int_init ();
406 246 julius
 
407 2 marcus.erl
  change_console_type (CONSOLE_TYPE);
408 246 julius
 
409 2 marcus.erl
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
410
 
411
#if SELF_CHECK
412
  printf ("Self check... ");
413
  if ((t = calc_mycrc32 ()))
414
      printf ("FAILED!!!\n");
415
  else
416
      printf ("OK\n");
417
#endif /* SELF_CHECK */
418 246 julius
 
419 140 julius
  num_commands=0;
420 2 marcus.erl
  mon_init ();
421
 
422 246 julius
  disable_spincursor();
423
 
424
  tick_init();
425
 
426
 
427 2 marcus.erl
  if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd);
428
 
429 140 julius
  printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n");
430
  printf("\tbuild: %s", BUILD_VERSION);
431 2 marcus.erl
 
432 246 julius
  // Loop forever, accepting commands
433
  while(1)
434
    {
435
      mon_command();
436
    }
437
 
438 2 marcus.erl
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.