Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 34 files changed
  • 0 comments
  • 1 contributor

Showing 34 changed files with 756 additions and 41 deletions. Show diff stats Hide diff stats

  1. 2  etc/etc.milkymist/MAKEDEV.conf
  2. 10  etc/etc.milkymist/Makefile.inc
  3. 11  etc/etc.milkymist/ttys
  4. 6  sys/arch/lm32/conf/files.lm32
  5. 27  sys/arch/lm32/include/cpu.h
  6. 3  sys/arch/lm32/include/cpu_counter.h
  7. 6  sys/arch/lm32/include/frame.h
  8. 12  sys/arch/lm32/include/intr.h
  9. 9  sys/arch/lm32/include/proc.h
  10. 1  sys/arch/lm32/include/reg.h
  11. 6  sys/arch/lm32/lm32/copy.c
  12. 48  sys/arch/lm32/lm32/cpu.c
  13. 58  sys/arch/lm32/lm32/interrupt.c
  14. 29  sys/arch/lm32/lm32/locore_subr.S
  15. 36  sys/arch/lm32/lm32/process_machdep.c
  16. 24  sys/arch/lm32/lm32/syscall.c
  17. 2  sys/arch/milkymist/conf/GENERIC
  18. 4  sys/arch/milkymist/conf/files.milkymist
  19. 6  sys/arch/milkymist/conf/majors.milkymist
  20. 5  sys/arch/milkymist/conf/std.milkymist
  21. 25  sys/arch/milkymist/dev/timer.c
  22. 77  sys/arch/milkymist/dev/uart.c
  23. 31  sys/arch/milkymist/include/autoconf.h
  24. 24  sys/arch/milkymist/include/csr.h
  25. 10  sys/arch/milkymist/include/intr.h
  26. 18  sys/arch/milkymist/include/irqhandler.h
  27. 6  sys/arch/milkymist/include/uart.h
  28. 56  sys/arch/milkymist/milkymist/autoconf.c
  29. 117  sys/arch/milkymist/milkymist/clock.c
  30. 11  sys/arch/milkymist/milkymist/intr.c
  31. 4  sys/arch/milkymist/milkymist/locore.s
  32. 26  sys/arch/milkymist/milkymist/machdep.c
  33. 72  sys/arch/milkymist/milkymist/mainbus.c
  34. 15  sys/arch/milkymist/milkymist/sys_machdep.c
2  etc/etc.milkymist/MAKEDEV.conf
... ...
@@ -0,0 +1,2 @@
  1
+# $NetBSD: MAKEDEV.conf,v 1.11 2011/09/06 14:40:10 apb Exp $
  2
+
10  etc/etc.milkymist/Makefile.inc
... ...
@@ -0,0 +1,10 @@
  1
+#	$NetBSD: Makefile.inc,v 1.27 2012/07/09 18:12:11 ysionneau Exp $
  2
+#
  3
+#	etc.milkymist/Makefile.inc -- milkymist-specific etc Makefile targets
  4
+#
  5
+
  6
+# If you change the list of distributed kernels, don't forget
  7
+# to update the release documentation in distrib/notes/common/contents
  8
+
  9
+KERNEL_SETS=		GENERIC
  10
+
11  etc/etc.milkymist/ttys
... ...
@@ -0,0 +1,11 @@
  1
+#
  2
+#	$NetBSD: ttys,v 1.24 2012/06/13 20:49:12 martin Exp $
  3
+#
  4
+#	from: @(#)ttys	5.1 (Berkeley) 4/17/89
  5
+#
  6
+# name	getty				type	status		comments
  7
+#
  8
+# If the console is marked insecure, single-user requires
  9
+# the root password.
  10
+console	"/usr/libexec/getty Pc"		wsvt25	on secure 
  11
+constty	"/usr/libexec/getty Pc"		wsvt25	off secure 
6  sys/arch/lm32/conf/files.lm32
@@ -2,4 +2,10 @@ include "arch/lm32/conf/majors.lm32"
2 2
 
3 3
 file 	arch/lm32/lm32/pmap.c
4 4
 file 	arch/lm32/lm32/copy.c
  5
+file	arch/lm32/lm32/cpu.c
  6
+file	arch/lm32/lm32/syscall.c
  7
+file	arch/lm32/lm32/process_machdep.c
  8
+file	arch/lm32/lm32/interrupt.c
5 9
 file    arch/lm32/lm32/lock_stubs.S
  10
+file	arch/lm32/lm32/locore_subr.S
  11
+file	dev/cons.c
27  sys/arch/lm32/include/cpu.h
@@ -182,8 +182,6 @@ extern struct cpu_info cpu_info_store;
182 182
 #define CPU_STOP(_ci)	        	((_ci)->ci_func->stop(_ci))
183 183
 #define CPU_START_CLEANUP(_ci)		((_ci)->ci_func->cleanup(_ci))
184 184
 
185  
-#define aston(l, why)		((l)->l_md.md_astpending |= (why))
186  
-
187 185
 void cpu_boot_secondary_processors(void);
188 186
 void cpu_init_idle_lwps(void);
189 187
 void cpu_init_msrs(struct cpu_info *, bool);
