Skip to content

Commit

Permalink
Added semi-working kernel-data.
Browse files Browse the repository at this point in the history
  • Loading branch information
pradosh-arduino committed Jan 13, 2024
1 parent a8c6e90 commit 2c6843d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
18 changes: 11 additions & 7 deletions source/desktop-manager/dm_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

#include <basics.h> // Avoid headers from kernel, this header contains just some basic macros.

// int64* fb_addr = null;
// int64* font_addr = null;
// int64 width = 0;
// int64 height = 0;
// int64 pitch = 0;
typedef struct
{
int64* fb_addr;
int64 width;
int64 height;
int64 pitch;
void (*print)(cstring msg);
} kernel_data ;

/*
* Example syscall usage
Expand All @@ -30,15 +33,16 @@ Replace [SYSCALL ID] to appropriate syscall numbers.
void send_alive_msg(){
asm volatile("movq %0, %%rax" :: "r"((int64)0x3));
asm volatile("int $0x80");
asm volatile("movq %0, %%rax" :: "r"((int64)0x0)); // ! Always revert the RAX register after an syscall
}

/**
* @attention Don't rename this function, if you wanted to rename it, u must change the linker also.
*
*/
int dw_main(){
int dw_main(kernel_data* data){
send_alive_msg();

data->print("hello from desktop-manager!");

return 0; // status code
}
13 changes: 12 additions & 1 deletion source/includes/executables/fwde.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#include <basics.h>
#include <stdbool.h>
#include <graphics.h>

typedef struct {
char signature[4]; // FWDE
Expand All @@ -18,4 +19,14 @@ typedef struct {
int8 endian; // 0 = error; 1 = little; 2 = big
} fwde_header;

void execute_fwde(int64* addr);
typedef struct
{
int64* fb_addr;
int64 width;
int64 height;
int64 pitch;
void (*print)(cstring msg);
} kernel_data ;


void execute_fwde(int64* addr, kernel_data* data);
19 changes: 7 additions & 12 deletions source/kernel/C/executables/fwde.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool verify_signature(char* signature){
return false;
}

void execute_fwde(int64* addr){
void execute_fwde(int64* addr, kernel_data* data){
info("Verifying the FrostWing deployed executable!", __FILE__);

int8* local = (int8*)addr;
Expand All @@ -47,18 +47,13 @@ void execute_fwde(int64* addr){
info("Valid executable! and ready for execution!", __FILE__);
}
info("Starting executing the FrostWing deployed executable...", __FILE__);
unsigned long long instruction_count_start, instruction_count_end;
int (*execute_binary)() = (int (*)())local;

typedef void(*EntryFunction)(kernel_data*);
EntryFunction execute_binary = (EntryFunction)local;

info("Function is ready!", __FILE__);
asm volatile ("rdtsc" : "=A" (instruction_count_start));
int status_code = execute_binary();
asm volatile ("rdtsc" : "=A" (instruction_count_end));
printf("Instructions executed: %u", instruction_count_end - instruction_count_start);
if(status_code != 0){
error("Executable returned an non zero status code! (something went wrong on the executable side)", __FILE__);
printf("Status code : 0x%x (%d)", status_code, status_code);
return;
}

execute_binary(data);
}else{
error("Unsupported architecture!", __FILE__);
return;
Expand Down
10 changes: 9 additions & 1 deletion source/kernel/C/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,15 @@ void main(void) {

font_address = module_request.response->modules[1]->address;

execute_fwde(module_request.response->modules[2]->address);
kernel_data* data = (kernel_data*) malloc(sizeof(kernel_data));
data->fb_addr = framebuffer->address;
data->width = framebuffer->width;
data->height = framebuffer->height;
data->pitch = framebuffer->pitch;
data->print = print;
execute_fwde(module_request.response->modules[2]->address, data);

free(data);

print("press F10 for (ACPI) Shutdown.\n");
print("press F9 for (ACPI/Hard) Reboot/Reset.\n");
Expand Down

0 comments on commit 2c6843d

Please sign in to comment.