18#include <FreeNOS/User.h>
68 (this->*h->
exec) (&msg);
77 ERROR(
"invalid action " << (
int)msg.
action <<
" from master");
84 const Size maximumArguments = 64;
85 char cmd[128], *argv[maximumArguments], *arg =
ZERO;
96 ERROR(
"failed to lookup virtual address at " <<
107 ERROR(
"failed to lookup virtual address at " <<
108 (
void *) msg->
programCmd <<
": " << (
int)result);
140 ERROR(
"failed to copy program command: result = " << (
int) result);
149 for (
Size i = 0; i <
sizeof(cmd) && argc < maximumArguments - 1; i++)
157 else if (cmd[i] == 0)
173 ERROR(
"failed to map program data: " << (
int)result);
182 ERROR(
"failed to spawn() program: " << pid);
195 ERROR(
"failed to unmap program data: " << (
int)result);
226 const Size pingPongNumber = 0x12345678;
242 for (
Size i = 1; i < numCores; i++)
248 NOTICE(
"core" << i <<
" send a Pong");
252 ERROR(
"invalid message received from core" << i);
267 ERROR(
"failed to setup IPC channels");
278 ERROR(
"failed to load kernel program");
284 ERROR(
"failed to discover cores");
290 ERROR(
"failed to prepare CoreInfo data array");
296 ERROR(
"failed to setup IPC channels");
302 ERROR(
"failed to boot all cores");
308 ERROR(
"failed to unload kernel program");
342 ERROR(
"failed to allocate compressed kernel image with VMCtl: result = " << (
int) result);
368 ERROR(
"failed to initialize LZ4 decompressor: result = " << (
int) decompResult);
382 ERROR(
"failed to allocate kernel image with VMCtl: result = " << (
int) result);
390 ERROR(
"failed to decompress kernel image: result = " << (
int) decompResult);
398 ERROR(
"failed to find ExecutableFormat of kernel on path: " <<
kernelPath <<
399 ": result " << (
int) execResult);
409 ERROR(
"failed to get ExecutableFormat regions of kernel on path: " <<
kernelPath <<
410 ": result " << (
int) execResult);
418 ERROR(
"failed to release compressed kernel image with VMCtl: result = " << (
int) result);
422 DEBUG(
"kernel loaded");
432 ERROR(
"failed to deallocate kernel image with VMCtl: result = " << (
int) r);
453 ERROR(
"VMCtl(ReserveMem) failed for core" <<
coreId <<
454 " at " << (
void *)info->
memory.
phys <<
": result " << (
int) r);
474 ERROR(
"VMCtl(Map) failed for kernel on core" <<
coreId <<
475 " at " << (
void *)range.
phys <<
": result " << (
int) r);
484 ERROR(
"VMCopy failed for kernel regions[" << i <<
"].dataOffset" <<
485 " at " << (
void *)regions[i].dataOffset <<
": result " << (
int) r);
492 ERROR(
"VMCtl(UnMap) failed for kernel on core" <<
coreId <<
493 " at " << (
void *)range.
phys <<
": result " << (
int) r);
498 " @ " << (
void *) range.
phys);
511 ERROR(
"VMCtl(Map) failed for BootImage on core" <<
coreId <<
512 " at " << (
void *)range.
phys <<
": result " << (
int) r);
521 ERROR(
"VMCopy failed for BootIage on core" <<
coreId <<
523 ": result " << (
int) r);
530 ERROR(
"VMCtl(UnMap) failed for BootImage on core" <<
coreId <<
531 " at " << (
void *)range.
phys <<
": result " << (
int) r);
545 if (cores.
count() == 0)
547 ERROR(
"no cores found");
556 (memPerCore / 1024 / 1024) <<
"MB per core");
603 if (cores.
count() == 0)
605 ERROR(
"no cores found");
628 DEBUG(
"addr = " << (
void*)addr <<
", size = " << size);
655 for (
Size i = 1; i < numCores; i++)
710 ERROR(
"failed to flush master channel: result = " << (
int) result);
735 ERROR(
"cannot retrieve MemoryChannel for core" <<
coreId);
743 ERROR(
"failed to write channel on core" <<
coreId <<
": result = " << (
int)result);
748 result = ch->
flush();
751 ERROR(
"failed to flush channel on core" <<
coreId <<
": result = " << (
int)result);
Result
Enumeration of generic kernel API result codes.
virtual Result syncSendTo(const void *buffer, const Size msgSize, const ProcessID pid)
Synchronous send to one process.
ProcessID from
Source process of the message.
Type type
Message type is either a request or response.
Template class which serves incoming messages from Channels using MessageHandlers.
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCount > m_ipcHandlers
IPC handler functions.
int run()
Enters an infinite loop, serving incoming requests.
void addIPCHandler(const Size slot, IPCHandlerFunction h, const bool sendReply=true)
Register a new IPC message action handler.
List< uint > & getCores()
Get list of core identities.
Represents a single Core in a Central Processing Unit (CPU).
Core::Result sendToMaster(CoreMessage *msg)
Send message to master.
MemoryChannel * m_toMaster
Core::Result bootAll()
Boot all processor cores.
Index< MemoryChannel, MaxCores > * m_fromSlave
virtual Core::Result sendIPI(uint coreId)=0
Send Inter-Processor-Interrupt.
void getCoreCount(CoreMessage *msg)
Get and fill the number of processor cores.
void createProcess(CoreMessage *msg)
Create a process on the current processor core.
virtual void waitIPI() const =0
Wait for Inter-Processor-Interrupt.
Memory::Range m_kernelImage
Core::Result loadKernel()
Load operating system kernel program.
virtual Result initialize()
Initialize the server.
ExecutableFormat * m_kernel
Index< MemoryChannel, MaxCores > * m_toSlave
int runCore()
Routine for the slave processor core.
Core::Result receiveFromMaster(CoreMessage *msg)
Receive message from master.
virtual Core::Result bootCore(uint coreId, CoreInfo *info)=0
Boot a processor core.
Core::Result unloadKernel()
Unload operating system kernel program.
Core::Result prepareCore(uint coreId, CoreInfo *info, ExecutableFormat::Region *regions)
Prepare processor core for booting.
virtual Core::Result discoverCores()=0
Discover processor cores.
Index< CoreInfo, MaxCores > * m_coreInfo
Core::Result sendToSlave(uint coreId, CoreMessage *msg)
Send message to slave.
Core::Result prepareCoreInfo()
Prepare the CoreInfo array.
Core::Result test()
Run a ping-pong test.
Core::Result receiveFromSlave(uint coreId, CoreMessage *msg)
Receive message from slave.
static const char * kernelPath
The default kernel for starting new cores.
MemoryChannel * m_fromMaster
static const Size MaxMessageRetry
Number of times to busy wait on receiving a message.
Core::Result clearPages(Address addr, Size size)
Clear memory pages with zeroes.
ExecutableFormat::Region m_regions[16]
Core::Result setupChannels()
Setup communication channels between CoreServers.
CoreServer()
Class constructor function.
Index is a N-sized array of pointers to items of type T.
virtual T * get(const Size position) const
Returns the item at the given position.
virtual bool insertAt(const Size position, T *item)
Inserts the given item at the given position.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Simple linked list template class.
Size count() const
Get the number of items on the list.
Decompress data using the LZ4 algorithm created by Yann Collet.
Result initialize()
Initialize the decompressor.
u64 getUncompressedSize() const
Get size of the uncompressed data.
Result read(void *buffer, const Size size) const
Reads compressed data.
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
Unidirectional point-to-point channel using shared memory.
Result setPhysical(const Address data, const Address feedback, const bool hardReset=true)
Set memory pages by physical address.
virtual Result flush()
Flush message buffers.
virtual Result read(void *buffer)
Read a message.
virtual Result write(const void *buffer)
Write a message.
static ChannelClient * instance()
Retrieve the instance.
API::Result VMCopy(const ProcessID proc, const API::Operation how, const Address ours, const Address theirs, const Size sz)
Prototype for user applications.
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
#define PAGESIZE
ARM uses 4K pages.
CoreInfo coreInfo
Local CoreInfo instance.
C size_t strlcpy(char *dst, const char *src, size_t siz)
Copy src to string dst of size siz.
C int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
C int close(int fildes)
Close a file descriptor.
#define O_RDONLY
Open for reading only.
ProcessID pid_t
Used for process IDs and process group IDs.
C ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file.
C int spawn(Address program, Size programSize, const char *argv[])
Create a new process using in-memory image.
C pid_t waitpid(pid_t pid, int *stat_loc, int options)
Wait for a child process to stop or terminate.
#define NULL
NULL means zero.
unsigned long Address
A memory address.
#define MegaByte(v)
Convert megabytes to bytes.
#define ERROR(msg)
Output an error message.
#define NOTICE(msg)
Output a notice message.
unsigned int uint
Unsigned integer number.
unsigned int Size
Any sane size indicator cannot go negative.
#define DEBUG(msg)
Output a debug message to standard output.
unsigned char u8
Unsigned 8-bit number.
Result
Result code for Actions.
Per-Core information structure.
uint timerCounter
Arch-specific timer counter.
Address bootImageSize
Boot image size in bytes.
Memory::Range kernel
Kernel memory range.
Size coreChannelSize
Size of the IPC channel in bytes.
uint coreId
Core identifier.
Address coreChannelAddress
Physical memory address of IPC channel for CoreServer of this core.
Address bootImageAddress
Boot image physical memory address.
Memory::Range memory
Defines the physical memory available to the core.
Size heapSize
Size in bytes of the kernel heap.
Address heapAddress
Physical memory address of the kernel heap.
Address kernelEntry
Kernel entry point.
char kernelCommand[KERNEL_PATHLEN]
Kernel command.
Message format for communication with the CoreServer.
Size programSize
Contains the size of a loaded program.
Size coreNumber
Indicates a number of cores or a specific coreId.
Core::Result result
Result code.
Core::Action action
Action to perform.
const char * programCmd
Command-line string for a loaded program.
Address programAddr
Contains the virtual address of a loaded program.
Size size
Size in number of bytes.
Address phys
Physical address.
Address virt
Virtual address.
Access access
Page access flags.
Message handler function (dummy) container.
const Func exec
Handler function.
const bool sendReply
Whether to send a reply or not.
The <sys/stat.h> header shall define the stat structure.
off_t st_size
For regular files, the file size in bytes.