Skip to content

Commit 21a0919

Browse files
committedApr 3, 2015
runtime: load support code into kernel CPU
1 parent c6d3750 commit 21a0919

File tree

7 files changed

+143
-34
lines changed

7 files changed

+143
-34
lines changed
 

Diff for: ‎soc/runtime/Makefile

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include $(MSCDIR)/software/common.mak
33
BOARD=papilio_pro
44
SERIAL=/dev/ttyUSB1
55

6-
OBJECTS=isr.o elf_loader.o exception_jmp.o exceptions.o services.o comm_serial.o gpio.o rtio.o dds.o test_mode.o main.o
6+
OBJECTS=isr.o elf_loader.o kernelcpu.o exception_jmp.o exceptions.o services.o comm_serial.o gpio.o rtio.o dds.o ksupport_data.o test_mode.o main.o
77

88
all: runtime.bin
99

@@ -12,7 +12,7 @@ all: runtime.bin
1212

1313
%.bin: %.elf
1414
$(OBJCOPY) -O binary $< $@
15-
chmod -x $@
15+
@chmod -x $@
1616

1717
%.fbi: %.bin
1818
$(MSCDIR)/mkmscimg.py -f -o $@ $<
@@ -28,7 +28,18 @@ runtime.elf: $(OBJECTS) libs
2828
-L$(MSCDIR)/software/libbase \
2929
-L$(MSCDIR)/software/libcompiler-rt \
3030
-lbase -lcompiler-rt
31-
chmod -x $@
31+
@chmod -x $@
32+
33+
ksupport.elf: ksupport.o
34+
$(LD) $(LDFLAGS) \
35+
-T ksupport.ld \
36+
-N -o $@ \
37+
$(MSCDIR)/software/libbase/crt0-$(CPU).o \
38+
ksupport.o
39+
@chmod -x $@
40+
41+
ksupport_data.o: ksupport.bin
42+
$(LD) -r -b binary -o $@ $<
3243

3344
main.o: main.c
3445
$(compile-dep)
@@ -52,5 +63,6 @@ flash: runtime.fbi
5263

5364
clean:
5465
$(RM) $(OBJECTS) $(OBJECTS:.o=.d) runtime.elf runtime.bin runtime.fbi .*~ *~
66+
$(RM) ksupport.d ksupport.o ksupport.elf ksupport.bin
5567

5668
.PHONY: all main.o clean libs load

Diff for: ‎soc/runtime/kernelcpu.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <generated/csr.h>
2+
3+
#ifdef CSR_KERNEL_CPU_BASE
4+
5+
#include <stdio.h>
6+
#include <string.h>
7+
#include <system.h>
8+
9+
#include "kernelcpu.h"
10+
11+
extern char _binary_ksupport_bin_start;
12+
extern char _binary_ksupport_bin_end;
13+
14+
void kernelcpu_start(void)
15+
{
16+
memcpy((void *)KERNELCPU_EXEC_ADDRESS, &_binary_ksupport_bin_start,
17+
&_binary_ksupport_bin_end - &_binary_ksupport_bin_start);
18+
flush_l2_cache();
19+
kernel_cpu_reset_write(0);
20+
}
21+
22+
void kernelcpu_stop(void)
23+
{
24+
kernel_cpu_reset_write(1);
25+
}
26+
27+
#endif /* CSR_KERNEL_CPU_BASE */

Diff for: ‎soc/runtime/kernelcpu.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __KERNELCPU_H
2+
#define __KERNELCPU_H
3+
4+
#include <hw/common.h>
5+
6+
#define KERNELCPU_EXEC_ADDRESS 0x40020000
7+
#define KERNELCPU_KMAIN_ADDRESS 0x40022000
8+
9+
#define KERNELCPU_MAILBOX MMPTR(0xd0000000)
10+
11+
void kernelcpu_start(void);
12+
void kernelcpu_stop(void);
13+
14+
#endif /* __KERNELCPU_H */

Diff for: ‎soc/runtime/ksupport.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void exception_handler(unsigned long vect, unsigned long *sp);
2+
void exception_handler(unsigned long vect, unsigned long *sp)
3+
{
4+
/* TODO: report hardware exception to comm CPU */
5+
for(;;);
6+
}
7+
8+
extern void kmain(void);
9+
10+
int main(void);
11+
int main(void)
12+
{
13+
kmain();
14+
/* TODO: report end of kernel to comm CPU */
15+
return 0;
16+
}

