-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
comm: refactor to support lwip event model
1 parent
9f52277
commit 18106cc
Showing
20 changed files
with
830 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include <string.h> | ||
#include <generated/csr.h> | ||
|
||
#include "log.h" | ||
#include "mailbox.h" | ||
#include "elf_loader.h" | ||
#include "services.h" | ||
#include "kloader.h" | ||
|
||
|
||
static struct symbol symtab[128]; | ||
static int _symtab_count; | ||
static char _symtab_strings[128*16]; | ||
static char *_symtab_strptr; | ||
|
||
static void symtab_init(void) | ||
{ | ||
memset(symtab, 0, sizeof(symtab)); | ||
_symtab_count = 0; | ||
_symtab_strptr = _symtab_strings; | ||
} | ||
|
||
static int symtab_add(const char *name, void *target) | ||
{ | ||
if(_symtab_count >= sizeof(symtab)/sizeof(symtab[0])) { | ||
log("Too many provided symbols in object"); | ||
symtab_init(); | ||
return 0; | ||
} | ||
symtab[_symtab_count].name = _symtab_strptr; | ||
symtab[_symtab_count].target = target; | ||
_symtab_count++; | ||
|
||
while(1) { | ||
if(_symtab_strptr >= &_symtab_strings[sizeof(_symtab_strings)]) { | ||
log("Provided symbol string table overflow"); | ||
symtab_init(); | ||
return 0; | ||
} | ||
*_symtab_strptr = *name; | ||
_symtab_strptr++; | ||
if(*name == 0) | ||
break; | ||
name++; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
int kloader_load(void *buffer, int length) | ||
{ | ||
#ifdef ARTIQ_AMP | ||
if(!kernel_cpu_reset_read()) { | ||
log("BUG: attempted to load while kernel CPU running"); | ||
return 0; | ||
} | ||
#endif | ||
symtab_init(); | ||
return load_elf( | ||
resolve_service_symbol, symtab_add, | ||
buffer, length, (void *)KERNELCPU_PAYLOAD_ADDRESS, 4*1024*1024); | ||
} | ||
|
||
kernel_function kloader_find(const char *name) | ||
{ | ||
return find_symbol(symtab, name); | ||
} | ||
|
||
#ifdef ARTIQ_AMP | ||
|
||
extern char _binary_ksupport_bin_start; | ||
extern char _binary_ksupport_bin_end; | ||
|
||
static void start_kernel_cpu(void *addr) | ||
{ | ||
memcpy((void *)KERNELCPU_EXEC_ADDRESS, &_binary_ksupport_bin_start, | ||
&_binary_ksupport_bin_end - &_binary_ksupport_bin_start); | ||
mailbox_acknowledge(); | ||
mailbox_send(addr); | ||
kernel_cpu_reset_write(0); | ||
} | ||
|
||
void kloader_start_bridge(void) | ||
{ | ||
start_kernel_cpu(NULL); | ||
} | ||
|
||
void kloader_start_user_kernel(kernel_function k) | ||
{ | ||
if(!kernel_cpu_reset_read()) { | ||
log("BUG: attempted to start kernel CPU while already running (user kernel)"); | ||
return; | ||
} | ||
start_kernel_cpu((void *)k); | ||
} | ||
|
||
void kloader_start_idle_kernel(void) | ||
{ | ||
if(!kernel_cpu_reset_read()) { | ||
log("BUG: attempted to start kernel CPU while already running (idle kernel)"); | ||
return; | ||
} | ||
/* TODO */ | ||
} | ||
|
||
void kloader_stop_kernel(void) | ||
{ | ||
kernel_cpu_reset_write(1); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef __KLOADER_H | ||
#define __KLOADER_H | ||
|
||
#define KERNELCPU_EXEC_ADDRESS 0x40020000 | ||
#define KERNELCPU_PAYLOAD_ADDRESS 0x40024000 | ||
|
||
typedef void (*kernel_function)(void); | ||
|
||
int kloader_load(void *buffer, int length); | ||
kernel_function kloader_find(const char *name); | ||
|
||
#ifdef ARTIQ_AMP | ||
void kloader_start_bridge(void); | ||
void kloader_start_idle_kernel(void); | ||
void kloader_start_user_kernel(kernel_function k); | ||
void kloader_stop_kernel(void); | ||
#endif | ||
|
||
#endif /* __KLOADER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
|
||
#include "log.h" | ||
|
||
static int buffer_index; | ||
static char buffer[LOG_BUFFER_SIZE]; | ||
|
||
void log_va(const char *fmt, va_list args) | ||
{ | ||
char outbuf[256]; | ||
int i, len; | ||
|
||
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args); | ||
for(i=0;i<len;i++) { | ||
buffer[buffer_index] = outbuf[i]; | ||
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE; | ||
} | ||
buffer[buffer_index] = '\n'; | ||
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE; | ||
} | ||
|
||
void log(const char *fmt, ...) | ||
{ | ||
va_list args; | ||
|
||
va_start(args, fmt); | ||
log_va(fmt, args); | ||
va_end(args); | ||
} | ||
|
||
void log_get(char *outbuf) | ||
{ | ||
int i, j; | ||
|
||
j = buffer_index + 1; | ||
for(i=0;i<LOG_BUFFER_SIZE;i++) { | ||
outbuf[i] = buffer[j]; | ||
j = (j + 1) % LOG_BUFFER_SIZE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef __LOG_H | ||
#define __LOG_H | ||
|
||
#include <stdarg.h> | ||
|
||
#define LOG_BUFFER_SIZE 4096 | ||
|
||
void log_va(const char *fmt, va_list args); | ||
void log(const char *fmt, ...); | ||
|
||
void log_get(char *outbuf); | ||
|
||
#endif /* __LOG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __SESSION_H | ||
#define __SESSION_H | ||
|
||
void session_start(void); | ||
void session_end(void); | ||
|
||
int session_input(void *data, int len); | ||
void session_poll(void **data, int *len); | ||
void session_ack(int len); | ||
|
||
int rpc(int rpc_num, ...); | ||
void comm_service(void); | ||
|
||
#endif /* __SESSION_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters