0
|
1 /*****************************************************************
|
|
2 * main.c
|
|
3 * by Zhiyi Huang, hzy@cs.otago.ac.nz
|
|
4 * University of Otago
|
|
5 *
|
|
6 ********************************************************************/
|
|
7
|
|
8
|
|
9 #include "types.h"
|
|
10 #include "defs.h"
|
|
11 #include "param.h"
|
|
12 #include "memlayout.h"
|
|
13 #include "mmu.h"
|
|
14 #include "proc.h"
|
|
15 #include "arm.h"
|
|
16 #include "mailbox.h"
|
|
17
|
|
18 extern char end[]; // first address after kernel loaded from ELF file
|
|
19 extern pde_t *kpgdir;
|
|
20 extern volatile uint *mailbuffer;
|
|
21 extern unsigned int pm_size;
|
|
22
|
|
23 void OkLoop()
|
|
24 {
|
|
25 setgpiofunc(18, 1); // gpio 18 for Ok Led, set as an output
|
|
26 while(1){
|
|
27 setgpioval(18, 0);
|
|
28 delay(2000000);
|
|
29 setgpioval(18, 1);
|
|
30 delay(2000000);
|
|
31 }
|
|
32 }
|
|
33
|
|
34 void NotOkLoop()
|
|
35 {
|
|
36 setgpiofunc(18, 1); // gpio 18 for Ok Led, set as an output
|
|
37 while(1){
|
|
38 setgpioval(18, 0);
|
|
39 delay(500000);
|
|
40 setgpioval(18, 1);
|
|
41 delay(500000);
|
|
42 }
|
|
43 }
|
|
44
|
|
45 unsigned int getpmsize()
|
|
46 {
|
|
47 create_request(mailbuffer, MPI_TAG_GET_ARM_MEMORY, 8, 0, 0);
|
|
48 writemailbox((uint *)mailbuffer, 8);
|
|
49 readmailbox(8);
|
|
50 if(mailbuffer[1] != 0x80000000) cprintf("Error readmailbox: %x\n", MPI_TAG_GET_ARM_MEMORY);
|
|
51 return mailbuffer[MB_HEADER_LENGTH + TAG_HEADER_LENGTH+1];
|
|
52 }
|
|
53
|
|
54 void machinit(void)
|
|
55 {
|
|
56 memset(cpus, 0, sizeof(struct cpu)*NCPU);
|
|
57 }
|
|
58
|
|
59
|
|
60 void enableirqminiuart(void);
|
|
61
|
|
62 uint mb_data[10];
|
|
63
|
|
64 int cmain()
|
|
65 {
|
|
66 mmuinit0();
|
|
67 machinit();
|
|
68
|
|
69 #if defined (RPI1) || defined (RPI2)
|
|
70 uartinit();
|
|
71 #elif defined (FVP)
|
|
72 uartinit_fvp();
|
|
73 #endif
|
|
74
|
|
75 dsb_barrier();
|
|
76
|
|
77 consoleinit();
|
|
78 cprintf("\nHello World from xv6\n");
|
|
79
|
|
80 kinit1(end, P2V((8*1024*1024)+PHYSTART));
|
|
81 // collect some free space (8 MB) for imminent use
|
|
82 // the physical space below 0x8000 is reserved for PGDIR and kernel stack
|
|
83 kpgdir=p2v(K_PDX_BASE);
|
|
84
|
|
85 mailboxinit();
|
|
86
|
|
87 pm_size = getpmsize();
|
|
88 cprintf("ARM memory is %x\n", pm_size);
|
|
89
|
|
90 mmuinit1();
|
|
91 gpuinit();
|
|
92 pinit();
|
|
93 tvinit();
|
|
94 cprintf("it is ok after tvinit\n");
|
|
95 binit();
|
|
96 cprintf("it is ok after binit\n");
|
|
97 fileinit();
|
|
98 cprintf("it is ok after fileinit\n");
|
|
99 iinit();
|
|
100 cprintf("it is ok after iinit\n");
|
|
101 ideinit();
|
|
102 cprintf("it is ok after ideinit\n");
|
|
103 kinit2(P2V((8*1024*1024)+PHYSTART), P2V(pm_size));
|
|
104 cprintf("it is ok after kinit2\n");
|
|
105 userinit();
|
|
106 cprintf("it is ok after userinit\n");
|
|
107 timer3init();
|
|
108 cprintf("it is ok after timer3init\n");
|
|
109 scheduler();
|
|
110 NotOkLoop();
|
|
111 return 0;
|
|
112 }
|