Diff for: ‎soc/runtime/ksupport.ld

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
INCLUDE generated/output_format.ld
2+
ENTRY(_start)
3+
4+
INCLUDE generated/regions.ld
5+
6+
/* First 128K of main memory are reserved for runtime code/data
7+
* then comes kernel memory. First 8K of kernel memory are for support code.
8+
*/
9+
MEMORY {
10+
ksupport : ORIGIN = 0x40020000, LENGTH = 0x2000
11+
}
12+
13+
/* Then comes the payload. */
14+
PROVIDE(kmain = ORIGIN(ksupport) + LENGTH(ksupport));
15+
16+
/* On biprocessor systems, kernel stack is at the end of main RAM,
17+
* before the runtime stack. Leave 1M for runtime stack.
18+
*/
19+
PROVIDE(_fstack = 0x40000000 + LENGTH(main_ram) - 1024*1024 - 4);
20+
21+
SECTIONS
22+
{
23+
.text :
24+
{
25+
_ftext = .;
26+
*(.text .stub .text.* .gnu.linkonce.t.*)
27+
_etext = .;
28+
} > ksupport
29+
30+
.rodata :
31+
{
32+
. = ALIGN(4);
33+
_frodata = .;
34+
*(.rodata .rodata.* .gnu.linkonce.r.*)
35+
*(.rodata1)
36+
_erodata = .;
37+
} > ksupport
38+
39+
.data :
40+
{
41+
. = ALIGN(4);
42+
_fdata = .;
43+
*(.data .data.* .gnu.linkonce.d.*)
44+
*(.data1)
45+
_gp = ALIGN(16);
46+
*(.sdata .sdata.* .gnu.linkonce.s.*)
47+
_edata = .;
48+
} > ksupport
49+
50+
.bss :
51+
{
52+
. = ALIGN(4);
53+
_fbss = .;
54+
*(.dynsbss)
55+
*(.sbss .sbss.* .gnu.linkonce.sb.*)
56+
*(.scommon)
57+
*(.dynbss)
58+
*(.bss .bss.* .gnu.linkonce.b.*)
59+
*(COMMON)
60+
. = ALIGN(4);
61+
_ebss = .;
62+
. = ALIGN(8);
63+
_heapstart = .;
64+
} > ksupport
65+
}

Diff for: ‎soc/runtime/main.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
#include "test_mode.h"
1111
#include "comm.h"
1212
#include "elf_loader.h"
13+
#include "kernelcpu.h"
1314
#include "exceptions.h"
1415
#include "services.h"
1516
#include "rtio.h"
1617
#include "dds.h"
1718

18-
1919
static struct symbol symtab[128];
2020
static int _symtab_count;
2121
static char _symtab_strings[128*16];
2222
static char *_symtab_strptr;
2323

24-
2524
static void symtab_init(void)
2625
{
2726
memset(symtab, 0, sizeof(symtab));
@@ -132,7 +131,11 @@ int main(void)
132131
irq_setie(1);
133132
uart_init();
134133

135-
puts("ARTIQ runtime built "__DATE__" "__TIME__"\n");
134+
#ifdef CSR_KERNEL_CPU_BASE
135+
puts("ARTIQ runtime built "__DATE__" "__TIME__" for biprocessor systems\n");
136+
#else
137+
puts("ARTIQ runtime built "__DATE__" "__TIME__" for uniprocessor systems\n");
138+
#endif
136139
blink_led();
137140

138141
if(check_test_mode()) {

Diff for: ‎soc/runtime/test_mode.c

-28
Original file line numberDiff line numberDiff line change
@@ -305,30 +305,6 @@ static char *get_token(char **str)
305305
return d;
306306
}
307307

308-
#ifdef CSR_KERNEL_CPU_BASE
309-
static const unsigned int test_program[] = {
310-
0x1860dead, // l.movhi r3,0xdead
311-
0x1880d000, // l.movhi r4,0xd000
312-
0xa863beef, // l.ori r3,r3,0xbeef
313-
0xd4041800, // l.sw 0(r4),r3
314-
0x00000000, // l.j +0
315-
0x15000000, // l.nop
316-
};
317-
318-
static void cputest(void)
319-
{
320-
int i;
321-
322-
kernel_cpu_reset_write(1);
323-
MMPTR(0xd0000000) = 0;
324-
memcpy((void *)0x41000000, test_program, sizeof(test_program));
325-
flush_l2_cache();
326-
kernel_cpu_reset_write(0);
327-
for(i=0;i<10;i++)
328-
printf("%08x\n", MMPTR(0xd0000000));
329-
}
330-
#endif
331-
332308
static void do_command(char *c)
333309
{
334310
char *token;
@@ -351,10 +327,6 @@ static void do_command(char *c)
351327
else if(strcmp(token, "ddsftw") == 0) ddsftw(get_token(&c), get_token(&c));
352328
else if(strcmp(token, "ddstest") == 0) ddstest(get_token(&c));
353329

354-
#ifdef CSR_KERNEL_CPU_BASE
355-
else if(strcmp(token, "cputest") == 0) cputest();
356-
#endif
357-
358330
else if(strcmp(token, "") != 0)
359331
printf("Command not found\n");
360332
}

0 commit comments

Comments
 (0)
Please sign in to comment.