diff --git a/arch/arch.c b/arch/arch.c index 7809cffa..071709a3 100644 --- a/arch/arch.c +++ b/arch/arch.c @@ -21,6 +21,8 @@ void arch_init(boot_info_t* boot, int cpu) { interrupt_init(cpu); platform_end(); } else { +#ifdef MP_ENABLE ap_init(cpu); +#endif } } \ No newline at end of file diff --git a/arch/armv7/context.c b/arch/armv7/context.c index bac58553..a62c6556 100644 --- a/arch/armv7/context.c +++ b/arch/armv7/context.c @@ -20,7 +20,7 @@ int context_get_mode(context_t* context) { } void context_init(context_t* context, u32* entry, u32* stack0, u32* stack3, - u32 level) { + u32 level, int cpu) { if (context == NULL) { return; } diff --git a/arch/armv7/context.h b/arch/armv7/context.h index 35820f96..aceb2a74 100644 --- a/arch/armv7/context.h +++ b/arch/armv7/context.h @@ -10,6 +10,18 @@ #include "libs/include/types.h" #include "platform/platform.h" + +typedef struct context_t { + u32 esp0, ss0, ds0; + u32 esp, ss, ds; + u32 eip; + tss_t* tss; + u32* page_dir; + u32* kernel_page_dir; + u32 level; +} context_t; + + typedef struct interrupt_context { // manual push u32 no; @@ -56,6 +68,18 @@ typedef struct interrupt_context { : \ : "i"(VEC), "i"(CODE)) +#define interrupt_exit_ret() \ + asm volatile( \ + "mov r0,r0 \n" \ + "ldmfd r0!,{r1,r2}\n" \ + "ldmfd r0!,{r4-r11}\n" \ + "msr psp, r0\n" \ + "mov lr,#0xFFFFFFFD\n" \ + "isb\n" \ + "bx lr\n" \ + : \ + : ) + #define interrupt_exit_context(duck_context) \ asm volatile( \ "ldr r0,%0 \n" \ @@ -90,7 +114,9 @@ typedef struct interrupt_context { #define context_fn(context) context->r6 #define context_ret(context) context->r0 - +#define context_set_entry(context, entry) \ + ((interrupt_context_t*)((context)->esp0))->lr = entry + 4; + #define context_restore(duck_context) \ asm volatile( \ "ldr r0,%0 \n" \ @@ -111,7 +137,7 @@ typedef struct interrupt_context { void context_clone(context_t* context, context_t* src, u32* stack0, u32* stack3, u32* old0, u32* old3); void context_init(context_t* context, u32* entry, u32* stack0, u32* stack3, - u32 level); + u32 level, int cpu); void context_dump(context_t* c); diff --git a/arch/armv7/cpu.c b/arch/armv7/cpu.c index 43497fca..9e47cf27 100644 --- a/arch/armv7/cpu.c +++ b/arch/armv7/cpu.c @@ -278,3 +278,8 @@ void cpu_backtrace(void) { topfp = fp; } } + + +int cpu_get_id(){ + return 0; +} \ No newline at end of file diff --git a/arch/armv7/cpu.h b/arch/armv7/cpu.h index 0ea4f9ea..8f1152ed 100644 --- a/arch/armv7/cpu.h +++ b/arch/armv7/cpu.h @@ -11,16 +11,6 @@ #define debugger -typedef struct context_t { - u32 esp0, ss0, ds0; - u32 esp, ss, ds; - u32 eip; - tss_t* tss; - u32* page_dir; - u32* kernel_page_dir; - u32 level; -} context_t; - typedef struct cpsr { union { struct { diff --git a/boot/arm/SConscript b/boot/arm/SConscript index 6f0305c5..101e6130 100644 --- a/boot/arm/SConscript +++ b/boot/arm/SConscript @@ -22,13 +22,12 @@ boot_source= ['boot_'+env['ARCH']+'.s'] if env.get('MYLIB'): source.append(env.get('MYLIB')) -env.GenerateKernelSize('config.h',['../../init/kernel']) if env['PLATFORM']=='stm32f4xx': linkflags='-nostdlib -nostartfiles -T boot/arm/link-stm32f4xx.ld' source=['init_armv7.c'] boot_source=['boot_armv7.s',] - cflags+='-DNO_KSTART' + cflags+=' -DNO_KSTART ' elif env['PLATFORM']=='raspi2': linkflags='-nostdlib -nostartfiles -T boot/arm/link-raspi2.ld' @@ -36,8 +35,13 @@ else: pass -env.Object('boot.o',boot_source,ASFLAGS='') -env.Program(target ='init.elf', source = source, - CFLAGS=cflags, - LINKFLAGS= linkflags) -env.Objcopy('init.bin','init.elf',OBJCOPYFLAGS='-O binary -S --strip-debug') \ No newline at end of file +if env['PLATFORM']=='stm32f4xx': + env.Object('boot.o',boot_source,ASFLAGS='') + env.Object('init.o',source,ASFLAGS='', CFLAGS=cflags,LINKFLAGS= linkflags) +else: + env.GenerateKernelSize('config.h',['../../init/kernel']) + env.Object('boot.o',boot_source,ASFLAGS='') + env.Program(target ='init.elf', source = source, + CFLAGS=cflags, + LINKFLAGS= linkflags) + env.Objcopy('init.bin','init.elf',OBJCOPYFLAGS='-O binary -S --strip-debug') \ No newline at end of file diff --git a/boot/arm/config.h b/boot/arm/config.h index 1e2fb73c..14764cac 100644 --- a/boot/arm/config.h +++ b/boot/arm/config.h @@ -1,5 +1,5 @@ #ifndef BOOT/ARM/CONFIG_H #define BOOT/ARM/CONFIG_H -#define KERNEL_BLOCK_SIZE 169 -#define KERNEL_SIZE 172948 +#define KERNEL_BLOCK_SIZE 194 +#define KERNEL_SIZE 197672 #endif diff --git a/boot/arm/link.ld b/boot/arm/link.ld index 391e5297..cdeb85e3 100644 --- a/boot/arm/link.ld +++ b/boot/arm/link.ld @@ -1,9 +1,36 @@ ENTRY(_start) + +__heap_size = 0x200; +__stack_size = 0x200; + SECTIONS { -. = 0x0000; -.text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } -.data : {*(.data)} -.bss : {*(.bss)} -sp_top = .; + . = 0x000; + .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } + .data : {*(.data)} + .bss : {*(.bss)} + .stack : ALIGN(4) { + . = 0x6000; + _estack = .; + . = . + __stack_size; + _stack_abt = .; + + . = . + __stack_size; + _stack_undf = .; + + . = . + __stack_size; + _stack_irq = .; + + . = . + __stack_size; + _stack_svc = .; + + + . = . + __stack_size*4*4 ; + _stack_other = .; + + + . = ALIGN(4); + _sstack = .; + } + } \ No newline at end of file diff --git a/init/SConscript b/init/SConscript index b164cce1..bea0498b 100644 --- a/init/SConscript +++ b/init/SConscript @@ -13,7 +13,7 @@ Import('env') linkflags=' $LINKFLAGS -Xlinker -Map=kernel.map -T'+env.get('LINKLD') libs=[ - '../modules/libdriver.a', + '../modules/libmodules.a', '../kernel/libyiyiya.a', '../arch/libarch.a', '../platform/libplatform.a', @@ -36,8 +36,9 @@ if env.get('ARCHTYPE')=='xtensa': pass elif env.get('ARCHTYPE')=='arm': if env.get('ARCH')=='armv7': - kernel.append('../boot/arm/boot_armv7.s') - kernel.append('../boot/arm/init_armv7.c') + kernel.append('../boot/arm/boot.o') + kernel.append('../boot/arm/init.o') + pass else: pass if env.get('MYLIB'): diff --git a/kernel/config.h b/kernel/config.h index a47fcdfe..fa00175f 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -27,6 +27,8 @@ #define PAGE_SIZE 0x1000 +#define MP_ENABLE 1 //多cpu + #elif defined(ARMV7) #define MAX_FD_NUMBER 50 @@ -66,6 +68,7 @@ #define THREAD_STACK_SIZE 4096*4 #define PAGE_SIZE 0x1000 +#define MP_ENABLE 1 //多cpu #endif @@ -79,7 +82,7 @@ // #define LOG_DEBUG 0 #define MAX_PATH_BUFFER 256 //最长文件路径 -#define MP_ENABLE 1 //多cpu + #include "logger.h" diff --git a/kernel/exceptions.c b/kernel/exceptions.c index daa70fbf..76e6250e 100644 --- a/kernel/exceptions.c +++ b/kernel/exceptions.c @@ -208,7 +208,7 @@ INTERRUPT_SERVICE void sys_tick_handler() { interrupt_entering_code(2, 0); interrupt_process(do_schedule); - interrupt_exit_context(current_context); + interrupt_exit_ret(); } INTERRUPT_SERVICE diff --git a/platform/v3s/init.c b/platform/v3s/init.c index 46c8c3de..8db13613 100644 --- a/platform/v3s/init.c +++ b/platform/v3s/init.c @@ -1,6 +1,5 @@ #include "init.h" -#include "gpio/v3s.h" #include "gpio.h" #include "v3s-reg-ccu.h" @@ -146,4 +145,21 @@ void platform_init() { // sys_dram_init(); } -void platform_end() {} \ No newline at end of file +void platform_end() {} + + +void ipi_enable(int cpu) { + +} + +void lcpu_send_start(u32 cpu, u32 entry) { + +} + +void ipi_send(int cpu, int vec) { + +} + +void ipi_clear(int cpu) { + +} \ No newline at end of file