@@ -206,13 +204,16 @@ struct clockframe {
206 204
 #define CLKF_USERMODE(framep) (0)
207 205
 #define CLKF_PC(framep) ((framep)->tf_pc)
208 206
 #define CLKF_INTR(framep) (0)
  207
+#define	aston(l)		do { (l)->l_md.md_astpending = 1; } while(0)
209 208
 
210  
-/*
211  
- * Give a profiling tick to the current process when the user profiling
212  
- * buffer pages are invalid.  On the i386, request an ast to send us
213  
- * through trap(), marking the proc as needing a profiling tick.
214  
- */
215  
-extern void	cpu_need_proftick(struct lwp *l);
  209
+#define cpu_need_proftick(l)      do { (l)->l_pflag |= LP_OWEUPC; aston(l); } while (0)
  210
+
  211
+#define	cpu_need_resched(ci, flags)					\
  212
+do {									\
  213
+	ci->ci_want_resched = 1;					\
  214
+	if (curlwp != ci->ci_data.cpu_idlelwp)				\
  215
+		aston(curlwp);						\
  216
+} while (/*CONSTCOND*/0)
216 217
 
217 218
 /*
218 219
  * Notify the LWP l that it has a signal pending, process as soon as
@@ -223,18 +224,18 @@ extern void	cpu_signotify(struct lwp *);
223 224
 /*
224 225
  * We need a machine-independent name for this.
225 226
  */
226  
-extern void (*delay_func)(unsigned int);
  227
+void delay_func(unsigned int);
227 228
 struct timeval;
228 229
 
229  
-#define	DELAY(x)		(*delay_func)(x)
230  
-#define delay(x)		(*delay_func)(x)
  230
+#define	DELAY(x)		delay_func(x)
  231
+#define delay(x)		delay_func(x)
231 232
 
232 233
 extern int cputype;
233 234
 extern int cpuid_level;
234 235
 extern int cpu_class;
235 236
 
236  
-extern void (*lm32_cpu_idle)(void);
237  
-#define	cpu_idle() (*lm32_cpu_idle)()
  237
+void lm32_cpu_idle(void);
  238
+#define	cpu_idle() lm32_cpu_idle()
238 239
 
239 240
 /* machdep.c */
240 241
 void	dumpconf(void);
3  sys/arch/lm32/include/cpu_counter.h
@@ -38,7 +38,8 @@ uint64_t	cpu_counter(void);
38 38
 uint64_t	cpu_counter_serializing(void);
39 39
 uint32_t	cpu_counter32(void);
40 40
 uint64_t	cpu_frequency(struct cpu_info *);
41  
-int		cpu_hascounter(void);
  41
+//int		cpu_hascounter(void);
  42
+#define		cpu_hascounter()	(0)
42 43
 
43 44
 #endif	/* _KERNEL */
44 45
 
6  sys/arch/lm32/include/frame.h
@@ -71,6 +71,8 @@
71 71
 #include <lm32/signal.h>
72 72
 #include <sys/ucontext.h>
73 73
 #include <sys/siginfo.h>
  74
+#include <lm32/reg.h>
  75
+
74 76
 /*
75 77
  * New-style signal frame
76 78
  */
@@ -83,7 +85,9 @@ struct sigframe_siginfo {
83 85
 	ucontext_t	sf_uc;		/* actual saved ucontext */
84 86
 };
85 87
 
86  
-
  88
+struct trapframe {
  89
+	struct reg tf_regs;
  90
+};
87 91
 
88 92
 void *getframe(struct lwp *, int, int *);
89 93
 void buildcontext(struct lwp *, int, void *, void *);
12  sys/arch/lm32/include/intr.h
@@ -33,5 +33,17 @@ static __inline void _set_irq_mask(int mask)
33 33
 	__asm volatile ("wcsr IM, %0" :: "r"(mask) : );
34 34
 }
35 35
 
  36
+static __inline void _ack_irq(unsigned int irq)
  37
+{
  38
+	unsigned int __ip;
  39
+	asm volatile("rcsr %0, IP\n\t"
  40
+		     "or %0, %0, %1\n\t"
  41
+		     "wcsr IP, %0" : "=&r"(__ip) : "r"(irq) : );
  42
+}
  43
+
  44
+void lm32_intrhandler_register(int irqmask, int (*func)(void *));
  45
+void init_irqhandlers_array(void);
  46
+unsigned int lm32_dispatch_irq(unsigned int irq_pending_mask, void *arg);
  47
+
36 48
 #endif
37 49
 #endif
9  sys/arch/lm32/include/proc.h
@@ -40,7 +40,7 @@
40 40
 struct mdlwp {
41 41
 	volatile int md_flags;
42 42
 	volatile int md_astpending;
43  
-	struct trapframe *md_utf;		/* user trampframe */
  43
+	struct trapframe md_utf;		/* user trampframe */
44 44
 };
45 45
 
46 46
 struct trapframe;
@@ -53,7 +53,12 @@ struct mdproc {
53 53
 //#define	LWP0_CPU_INFO	&cpu_info[0] 
54 54
 #define	LWP0_MD_INITIALIZER {	\
55 55
 		.md_flags = 0, \
56  
-		.md_utf = (void *)0xdeadbeef, \
  56
+		.md_utf = { \
  57
+			.tf_regs = { .r_regs = { 0 }, \
  58
+				.r_ra = 0, \
  59
+				.r_ea = 0, \
  60
+				.r_ba = 0, \
  61
+				.r_pc = 0} } \
57 62
 	}
58 63
 #endif /* _KERNEL */
59 64
 
