Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/includes/algorithms/hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void init_hashing(void);
* @param data The string to be hashed.
* @return [int64] Hashed value.
*/
int64 hash_string(string data);
int64 hash_string(cstring data);

/**
* @brief A function to hash a string from BARANIUM ENTERTAINMENT
Expand Down
5 changes: 4 additions & 1 deletion source/includes/cc-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ void high_level_halt(void);
* @brief Halt and catch fire function but doesn't print any text.
*
*/
void hcf2(void);
void hcf2(void);
void wrmsr64(uint32_t msr, uint64_t value);
uint64_t rdmsr64(uint32_t msr);
uint64_t rdtsc64(void);
2 changes: 1 addition & 1 deletion source/includes/executables/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef int64_t Elf64_Sxword;
#define R_X86_64_IRELATIVE 37

// Extract symbol and type from r_info
#define ELF64_R_SYM(info) ((info) >> 32)
#define ELF64_R_SYM(info) ((uint32_t)((info) >> 32))
#define ELF64_R_TYPE(info) ((uint32_t)(info))

// Program header
Expand Down
5 changes: 4 additions & 1 deletion source/includes/executables/fwde.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include <stdbool.h>
#include <graphics.h>
#include <isr.h>
#include <meltdown.h>
#include <cc-asm.h>

