Go to the documentation of this file.
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);
virtual Core::Result bootCore(uint coreId, CoreInfo *info)=0
Boot a processor core.
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCount > m_ipcHandlers
IPC handler functions.
size_t strlcpy(char *dst, const char *src, size_t siz)
Copy src to string dst of size siz.
off_t st_size
For regular files, the file size in bytes.
The <sys/stat.h> header shall define the stat structure.
void createProcess(CoreMessage *msg)
Create a process on the current processor core.
virtual bool insertAt(const Size position, T *item)
Inserts the given item at the given position.
static ChannelClient * instance()
Retrieve the instance.
MemoryChannel * m_fromMaster
Result
Enumeration of generic kernel API result codes.
Core::Result unloadKernel()
Unload operating system kernel program.
Address programAddr
Contains the virtual address of a loaded program.
Index< CoreInfo, MaxCores > * m_coreInfo
#define NOTICE(msg)
Output a notice message.
Message format for communication with the CoreServer.
Core::Result prepareCoreInfo()
Prepare the CoreInfo array.
Address bootImageSize
Boot image size in bytes.
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
Result setPhysical(const Address data, const Address feedback, const bool hardReset=true)
Set memory pages by physical address.
Memory::Range m_kernelImage
Address heapAddress
Physical memory address of the kernel heap.
u64 getUncompressedSize() const
Get size of the uncompressed data.
#define PAGESIZE
ARM uses 4K pages.
virtual Result initialize()
Initialize the server.
Core::Result loadKernel()
Load operating system kernel program.
Core::Result sendToSlave(uint coreId, CoreMessage *msg)
Send message to slave.
Type type
Message type is either a request or response.
Result initialize()
Initialize the decompressor.
int runCore()
Routine for the slave processor core.
unsigned long Address
A memory address.
int run()
Enters an infinite loop, serving incoming requests.
Memory::Range memory
Defines the physical memory available to the core.
Core::Result result
Result code.
Size count() const
Get the number of items on the list.
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Address coreChannelAddress
Physical memory address of IPC channel for CoreServer of this core.
int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
const bool sendReply
Whether to send a reply or not.
ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file.
Core::Action action
Action to perform.
unsigned int uint
Unsigned integer number.
Index< MemoryChannel, MaxCores > * m_toSlave
virtual void waitIPI() const =0
Wait for Inter-Processor-Interrupt.
uint coreId
Core identifier.
#define MegaByte(v)
Convert megabytes to bytes.
const Func exec
Handler function.
Represents a single Core in a Central Processing Unit (CPU).
struct CoreInfo CoreInfo
Per-Core information structure.
ExecutableFormat * m_kernel
#define DEBUG(msg)
Output a debug message to standard output.
char kernelCommand[KERNEL_PATHLEN]
Kernel command.
CoreServer()
Class constructor function.
Address phys
Physical address.
int close(int fildes)
Close a file descriptor.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Core::Result bootAll()
Boot all processor cores.
Address kernelEntry
Kernel entry point.
const char * programCmd
Command-line string for a loaded program.
Size coreNumber
Indicates a number of cores or a specific coreId.
virtual Core::Result discoverCores()=0
Discover processor cores.
virtual Result syncSendTo(const void *buffer, const Size msgSize, const ProcessID pid)
Synchronous send to one process.
Core::Result clearPages(Address addr, Size size)
Clear memory pages with zeroes.
#define NULL
NULL means zero.
unsigned int Size
Any sane size indicator cannot go negative.
Size programSize
Contains the size of a loaded program.
virtual Result write(const void *buffer)
Write a message.
void getCoreCount(CoreMessage *msg)
Get and fill the number of processor cores.
Address bootImageAddress
Boot image physical memory address.
Unidirectional point-to-point channel using shared memory.
virtual T * get(const Size position) const
Returns the item at the given position.
int stat(const char *path, struct stat *buf)
Get file status.
Core::Result setupChannels()
Setup communication channels between CoreServers.
ProcessID pid_t
Used for process IDs and process group IDs.
virtual Result flush()
Flush message buffers.
virtual Result read(void *buffer)
Read a message.
Per-Core information structure.
Result
Result code for Actions.
CoreInfo coreInfo
Local CoreInfo instance.
Index< MemoryChannel, MaxCores > * m_fromSlave
uint timerCounter
Arch-specific timer counter.
Template class which serves incoming messages from Channels using MessageHandlers.
Result read(void *buffer, const Size size) const
Reads compressed data.
#define ERROR(msg)
Output an error message.
unsigned char u8
Unsigned 8-bit number.
Size coreChannelSize
Size of the IPC channel in bytes.
Decompress data using the LZ4 algorithm created by Yann Collet.
Memory::Range kernel
Kernel memory range.
Core::Result test()
Run a ping-pong test.
int spawn(Address program, Size programSize, const char *argv[])
Create a new process using in-memory image.
List< uint > & getCores()
Get list of core identities.
ProcessID from
Source process of the message.
void addIPCHandler(const Size slot, IPCHandlerFunction h, const bool sendReply=true)
Register a new IPC message action handler.
Core::Result prepareCore(uint coreId, CoreInfo *info, ExecutableFormat::Region *regions)
Prepare processor core for booting.
Core::Result sendToMaster(CoreMessage *msg)
Send message to master.
Address virt
Virtual address.
static const Size MaxMessageRetry
Number of times to busy wait on receiving a message.
static const char * kernelPath
The default kernel for starting new cores.
pid_t waitpid(pid_t pid, int *stat_loc, int options)
Wait for a child process to stop or terminate.
Size heapSize
Size in bytes of the kernel heap.
virtual Core::Result sendIPI(uint coreId)=0
Send Inter-Processor-Interrupt.
API::Result VMCopy(const ProcessID proc, const API::Operation how, const Address ours, const Address theirs, const Size sz)
Prototype for user applications.
Size size
Size in number of bytes.
Access access
Page access flags.
MemoryChannel * m_toMaster
Core::Result receiveFromSlave(uint coreId, CoreMessage *msg)
Receive message from slave.
Core::Result receiveFromMaster(CoreMessage *msg)
Receive message from master.
#define O_RDONLY
Open for reading only.
ExecutableFormat::Region m_regions[16]