1  sys/arch/lm32/include/reg.h
@@ -49,6 +49,7 @@ struct reg {
49 49
 	int	r_ra;
50 50
 	int	r_ea;
51 51
 	int 	r_ba;
  52
+	int	r_pc;
52 53
 };
53 54
 
54 55
 /*
6  sys/arch/lm32/lm32/copy.c
@@ -185,3 +185,9 @@ int copystr(const void *kfaddr, void *kdaddr, size_t maxlen, size_t *done)
185 185
 
186 186
 	return ret;
187 187
 }
  188
+
  189
+int copyoutstr(const void *from, void *to, size_t maxlen, size_t *done)
  190
+{
  191
+	return 0;
  192
+	//TODO
  193
+}
48  sys/arch/lm32/lm32/cpu.c
... ...
@@ -0,0 +1,48 @@
  1
+#include <lm32/cpu.h>
  2
+#include <sys/cpu.h>
  3
+#include <lm32/reg.h>
  4
+#include <sys/exec.h>
  5
+
  6
+void
  7
+cpu_intr_redistribute(void)
  8
+{
  9
+
  10
+	/* XXX nothing */
  11
+}
  12
+
  13
+u_int cpu_intr_count(struct cpu_info *ci)
  14
+{
  15
+	return ci->ci_nintrhand;
  16
+}
  17
+
  18
+void cpu_offline_md(void)
  19
+{
  20
+	/* XXX nothing */
  21
+}
  22
+
  23
+
  24
+/*
  25
+ * Clear registers on exec
  26
+ */
  27
+void
  28
+setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
  29
+{
  30
+//	struct pmap *pmap = vm_map_pmap(&l->l_proc->p_vmspace->vm_map);
  31
+	struct reg *regs;
  32
+	int i;
  33
+
  34
+	regs = &l->l_md.md_utf.tf_regs;
  35
+	for (i = R1 ; i <= R27 ; i++)
  36
+		regs->r_regs[i] = 0;
  37
+
  38
+	regs->r_pc = pack->ep_entry;
  39
+	regs->r_regs[R28] = stack; // R28: stack pointer
  40
+}
  41
+
  42
+
  43
+//TODO: use Milkymist SoC timer to provide more precise delay function?
  44
+void delay_func(unsigned int n)
  45
+{
  46
+	unsigned int i = n;
  47
+	while(i-- > 0);
  48
+}
58  sys/arch/lm32/lm32/interrupt.c
... ...
@@ -0,0 +1,58 @@
  1
+/*
  2
+ * COPYRIGHT (C) 2013 Yann Sionneau <yann.sionneau@gmail.com>
  3
+ */
  4
+
  5
+#include <lib/libkern/libkern.h>
  6
+#include <machine/psl.h>
  7
+
  8
+struct irqhandler {
  9
+	unsigned int mask;
  10
+	int (*irq_handler)(void *);
  11
+};
  12
+
  13
+struct irqhandler irqhandlers[32];
  14
+
  15
+void init_irqhandlers_array(void)
  16
+{
  17
+	memset(irqhandlers, 0, sizeof(irqhandlers));
  18
+}
  19
+
  20
+unsigned int lm32_dispatch_irq(unsigned int irq_pending_mask, void *arg)
  21
+{
  22
+	unsigned int i;
  23
+	int s;
  24
+
  25
+	for (i = 0 ; i < 32 ; i++)
  26
+	{
  27
+		if ((irq_pending_mask & irqhandlers[i].mask)
  28
+		    && (irqhandlers[i].irq_handler != NULL))
  29
+		{
  30
+			s = spl0();
  31
+			if (irqhandlers[i].irq_handler(arg))
  32
+			{
  33
+				splx(s);
  34
+				return 1;
  35
+			}
  36
+			splx(s);
  37
+		}
  38
+	}
  39
+
  40
+	printf("spurious IRQ or no handler registered for this IRQ: IP == 0x%08X\n", irq_pending_mask);
  41
+	return 0;
  42
+}
  43
+
  44
+void lm32_intrhandler_register(int irqmask, int (*func)(void *))
  45
+{
  46
+	unsigned int i;
  47
+	for (i = 0 ; i < 32 ; i++)
  48
+	{
  49
+		if (irqhandlers[i].irq_handler == NULL)
  50
+		{
  51
+			irqhandlers[i].mask = irqmask;
  52
+			irqhandlers[i].irq_handler = func;
  53
+			return;
  54
+		}
  55
+	}
  56
+
  57
+	panic("No more slot to register irq handler\n");
  58
+}
29  sys/arch/lm32/lm32/locore_subr.S
... ...
@@ -0,0 +1,29 @@
  1
+/*
  2
+ * COPYRIGHT (C) 2013 Yann Sionneau <yann.sionneau@gmail.com>
  3
+ */
  4
+
  5
+#include <lm32/asm.h>
  6
+
  7
+// TODO: implement suword
  8
+ENTRY(suword)
  9
+
  10
+// TODO: implement susword
  11
+ENTRY(susword)
  12
+
  13
+// TODO: implement suswintr
  14
+ENTRY(suswintr)
  15
+
  16
+// TODO: implement subyte
  17
+ENTRY(subyte)
  18
+
  19
+// TODO: implement fuswintr
  20
+ENTRY(fuswintr)
  21
+
  22
+// TODO: implement kcopy
  23
+ENTRY(kcopy)
  24
+
  25
+// TODO: implement setjmp
  26
+ENTRY(setjmp)
  27
+
  28
