annotate source/main.c @ 0:ed10291ff195

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