typedef struct {
char signature[5]; // 0xCD + 0x31 + FWDE
char signature[6]; // 0xCD + 0x31 + FWDE
int8 architecture; // 1 = 64 bits; 2 = 32 bits; 3 = 16 bits; 4 = 8 bits
int16 raw_size; // size of just the executable part and not the header
int8 endian; // 0 = error; 1 = little; 2 = big
Expand All @@ -31,5 +33,6 @@ typedef struct

typedef void(*entry_function)(kernel_data*);

bool verify_signature(const char* signature);
void process_IFL(InterruptFrame* frame);
void execute_fwde(int64* addr, kernel_data* data);
2 changes: 1 addition & 1 deletion source/includes/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ void print(cstring s);
* @param pixels
* @param color
*/
void print_bitmap(int x, int y, int w, int h, bool* pixels, int32 color);
void print_bitmap(int x, int y, int w, int h, const bool* pixels, int32 color);

#endif
1 change: 1 addition & 0 deletions source/includes/idt.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern void syscall_entry(void);
*/
void init_syscall(void);

void remap_pic(void);
void initIdt(void);
void setIdtEntry(IDTEntry *target, uint64_t offset, uint16_t selector, uint8_t ist, uint8_t type_attributes);

Expand Down
4 changes: 3 additions & 1 deletion source/includes/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ extern int64* wm_addr;
* @brief The main kernel function
* @attention main() to something else, make sure to change the linker script accordingly.
*/
void main(void);
void main(void);
void shutdown(void);
void reboot(void);
22 changes: 11 additions & 11 deletions source/includes/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
#include <hal.h>
#include <isr.h>

#define MOD_LCTRL 0b00000001
#define MOD_RCTRL 0b00000010
#define MOD_CTRL 0b00000011
#define MOD_LSHIFT 0b00000100
#define MOD_RSHIFT 0b00001000
#define MOD_SHIFT 0b01001100
#define MOD_LALT 0b00010000
#define MOD_RALT 0b00100000
#define MOD_ALT 0b00110000
#define MOD_CAPSLOCK 0b01000000
#define MOD_NUMLOCK 0b10000000
#define MOD_LCTRL 0x01U
#define MOD_RCTRL 0x02U
#define MOD_CTRL 0x03U
#define MOD_LSHIFT 0x04U
#define MOD_RSHIFT 0x08U
#define MOD_SHIFT 0x4CU
#define MOD_LALT 0x10U
#define MOD_RALT 0x20U
#define MOD_ALT 0x30U
#define MOD_CAPSLOCK 0x40U
#define MOD_NUMLOCK 0x80U

#define CUR_UP -1
#define CUR_DOWN -2
Expand Down
6 changes: 4 additions & 2 deletions source/includes/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <pci_id.h>

extern cstring display_adapter_name;
extern cstring GPUName[1]; //Max 2 GPUs allowed
extern string using_graphics_card;
extern cstring GPUName[2]; //Max 2 GPUs allowed
extern cstring using_graphics_card;
extern int64* graphics_base_Address;
extern int total_devices;

Expand Down Expand Up @@ -94,13 +94,15 @@ int16 getClassId(int16 bus, int16 device, int16 function);
* @return int16 Sub-class ID
*/
int16 getSubClassId(int16 bus, int16 device, int16 function);
int8 getRevision(int16 bus, int16 slot, int16 func);
int8 getProgIF(int16 bus, int16 device, int16 function);

/**
* @brief Scans (Probes) PCI Devices
*
*/
void probe_pci(void);
void print_lspci(void);

/**
* @brief Function to read a 32-bit value from the PCI configuration space
Expand Down
4 changes: 2 additions & 2 deletions source/includes/pci_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ typedef struct {
* @param vendor vendor id
* @return string vendor name
*/
string parse_vendor(int16 vendor);
cstring parse_vendor(int16 vendor);

/**
* @brief Gets the class id and gives the appropriate class name.
*
* @param classid class id
* @return string class name
*/
string parse_class(int16 classid);
cstring parse_class(int16 classid);

/**
* @brief A Simplified and clean PCI lookup function.
Expand Down
4 changes: 3 additions & 1 deletion source/includes/pit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
*
* @param frame
*/
void process_pit(InterruptFrame* frame);
void process_pit(InterruptFrame* frame);
void init_pit(void);
void pit_sleep(uint32_t milliseconds);
17 changes: 9 additions & 8 deletions source/includes/ps2-mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include <isr.h>
#include <hal.h>

#define PS2_left_button 0b00000001
#define PS2_middle_button 0b00000100
#define PS2_right_button 0b00000010
#define PS2_x 0b00010000
#define PS2_y 0b00100000
#define PS2_x_overflow 0b01000000
#define PS2_y_overflow 0b10000000
#define PS2_left_button 0x01U
#define PS2_middle_button 0x04U
#define PS2_right_button 0x02U
#define PS2_x 0x10U
#define PS2_y 0x20U
#define PS2_x_overflow 0x40U
#define PS2_y_overflow 0x80U

#define MOUSE_BUTTON_LEFT PS2_left_button
#define MOUSE_BUTTON_RIGHT PS2_right_button
Expand Down Expand Up @@ -85,4 +85,5 @@ ivec2 GetLastMousePosition(void);
*
* @param frame
*/
void process_mouse(InterruptFrame* frame);
void process_mouse(InterruptFrame* frame);
void init_ps2_mouse(void);
1 change: 1 addition & 0 deletions source/includes/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <basics.h>
#include <graphics.h>
#include <hal.h>

// I/O ports for RTC
#define RTC_PORT 0x70
Expand Down
2 changes: 1 addition & 1 deletion source/includes/sh_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ void execute(const char* buffer, int argc, char** argv);
*/
void user_main(char* buffer);

#endif
#endif
4 changes: 3 additions & 1 deletion source/includes/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @param s The input string.
* @return The length of the string.
*/
int strlen(char s[]);
int strlen(cstring s);

/**
* @brief Copies a string from `src` to `dest`
Expand Down Expand Up @@ -192,3 +192,5 @@ char* trim_inplace(char* s);

char* strrchr(const char* s, int c);
char* strdup(const char* str);

int itoa(int num, string str, int len, int base);
15 changes: 8 additions & 7 deletions source/kernel/C/acpi-shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stddef.h>
#include <stdint.h>
#include <acpi-shutdown.h>
#include <hal.h>

struct facp {
char signature[4];
Expand Down Expand Up @@ -59,7 +60,7 @@ static inline int8 parse_integer(int8* s5_addr, int64* value) {
return 9; // 1 Type Byte, 8 Data Bytes

case 0xFF: // OnesOp
*value = ~0;
*value = UINT64_MAX;
return 1; // 1 Op Byte

default:
Expand Down Expand Up @@ -98,30 +99,30 @@ int acpi_shutdown_hack(uintptr_t direct_map_base, void *(*find_sdt)(cstring sign
if (size == 0) // Wasn't able to parse it
return -1;

int16 SLP_TYPa = value << 10;
int16 SLP_TYPa = (int16)((value & 0x7ULL) << 10);
s5_addr += size;


size = parse_integer(s5_addr, &value);
if (size == 0) // Wasn't able to parse it
return -1;

int16 SLP_TYPb = value << 10;
int16 SLP_TYPb = (int16)((value & 0x7ULL) << 10);
s5_addr += size;

if(facp->SMI_CMD != 0 && facp->ACPI_ENABLE != 0) { // This PC has SMM and we need to enable ACPI mode first
outb(facp->SMI_CMD, facp->ACPI_ENABLE);
outb((int16)facp->SMI_CMD, facp->ACPI_ENABLE);
for (int i = 0; i < 100; i++)
inb(0x80);

while (!inw(facp->PM1a_CNT_BLK) & (1 << 0))
while ((inw((int16)facp->PM1a_CNT_BLK) & 1U) == 0U)
;
}


outw(facp->PM1a_CNT_BLK, SLP_TYPa | (1 << 13));
outw((int16)facp->PM1a_CNT_BLK, (int16)(SLP_TYPa | (1U << 13)));
if (facp->PM1b_CNT_BLK)
outw(facp->PM1b_CNT_BLK, SLP_TYPb | (1 << 13));
outw((int16)facp->PM1b_CNT_BLK, (int16)(SLP_TYPb | (1U << 13)));

for (int i = 0; i < 100; i++)
inb(0x80);
Expand Down
14 changes: 7 additions & 7 deletions source/kernel/C/algorithms/hashing.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <algorithms/hashing.h>

void init_hashing(void){
string data = "PradoshGame";
cstring data = "PradoshGame";
int64 hash = hash_string(data);

if(hash == (int64)0x393e7fd){
Expand All @@ -22,23 +22,23 @@ void init_hashing(void){
}
}

int64 hash_string(string data){
int hash = 0;
int64 hash_string(cstring data){
int64 hash = 0;
while(*data){
hash += *data++;
hash += (uint8_t)*data++;
if(*data)
hash *= *data++;
hash *= (uint8_t)*data++;
}
return hash;
}

int64 baranium_hash(const char* name)
{
int64 identifier = 9780;
size_t length = strlen(name);
size_t length = (size_t)strlen(name);
for (size_t i = 0; i < length; i++)
{
char c = name[i];
uint8_t c = (uint8_t)name[i];
identifier = ((identifier << 5) + identifier) + c;
}
return (int64)identifier;
Expand Down
34 changes: 29 additions & 5 deletions source/kernel/C/executables/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ static uint32_t* elf_vfs_pos_ptr(vfs_file_t* file)
return &file->f.fat32.pos;
case FS_ISO9660:
return &file->f.iso9660.pos;
case FS_UNKNOWN:
case FS_FAT12:
case FS_EXFAT:
case FS_EXT2:
case FS_EXT3:
case FS_EXT4:
case FS_XFS:
case FS_BTRFS:
case FS_NTFS:
case FS_UDF:
case FS_PROC:
case FS_DEV:
default:
return NULL;
}
Expand Down Expand Up @@ -110,7 +122,7 @@ static int elf_load_tls_template_from_memory(void* file_base_address, uint64_t f
return 0;
}

static int elf_load_tls_template_from_vfs(const char* path, elf_image_info_t* info)
__attribute__((unused)) static int elf_load_tls_template_from_vfs(const char* path, elf_image_info_t* info)
{
if (!info || info->tls_filesz == 0)
return 0;
Expand Down Expand Up @@ -351,7 +363,7 @@ static uint64_t elf_runtime_addr_for_offset(Elf64_Phdr* headers, uint16_t phnum,
return 0;
}

static void elf_log_load_progress(uint16_t current, uint16_t total, Elf64_Phdr* ph)
__attribute__((unused)) static void elf_log_load_progress(uint16_t current, uint16_t total, Elf64_Phdr* ph)
{
if (!total)
return;
Expand Down Expand Up @@ -448,7 +460,7 @@ static int elf_map_program_header(Elf64_Phdr* ph, void* file_base, uint64_t file
return 0;
}

static int elf_map_program_header_from_vfs(Elf64_Phdr* ph, const char* path, uint64_t file_size, uint16_t seg_index, uint64_t load_bias)
__attribute__((unused)) static int elf_map_program_header_from_vfs(Elf64_Phdr* ph, const char* path, uint64_t file_size, uint16_t seg_index, uint64_t load_bias)
{
if (ph->p_type != PT_LOAD)
return 0;
Expand Down Expand Up @@ -531,7 +543,7 @@ void* elf_load_from_memory_ex(void* file_base_address, uint64_t file_size, elf_i
return NULL;

uint8_t* file_ptr = file_base_address;
Elf64_Ehdr header = {};
Elf64_Ehdr header = {0};
memcpy(&header, file_ptr, sizeof(Elf64_Ehdr));

if (elf_validate_header(&header, file_size) != 0)
Expand Down Expand Up @@ -599,6 +611,18 @@ void* elf_load_from_vfs_ex(const char* path, elf_image_info_t* info)
case FS_ISO9660:
size = file.f.iso9660.entry.size;
break;
case FS_UNKNOWN:
case FS_FAT12:
case FS_EXFAT:
case FS_EXT2:
case FS_EXT3:
case FS_EXT4:
case FS_XFS:
case FS_BTRFS:
case FS_NTFS:
case FS_UDF:
case FS_PROC:
case FS_DEV:
default:
vfs_close(&file);
return NULL;
Expand All @@ -609,7 +633,7 @@ void* elf_load_from_vfs_ex(const char* path, elf_image_info_t* info)
return NULL;
}

Elf64_Ehdr header = {};
Elf64_Ehdr header = {0};
if (elf_vfs_read_exact(&file, 0, &header, sizeof(header)) != 0) {
eprintf("elf: failed to read header");
vfs_close(&file);
Expand Down
Loading