+// TODO: implement longjmp
  29
+ENTRY(longjmp)
36  sys/arch/lm32/lm32/process_machdep.c
... ...
@@ -0,0 +1,36 @@
  1
+#include <sys/param.h>
  2
+#include <sys/cdefs.h>
  3
+#include <sys/cpu.h>
  4
+#include <sys/proc.h>
  5
+#include <sys/ptrace.h>
  6
+#include <sys/systm.h>
  7
+
  8
+#include <uvm/uvm_extern.h>
  9
+
  10
+#include <lm32/pcb.h>
  11
+#include <lm32/psl.h>
  12
+#include <lm32/reg.h>
  13
+
  14
+int
  15
+process_set_pc(struct lwp *l, void *addr)
  16
+{
  17
+	return 0;
  18
+}
  19
+
  20
+int
  21
+process_sstep(struct lwp *l, int sstep)
  22
+{
  23
+	return 0;
  24
+}
  25
+
  26
+int
  27
+process_read_regs(struct lwp *l, struct reg *regs)
  28
+{
  29
+	return 0;
  30
+}
  31
+
  32
+int
  33
+process_write_regs(struct lwp *l, const struct reg *regs)
  34
+{
  35
+	return 0;
  36
+}
24  sys/arch/lm32/lm32/syscall.c
... ...
@@ -0,0 +1,24 @@
  1
+#include <sys/param.h>
  2
+#include <sys/cpu.h>
  3
+#include <sys/ktrace.h>
  4
+#include <sys/proc.h>
  5
+#include <sys/reboot.h>
  6
+#include <sys/systm.h>
  7
+#include <sys/syscallvar.h>
  8
+#include <sys/syscall.h>
  9
+
  10
+#include <uvm/uvm_extern.h>
  11
+
  12
+#include <lm32/frame.h>
  13
+#include <lm32/pcb.h>
  14
+#include <lm32/reg.h>
  15
+
  16
+void
  17
+child_return(void *arg)
  18
+{
  19
+	struct lwp * const l = arg;
  20
+	struct trapframe * const tf = &l->l_md.md_utf;
  21
+
  22
+	tf->tf_regs.r_regs[R1] = 0; // set return value to 0 as the result of fork() for the child
  23
+	ktrsysret(SYS_fork, 0, 0);
  24
+}
2  sys/arch/milkymist/conf/GENERIC
@@ -10,4 +10,6 @@ file-system PTYFS
10 10
 file-system KERNFS
11 11
 file-system FDESC
12 12
 
  13
+pseudo-device	pty			# pseudo-terminals
  14
+
13 15
 config netbsd root on ? type ?
4  sys/arch/milkymist/conf/files.milkymist
@@ -7,6 +7,7 @@ maxusers 2 8 64
7 7
 
8 8
 device	mainbus {}
9 9
 attach	mainbus at root
  10
+file	arch/milkymist/milkymist/mainbus.c
10 11
 
11 12
 device	cpu
12 13
 attach	cpu at mainbus
@@ -23,5 +24,8 @@ file	arch/milkymist/dev/uart.c		uart needs-flag
23 24
 
24 25
 file	arch/milkymist/milkymist/intr.c
25 26
 file	arch/milkymist/milkymist/machdep.c
  27
+file 	arch/milkymist/milkymist/sys_machdep.c
  28
+file	arch/milkymist/milkymist/autoconf.c
  29
+file	arch/milkymist/milkymist/clock.c
26 30
 
27 31
 include "arch/milkymist/conf/majors.milkymist"
6  sys/arch/milkymist/conf/majors.milkymist
... ...
@@ -1 +1,5 @@
1  
-device-major mem char 2
  1
+device-major	cons		char 0
  2
+device-major	mem		char 1
  3
+device-major	pts		char 2			pty
  4
+device-major	ptc		char 3			pty
  5
+device-major	swap		char 4	block 1		vmswap
5  sys/arch/milkymist/conf/std.milkymist
... ...
@@ -1,5 +1,8 @@
1  
-machine milkymist lm32
  1
+# $NetBSD: std.lm32,v 1.33 2012/09/27 18:28:55 ysionneau Exp $
  2
+#
  3
+# standard, required NetBSD/milkymist 'options'
2 4
 
  5
+machine milkymist lm32
3 6
 include		"conf/std"			# MI standard options
4 7
 include		"arch/lm32/conf/std.lm32"	# lm32 standard options
5 8
 
25  sys/arch/milkymist/dev/timer.c
... ...
@@ -0,0 +1,25 @@
  1
+#include <sys/cdefs.h>
  2
+__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.11 2010/11/21 18:53:56 ysionneau Exp $");
  3
+
  4
+#include <sys/param.h>
  5
+#include <sys/systm.h>
  6
+#include <sys/device.h>
  7
+#include <machine/autoconf.h>
  8
+
  9
+static int timer_match(device_t, cfdata_t, void*);
  10
+static void timer_attach(device_t, device_t, void *);
  11
+
  12
+CFATTACH_DECL_NEW(timer, 0,
  13
+    timer_match, timer_attach, NULL, NULL);
  14
+
  15
+int
  16
+timer_match(device_t parent, cfdata_t cf, void *aux)
  17
+{
  18
+	return 1;
  19
+}
  20
+
  21
+void
  22
+timer_attach(device_t parent, device_t self, void *aux)
  23
