Skip to content

Commit

Permalink
Syscall to get info for bootloader loaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
coderarjob committed Dec 6, 2024
1 parent 3229e45 commit 6f74308
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
12 changes: 8 additions & 4 deletions include/cm/cm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ INT snprintf (CHAR* dest, size_t size, const CHAR* fmt, ...);
INT vsnprintf (CHAR* dest, size_t size, const CHAR* fmt, va_list l);

/***************************************************************************************************
* Halts thread for 'ms' miliseconds
*
* @return Nothing
**************************************************************************************************/
* Misc functions
***************************************************************************************************/
void cm_delay (UINT ms);

static inline void cm_get_bootloaded_file (const char* const filename,
OSIF_BootLoadedFiles* const out)
{
syscall (OSIF_SYSCALL_GET_BOOTLOADED_FILE, (U32)filename, (U32)out, 0, 0, 0);
}

/***************************************************************************************************
* Process management
***************************************************************************************************/
Expand Down
6 changes: 6 additions & 0 deletions include/cm/osif.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef enum OSIF_SYSCALLS {
OSIF_SYSCALL_WINDOW_GET_WINDOW_FB = 12,
OSIF_SYSCALL_WINDOW_FLUSH_GRAPHICS = 13,
OSIF_SYSCALL_GET_OS_ERROR = 14,
OSIF_SYSCALL_GET_BOOTLOADED_FILE = 15,
} OSIF_SYSCALLS;

typedef enum OSIF_ProcessEvents {
Expand All @@ -45,3 +46,8 @@ typedef struct OSIF_ProcessEvent {
OSIF_ProcessEvents event;
U64 data;
} OSIF_ProcessEvent;

typedef struct OSIF_BootLoadedFiles {
void* startLocation;
U16 length;
} OSIF_BootLoadedFiles;
29 changes: 29 additions & 0 deletions src/kernel/x86/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <handle.h>
#include <panic.h>
#include <cm/osif.h>
#if ARCH == x86
#include <x86/paging.h>
#include <x86/boot.h>
#endif

typedef struct SystemcallFrame {
U32 ebp;
Expand Down Expand Up @@ -51,6 +55,11 @@ bool ksys_getWindowFB (SystemcallFrame frame, Handle h, OSIF_WindowFrameBufferIn
void ksys_window_graphics_flush_all (SystemcallFrame frame);
#endif // GRAPHICS_MODE_ENABLED

#if ARCH == x86
void ksys_find_bootloaded_file (SystemcallFrame frame, const char* const filename,
OSIF_BootLoadedFiles* const file);
#endif // ARCH = x86

static U32 s_getSysCallCount();
static INT s_handleInvalidSystemCall();

Expand Down Expand Up @@ -95,6 +104,12 @@ void* g_syscall_table[] = {
#endif
//---------------------------
&sys_get_os_error, // 14
//---------------------------
#if ARCH == x86
&ksys_find_bootloaded_file, // 15
#else
&s_handleInvalidSystemCall, // 15
#endif
};
#pragma GCC diagnostic pop

Expand Down Expand Up @@ -370,3 +385,17 @@ void ksys_window_graphics_flush_all (SystemcallFrame frame)
kcompose_flush();
}
#endif // GRAPHICS_MODE_ENABLED

#if ARCH == x86
void ksys_find_bootloaded_file (SystemcallFrame frame, const char* const filename,
OSIF_BootLoadedFiles* const file)
{
FUNC_ENTRY ("Frame return address: %x:%x", frame.cs, frame.eip);
(void)frame;

BootFileItem fileinfo = kboot_findBootFileItem (filename);
file->length = fileinfo.length;
Physical start = PHYSICAL (fileinfo.startLocation);
file->startLocation = HIGHER_HALF_KERNEL_TO_VA (start);
}
#endif // ARCH = x86

0 comments on commit 6f74308

Please sign in to comment.