Kernel: initial version
This commit is contained in:
26
kernel/Makefile
Normal file
26
kernel/Makefile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
BUILD_TARGET = mee knf
|
||||||
|
BUILD_DIR = ../../build/mcos
|
||||||
|
SRC = $PWD
|
||||||
|
|
||||||
|
KERNEL = kernel.img
|
||||||
|
KERNELS = $(addsuffix /$(KERNEL),$(addprefix $(BUILD_DIR)/,$(BUILD_TARGET)))
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
all: $(KERNELS)
|
||||||
|
|
||||||
|
%/kernel.img: %/Makefile
|
||||||
|
make -C $(dir $@)
|
||||||
|
|
||||||
|
%/Makefile: Makefile.build FORCE
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
@echo 'SRC = $(PWD)' > $@
|
||||||
|
@echo 'TARGET = $(notdir $(patsubst %/,%,$(dir $@)))' >> $@
|
||||||
|
@cat Makefile.build >> $@
|
||||||
|
|
||||||
|
clean: $(addsuffix .clean,$(BUILD_TARGET))
|
||||||
|
|
||||||
|
%.clean: $(BUILD_DIR)/%/Makefile
|
||||||
|
make -C $(BUILD_DIR)/$(basename $@) clean
|
||||||
|
|
||||||
|
FORCE:
|
||||||
34
kernel/Makefile.build
Normal file
34
kernel/Makefile.build
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
AALBASE=$(SRC)/../../aal/manycore
|
||||||
|
AALDIR=$(AALBASE)/$(TARGET)
|
||||||
|
SRCS=$(wildcard $(SRC)/*.c)
|
||||||
|
OBJS=$(notdir $(patsubst %.c,%.o,$(SRCS)))
|
||||||
|
CFLAGS=-Wall -nostdlib -nostdinc -isystem $(shell $(CC) -print-file-name=include) -O3 -I$(AALBASE)/generic/include -I$(AALDIR)/include -I$(SRC)/include
|
||||||
|
LDFLAGS=-e arch_start
|
||||||
|
AALOBJ=$(AALDIR)/aal.o
|
||||||
|
|
||||||
|
-include $(SRC)/configs/config.$(TARGET)
|
||||||
|
|
||||||
|
all: depend kernel.img
|
||||||
|
|
||||||
|
kernel.img: $(OBJS) $(AALOBJ)
|
||||||
|
$(LD) $(LDFLAGS) -o $@.elf $^
|
||||||
|
[ -f $(SRC)/scripts/mkimage.$(TARGET) ] && sh $(SRC)/scripts/mkimage.$(TARGET) '$@.elf' '$@' '$(SRC)' || cp $@.elf $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(OBJS) kernel.img kernel.img.elf Makefile.dep
|
||||||
|
make -C $(AALDIR) clean
|
||||||
|
|
||||||
|
depend: Makefile.dep
|
||||||
|
|
||||||
|
Makefile.dep: $(SRCS)
|
||||||
|
$(CC) $(CFLAGS) -MM $(SRCS) > Makefile.dep
|
||||||
|
|
||||||
|
$(AALOBJ): FORCE
|
||||||
|
make -C $(AALDIR) CC=$(CC) LD=$(LD)
|
||||||
|
|
||||||
|
%.o: $(SRC)/%.c
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
FORCE:
|
||||||
|
|
||||||
|
-include Makefile.dep
|
||||||
5
kernel/configs/config.knf
Normal file
5
kernel/configs/config.knf
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CC = /home/shimosawa/cross.knf/bin/x86_64-l1om-linux-gcc
|
||||||
|
LD = /home/shimosawa/cross.knf/bin/x86_64-l1om-linux-ld
|
||||||
|
|
||||||
|
CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
|
||||||
|
LDFLAGS += -m elf_l1om
|
||||||
2
kernel/configs/config.mee
Normal file
2
kernel/configs/config.mee
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
|
||||||
|
LDFLAGS += -T $(SRC)/mee.lds
|
||||||
43
kernel/debug.c
Normal file
43
kernel/debug.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <kmsg.h>
|
||||||
|
#include <aal/debug.h>
|
||||||
|
|
||||||
|
struct aal_kmsg_buf kmsg_buf AAL_KMSG_ALIGN;
|
||||||
|
|
||||||
|
extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
|
||||||
|
|
||||||
|
/* TODO: lock */
|
||||||
|
void kputs(char *buf)
|
||||||
|
{
|
||||||
|
int len = strlen(buf);
|
||||||
|
|
||||||
|
if (len + kmsg_buf.tail > kmsg_buf.len) {
|
||||||
|
len = kmsg_buf.len - kmsg_buf.tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(kmsg_buf.str, buf, len);
|
||||||
|
kmsg_buf.tail += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int kprintf(const char *format, ...)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
va_list va;
|
||||||
|
|
||||||
|
va_start(va, format);
|
||||||
|
|
||||||
|
len = vsnprintf(kmsg_buf.str + kmsg_buf.tail,
|
||||||
|
kmsg_buf.len - kmsg_buf.tail, format, va);
|
||||||
|
kmsg_buf.tail += len;
|
||||||
|
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void kmsg_init(void)
|
||||||
|
{
|
||||||
|
kmsg_buf.tail = 0;
|
||||||
|
kmsg_buf.len = sizeof(kmsg_buf.str);
|
||||||
|
}
|
||||||
9
kernel/include/kmsg.h
Normal file
9
kernel/include/kmsg.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef KMSG_H
|
||||||
|
#define KMSG_H
|
||||||
|
|
||||||
|
void kputs(char *buf);
|
||||||
|
int kprintf(const char *format, ...);
|
||||||
|
|
||||||
|
void kmsg_init(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
3
kernel/mee.lds
Normal file
3
kernel/mee.lds
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
MEMORY {
|
||||||
|
ram (rwx) : ORIGIN = 0x40001000, LENGTH = 4M
|
||||||
|
}
|
||||||
3
kernel/scripts/mkimage.mee
Normal file
3
kernel/scripts/mkimage.mee
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cat $3/../elfboot/elfboot $1 > $2
|
||||||
23
kernel/setup.c
Normal file
23
kernel/setup.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <kmsg.h>
|
||||||
|
#include <aal/cpu.h>
|
||||||
|
#include <aal/debug.h>
|
||||||
|
|
||||||
|
extern struct aal_kmsg_buf kmsg_buf;
|
||||||
|
|
||||||
|
extern void arch_init(void);
|
||||||
|
extern void kmsg_init(void);
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
kmsg_init();
|
||||||
|
|
||||||
|
kputs("MCK started.\n");
|
||||||
|
|
||||||
|
arch_init();
|
||||||
|
|
||||||
|
cpu_disable_interrupt();
|
||||||
|
while (1) {
|
||||||
|
cpu_halt();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user