+{
  24
+	aprint_normal("\n");
  25
+}
77  sys/arch/milkymist/dev/uart.c
... ...
@@ -0,0 +1,77 @@
  1
+#include <sys/cdefs.h>
  2
+__KERNEL_RCSID(0, "$NetBSD: uart.c,v 1.11 2010/11/21 18:53:56 ysionneau Exp $");
  3
+
  4
+#include <sys/param.h>
  5
+#include <sys/systm.h>
  6
+#include <sys/device.h>
  7
+
  8
+#include <dev/cons.h>
  9
+
  10
+#include <machine/autoconf.h>
  11
+#include <machine/uart.h>
  12
+
  13
+static int uart_match(device_t, cfdata_t, void*);
  14
+static void uart_attach(device_t, device_t, void *);
  15
+
  16
+/* Console functions */
  17
+static int milkymist_com_cngetc(dev_t);
  18
+static void milkymist_com_cnputc(dev_t, int);
  19
+static void milkymist_com_cnpollc(dev_t, int);
  20
+
  21
+static struct cnm_state milkymist_com_cnm_state;
  22
+
  23
+CFATTACH_DECL_NEW(uart, 0,
  24
+    uart_match, uart_attach, NULL, NULL);
  25
+
  26
+int
  27
+uart_match(device_t parent, cfdata_t cf, void *aux)
  28
+{
  29
+	return 1;
  30
+}
  31
+
  32
+void
  33
+uart_attach(device_t parent, device_t self, void *aux)
  34
+{
  35
+	aprint_normal("\n");
  36
+}
  37
+
  38
+//TODO: implement com_cngetc
  39
+static int milkymist_com_cngetc(dev_t dev)
  40
+{
  41
+	return 1;
  42
+}
  43
+
  44
+//TODO: implement com_cnputc
  45
+static void milkymist_com_cnputc(dev_t dev, int c)
  46
+{
  47
+
  48
+}
  49
+
  50
+//TODO:implement com_cnpollc
  51
+static void milkymist_com_cnpollc(dev_t dev, int on)
  52
+{
  53
+
  54
+}
  55
+
  56
+/* console method struct */
  57
+struct consdev milkymist_com_cons =
  58
+{
  59
+    NULL,               /* cn_probe: probe hardware and fill in consdev info */
  60
+    NULL,               /* cn_init: turn on as console */
  61
+    milkymist_com_cngetc,   /* cn_getc: kernel getchar interface */
  62
+    milkymist_com_cnputc,   /* cn_putc: kernel putchar interface */
  63
+    milkymist_com_cnpollc,  /* cn_pollc: turn on and off polling */
  64
+    NULL,               /* cn_bell: ring bell */
  65
+    NULL,               /* cn_halt: stop device */
  66
+    NULL,               /* cn_flush: flush output */
  67
+    NODEV,              /* major/minor of device */
  68
+    CN_NORMAL           /* priority */
  69
+};
  70
+
  71
+int milkymist_uart_cnattach(void)
  72
+{
  73
+	cn_tab = &milkymist_com_cons;
  74
+	cn_init_magic(&milkymist_com_cnm_state);
  75
+
  76
+	return 0;
  77
+}
31  sys/arch/milkymist/include/autoconf.h
... ...
@@ -0,0 +1,31 @@
  1
+/*	$NetBSD: autoconf.h,v 1.4 2008/04/28 20:23:16 ysionneau Exp $	*/
  2
+
  3
+/*-
  4
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
  5
+ * All rights reserved.
  6
+ *
  7
+ * Redistribution and use in source and binary forms, with or without
  8
+ * modification, are permitted provided that the following conditions
  9
+ * are met:
  10
+ * 1. Redistributions of source code must retain the above copyright
  11
+ *    notice, this list of conditions and the following disclaimer.
  12
+ * 2. Redistributions in binary form must reproduce the above copyright
  13
+ *    notice, this list of conditions and the following disclaimer in the
  14
+ *    documentation and/or other materials provided with the distribution.
  15
+ *
  16
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  17
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  18
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  20
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26
+ * POSSIBILITY OF SUCH DAMAGE.
  27
+ */
  28
+
  29
+struct mainbus_attach_args {
  30
+	const char *ma_name;
  31
+};
24  sys/arch/milkymist/include/csr.h
... ...
@@ -0,0 +1,24 @@
  1
+#ifndef _MACHINE_CSR_H_
  2
+#define _MACHINE_CSR_H_
  3
+
  4
+#ifdef __ASSEMBLER__
  5
+#define MMPTR(x) x
  6
+#else
  7
+#define MMPTR(x) (*((volatile unsigned int *)(x)))
  8
+#endif
  9
+
  10
+void milkymist_write_csr(int addr, int value);
  11
+int milkymist_read_csr(int addr);
  12
+
  13
+#define CSR_TIMER0_CONTROL	MMPTR(0xe0001010)
  14
+#define CSR_TIMER0_COMPARE	MMPTR(0xe0001014)
  15
+#define CSR_TIMER0_COUNTER	MMPTR(0xe0001018)
  16
+
  17
+#define CSR_TIMER1_CONTROL	MMPTR(0xe0001020)
  18
+#define CSR_TIMER1_COMPARE	MMPTR(0xe0001024)
  19
+#define CSR_TIMER1_COUNTER	MMPTR(0xe0001028)
  20
+
  21
+#define TIMER_ENABLE		(0x01)
  22
+#define TIMER_AUTORESTART	(0x02)
  23
+
  24
