Skip to content

Commit

Permalink
fix armv7 error
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbinary committed Sep 3, 2022
1 parent 6612edb commit 5596ceb
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 34 deletions.
2 changes: 2 additions & 0 deletions arch/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion arch/armv7/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 28 additions & 2 deletions arch/armv7/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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" \
Expand All @@ -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);


Expand Down
5 changes: 5 additions & 0 deletions arch/armv7/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,8 @@ void cpu_backtrace(void) {
topfp = fp;
}
}


int cpu_get_id(){
return 0;
}
10 changes: 0 additions & 10 deletions arch/armv7/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 11 additions & 7 deletions boot/arm/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ 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'
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')
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')
4 changes: 2 additions & 2 deletions boot/arm/config.h
Original file line number Diff line number Diff line change
@@ -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
37 changes: 32 additions & 5 deletions boot/arm/link.ld
Original file line number Diff line number Diff line change
@@ -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 = .;
}

}
7 changes: 4 additions & 3 deletions init/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'):
Expand Down
5 changes: 4 additions & 1 deletion kernel/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#define PAGE_SIZE 0x1000

#define MP_ENABLE 1 //多cpu

#elif defined(ARMV7)

#define MAX_FD_NUMBER 50
Expand Down Expand Up @@ -66,6 +68,7 @@
#define THREAD_STACK_SIZE 4096*4
#define PAGE_SIZE 0x1000

#define MP_ENABLE 1 //多cpu
#endif


Expand All @@ -79,7 +82,7 @@
// #define LOG_DEBUG 0

#define MAX_PATH_BUFFER 256 //最长文件路径
#define MP_ENABLE 1 //多cpu


#include "logger.h"

Expand Down
2 changes: 1 addition & 1 deletion kernel/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions platform/v3s/init.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "init.h"

#include "gpio/v3s.h"
#include "gpio.h"
#include "v3s-reg-ccu.h"

Expand Down Expand Up @@ -146,4 +145,21 @@ void platform_init() {
// sys_dram_init();
}

void platform_end() {}
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) {

}

0 comments on commit 5596ceb

Please sign in to comment.