+#endif
10  sys/arch/milkymist/include/intr.h
@@ -72,6 +72,13 @@ static __inline void _mask_irq(int irq_mask)
72 72
 	_set_irq_mask( old_mask & ~(irq_mask) );
73 73
 }
74 74
 
  75
+static __inline void _unmask_irq(int irq_mask)
  76
+{
  77
+	int old_mask = _get_irq_mask();
  78
+	_set_irq_mask( old_mask & irq_mask);
  79
+}
  80
+
  81
+
75 82
 typedef int ipl_t;
76 83
 typedef struct {
77 84
 	ipl_t  _ipl;
@@ -96,6 +103,7 @@ splraiseipl(ipl_cookie_t icookie)
96 103
 	return _splraise(icookie._ipl);
97 104
 }
98 105
 
99  
-#include <machine/irqhandler.h>
  106
+//#include <machine/irqhandler.h>
  107
+void __isr(void);
100 108
 
101 109
 #endif	/* _MACHINE_INTR_H */
18  sys/arch/milkymist/include/irqhandler.h
@@ -44,6 +44,7 @@
44 44
 #define _MACHINE_IRQHANDLER_H_
45 45
 
46 46
 #include <sys/evcnt.h>
  47
+#include <lm32/intr.h>
47 48
 
48 49
 /* Define the IRQ bits */
49 50
 
@@ -68,24 +69,9 @@
68 69
 #define IRQ_INSTRUCT	-1
69 70
 #define NIRQS		0x10 // 16 IRQs
70 71
 
71  
-typedef struct irqhandler {
72  
-	int (*ih_func)(void *arg);	/* handler function */
73  
-	void *ih_arg;			/* Argument to handler */
74  
-	int ih_level;			/* Interrupt level */
75  
-	int ih_num;			/* Interrupt number (for accounting) */
76  
-	u_int ih_flags;			/* Interrupt flags */
77  
-	u_int ih_maskaddr;		/* mask address for expansion cards */
78  
-	u_int ih_maskbits;		/* interrupt bit for expansion cards */
79  
-	struct irqhandler *ih_next;	/* next handler */
80  
-	struct evcnt ih_ev;		/* evcnt structure */
81  
-	int (*ih_realfunc)(void *arg);	/* XXX real handler function */
82  
-	void *ih_realarg;
83  
-} irqhandler_t;
84  
-
85 72
 #ifdef _KERNEL
86 73
 extern u_int irqmasks[NIPL];
87  
-extern irqhandler_t *irqhandlers[NIRQS];
88  
-
  74
+typedef struct irqhandler irqhandler_t;
89 75
 void irq_init(void);
90 76
 int irq_claim(int, irqhandler_t *, const char *group, const char *name);
91 77
 int irq_release(int, irqhandler_t *);
6  sys/arch/milkymist/include/uart.h
... ...
@@ -0,0 +1,6 @@
  1
+#ifndef _MACHINE_UART_H_
  2
+#define _MACHINE_UART_H_
  3
+
  4
+int milkymist_uart_cnattach(void);
  5
+
  6
+#endif
56  sys/arch/milkymist/milkymist/autoconf.c
... ...
@@ -0,0 +1,56 @@
  1
+/*	$NetBSD: autoconf.c,v 1.10 2012/07/29 18:05:40 ysionneau Exp $	*/
  2
+
  3
+/*-
  4
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
  5
+ * All rights reserved.
  6
+ *
  7
+ * Redistribution and use in source and binary forms, with or without
  8
+ * modification, are permitted provided that the following conditions
  9
+ * are met:
  10
+ * 1. Redistributions of source code must retain the above copyright
  11
+ *    notice, this list of conditions and the following disclaimer.
  12
+ * 2. Redistributions in binary form must reproduce the above copyright
  13
+ *    notice, this list of conditions and the following disclaimer in the
  14
+ *    documentation and/or other materials provided with the distribution.
  15
+ *
  16
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  17
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  18
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  20
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26
+ * POSSIBILITY OF SUCH DAMAGE.
  27
+ */
  28
+
  29
+#include <sys/cdefs.h>
  30
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.10 2012/07/29 18:05:40 ysionneau Exp $");
  31
+
  32
+#include <sys/param.h>
  33
+#include <sys/systm.h>
  34
+#include <sys/device.h>
  35
+#include <sys/conf.h>
  36
+
  37
+void
  38
+cpu_configure(void)
  39
+{
  40
+	/* Start configuration */
  41
+	splhigh();
  42
+
  43
+	if (config_rootfound("mainbus", NULL) == NULL)
  44
+		panic("no mainbus found");
  45
+
  46
+	/* Configuration is finished, turn on interrupts. */
  47
+	spl0();
  48
+}
  49
+
  50
+void
  51
+cpu_rootconf(void)
  52
+{
  53
+
  54
+	/* No boot information */
  55
+	rootconf();
  56
+}
117  sys/arch/milkymist/milkymist/clock.c
... ...
@@ -0,0 +1,117 @@
  1
+/*
  2
+ * COPYRIGHT (C) 2013 Yann Sionneau <yann.sionneau@gmail.com>
  3
+ */
  4
+
  5
+#include <sys/types.h>
  6
+#include <sys/param.h>
  7
+#include <sys/systm.h>
  8
+#include <sys/kernel.h>
  9
+#include <sys/time.h>
  10
+#include <sys/device.h>
  11
+
  12
+#include <machine/intr.h>
  13
+#include <machine/csr.h>
  14
+
  15
+#include <opt_hz.h>     /* for HZ */
  16
+
  17
+#define DEBUG_CLK
  18
+#ifdef DEBUG_CLK
  19
+#define DPRINTF(fmt...)  printf(fmt)
  20
+#else
  21
+#define DPRINTF(fmt...)  
  22
+#endif
  23
+
  24
+#define SYSCLK_FREQ		(80000000)
  25
+#define TIMER0_MAX_VALUE	(SYSCLK_FREQ / HZ)
  26
+#define MILKYMIST_USEC_PER_TICK	(1000000 / HZ)
  27
+
  28
+static int milkymist_clock_match(struct device *, struct cfdata *, void *);
  29
+static void milkymist_clock_attach(struct device *, struct device *, void *);
  30
+
  31
+struct milkymist_clock_softc {
  32
+	struct device       device;
  33
+	int                 sc_intr;
  34
+};
  35
+
  36
+static struct milkymist_clock_softc *milkymist_clock_sc = NULL;
  37
+
  38
+static int
  39
+milkymist_clock_match(struct device *parent, struct cfdata *match, void *aux)
  40
+{
  41
+	DPRINTF("milkymist_clock_match\n");
  42
+	return 1;
  43
+}
  44
+
  45
+static void
  46
+milkymist_clock_attach(struct device *parent, struct device *self, void *aux)
  47
+{
  48
+	struct milkymist_clock_softc *sc = (struct milkymist_clock_softc*) self;
  49
+
  50
+	DPRINTF("milkymist_clk_attach\n");
  51
+
  52
+	if (milkymist_clock_sc == NULL)
  53
+		milkymist_clock_sc = sc;
  54
+}
  55
+
  56
+CFATTACH_DECL_NEW(milkymist_clock, sizeof(struct milkymist_clock_softc), milkymist_clock_match,
  57
+	milkymist_clock_attach, NULL, NULL);
  58
+
  59
+// TODO: what is this supposed to do?
  60
+// A lot of port let this empty
  61
+void
  62
+setstatclockrate(int hertz)
  63
+{
  64
+
  65
+}
  66
+
  67
+static __inline void milkymist_timer0_enable_irq(void)
  68
+{
  69
+	_unmask_irq(TIMER0_IRQ);
  70
+}
  71
+
  72
+static __inline void milkymist_timer0_disable_irq(void)
  73
+{
  74
+	_mask_irq(TIMER0_IRQ);
  75
+}
  76
+
  77
+/*
  78
+ * milkymist_clock_intr:
  79
+ *
  80
+ *Handle the hardclock interrupt.
  81
+ */
  82
+static int
  83
+milkymist_clock_intr(void *arg)
  84
+{
  85
+
  86
+	DPRINTF("clock ticked!\n");
  87
+	_ack_irq(TIMER0_IRQ);
  88
+	return 1;
  89
+}
  90
+
  91
+/*
  92
+ * cpu_initclocks:
  93
+ *
  94
+ *Initialize the clock and get it going.
  95
+ */
  96
+void
  97
+cpu_initclocks(void)
  98
+{
  99
+	struct milkymist_clock_softc *sc = milkymist_clock_sc;
  100
+
  101
+	stathz = profhz = 0;
  102
+
  103
+	/* set up and enable timer 0 as kernel timer, */
  104
+	/* using 88 MHz cpu clock source */
  105
+
  106
+	/* register interrupt handler */
  107
+	lm32_intrhandler_register(sc->sc_intr, milkymist_clock_intr);
  108
+
  109
+	/* Enable interrupts from timer 1 */
  110
+	milkymist_timer0_enable_irq();
  111
+
  112
+	/* load max value of the timer */
  113
+	CSR_TIMER0_COMPARE = TIMER0_MAX_VALUE;
  114
+
  115
+	/* start the timer */
  116
+	CSR_TIMER0_CONTROL = TIMER_ENABLE;
  117
+}
11  sys/arch/milkymist/milkymist/intr.c
@@ -30,3 +30,14 @@ ipl_t _splraise(ipl_t level)
30 30
 
31 31
 	return olevel;
32 32
 }
  33
+
  34
+void __isr(void)
  35
+{
  36
+	unsigned int irq_pending_mask;
  37
+
  38
+	asm volatile("rcsr %0, IP" : "=r"(irq_pending_mask) :: );
  39
+
  40
+//TODO: make sure we pass trapframe as argument to irq and lm32_dispatch_irq
  41
+	lm32_dispatch_irq(irq_pending_mask, NULL);
  42
+
  43
+}
4  sys/arch/milkymist/milkymist/locore.s
@@ -35,9 +35,9 @@ _reset_handler:
35 35
 	mvhi	r1, hi(_reset_handler)
36 36
 	ori	r1, r1, lo(_reset_handler)
37 37
 	wcsr	EBA, r1
38  
-	calli	_sdram_init
39 38
 	xor	r2, r2, r2
40 39
 	bi	_crt0
  40
+	nop
41 41
 
42 42
 _breakpoint_handler:
43 43
 	bi _breakpoint_handler
@@ -92,7 +92,7 @@ _divide_by_zero_handler:
92 92
 _interrupt_handler:
93 93
 	sw      (sp+0), ra
94 94
 	calli   .save_all
95  
-	calli   isr
  95
+	calli   __isr
96 96
 	bi      .restore_all_and_eret
97 97
 	nop
98 98
 	nop
26  sys/arch/milkymist/milkymist/machdep.c
@@ -79,13 +79,14 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.43 2012/06/11 16:27:08 tsutsui Exp $")
79 79
 
80 80
 #include <machine/intr.h>
81 81
 #include <machine/pcb.h>
  82
+#include <machine/uart.h>
82 83
 
83 84
 #include <dev/cons.h>
84 85
 
85 86
 /* the following is used externally (sysctl_hw) */
86 87
 char machine[] = MACHINE;
87 88
 char machine_arch[] = MACHINE_ARCH;
88  
-
  89
+char cpu_model[30];
89 90
 
90 91
 /* Our exported CPU info; we can have only one. */
91 92
 struct cpu_info cpu_info_store;
@@ -158,13 +159,16 @@ void lm32_lwp0_init(void)
158 159
 void
159 160
 consinit(void)
160 161
 {
161  
-	static int initted;
  162
+	static int initted = 0;
162 163
 
163 164
 	if (initted)
164 165
 		return;
165 166
 	initted = 1;
166 167
 
167  
-	cninit();
  168
+	if (milkymist_uart_cnattach())
  169
+	{
  170
+		panic("Cannot init Milkymist serial console");
  171
+	}
168 172
 }
169 173
 
170 174
 void
@@ -192,6 +196,12 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
192 196
 		       CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
193 197
 }
194 198
 
  199
+void cpu_reset(void)
  200
+{
  201
+	asm volatile("rcsr r11, EBA\n\t"
  202
+		     "b r11" ::: "r11" );
  203
+}
  204
+
195 205
 void
196 206
 cpu_reboot(int howto, char *bootstr)
197 207
 {
@@ -262,3 +272,13 @@ cpu_reboot(int howto, char *bootstr)
262 272
 		;
263 273
 	/*NOTREACHED*/
264 274
 }
  275
+
  276
+void lm32_cpu_idle(void)
  277
+{
  278
+	asm volatile("nop");
  279
+}
  280
+
  281
+void
  282
+cpu_dumpconf(void)
  283
+{
  284
+}
72  sys/arch/milkymist/milkymist/mainbus.c
... ...
@@ -0,0 +1,72 @@
  1
+/*	$NetBSD: mainbus.c,v 1.11 2010/11/21 18:53:56 ysionneau Exp $	*/
  2
+
  3
+/*-
  4
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
  5
+ * All rights reserved.
  6
+ *
  7
+ * Redistribution and use in source and binary forms, with or without
  8
+ * modification, are permitted provided that the following conditions
  9
+ * are met:
  10
+ * 1. Redistributions of source code must retain the above copyright
  11
+ *    notice, this list of conditions and the following disclaimer.
  12
+ * 2. Redistributions in binary form must reproduce the above copyright
  13
+ *    notice, this list of conditions and the following disclaimer in the
  14
+ *    documentation and/or other materials provided with the distribution.
  15
+ *
  16
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  17
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  18
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  20
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26
+ * POSSIBILITY OF SUCH DAMAGE.
  27
+ */
  28
+
  29
+#include <sys/cdefs.h>
  30
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.11 2010/11/21 18:53:56 ysionneau Exp $");
  31
+
  32
+#include <sys/param.h>
  33
+#include <sys/systm.h>
  34
+#include <sys/device.h>
  35
+#include <machine/autoconf.h>
  36
+
  37
+static int mainbus_match(device_t, cfdata_t, void *);
  38
+static void mainbus_attach(device_t, device_t, void *);
  39
+static int mainbus_print(void *, const char *);
  40
+
  41
+static struct mainbus_attach_args mainbusdevs[] = {
  42
+	{ "cpu" },
  43
+	{ NULL }	/* terminator */
  44
+};
  45
+
  46
+CFATTACH_DECL_NEW(mainbus, 0,
  47
+    mainbus_match, mainbus_attach, NULL, NULL);
  48
+
  49
+int
  50
+mainbus_match(device_t parent, cfdata_t cf, void *aux)
  51
+{
  52
+
  53
+	return 1;
  54
+}
  55
+
  56
+void
  57
+mainbus_attach(device_t parent, device_t self, void *aux)
  58
+{
  59
+	struct mainbus_attach_args *ma;
  60
+
  61
+	aprint_normal("\n");
  62
+
  63
+	for (ma = mainbusdevs; ma->ma_name != NULL; ma++)
  64
+		config_found(self, ma, mainbus_print);
  65
+}
  66
+
  67
+int
  68
+mainbus_print(void *aux, const char *pnp)
  69
+{
  70
+
  71
+	return pnp ? QUIET : UNCONF;
  72
+}
15  sys/arch/milkymist/milkymist/sys_machdep.c
... ...
@@ -0,0 +1,15 @@
  1
+#include <sys/cdefs.h>
  2
+#include <sys/param.h>
  3
+#include <sys/mount.h>
  4
+#include <sys/syscallargs.h>
  5
+#include <sys/cpu.h>
  6
+#include <uvm/uvm_extern.h>
  7
+
  8
+int
  9
+sys_sysarch(struct lwp *l, const struct sys_sysarch_args *uap, register_t *retval)
  10
+{
  11
+	/*
  12
+	 * Currently no special system calls
  13
+	 */
  14
+	return (ENOSYS);
  15
+}

No commit comments for this range

Something went wrong with that request. Please try again.