Skip to content

Commit

Permalink
Added semi-syscalls!
Browse files Browse the repository at this point in the history
  • Loading branch information
pradosh-arduino committed Dec 31, 2023
1 parent 9bc4361 commit 41f2a9a
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ override LDFLAGS += \

# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
# object and header dependency file names.
override CFILES := $(shell find -L * -type f -name '*.c')
override CFILES := $(shell find -L kernel drivers -type f -name '*.c')

# These are disabled because we don't want plain assembly code which will break the compiler for diffrent arch.
override ASFILES := $(shell find -L * -type f -name '*.S')
override NASMFILES := $(shell find -L * -type f -name '*.asm')
override ASFILES := $(shell find -L kernel drivers -type f -name '*.S')
override NASMFILES := $(shell find -L kernel drivers -type f -name '*.asm')

override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
Expand Down
17 changes: 17 additions & 0 deletions source/frosted-dm/desktop-manager.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file desktop-manager.c
* @author Pradosh ([email protected])
* @brief This is the main separate ELF that will contain the desktop/window manager.
* @version 0.1
* @date 2023-12-31
*
* @copyright Copyright (c) Pradosh 2023
*
*/

void fdm_main(){
sys_print("hello for desktop-manager!");
while(1){

}
}
23 changes: 23 additions & 0 deletions source/frosted-dm/syscalls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file syscalls.c
* @author Pradosh ([email protected])
* @brief Contains the system calls for the kernel and desktop manager.
* @version 0.1
* @date 2023-12-31
*
* @copyright Copyright (c) Pradosh 2023
*
*/
#include <basics.h>
#include <syscalls.h>

void sys_print(const char* message) {
asm volatile (
"mov rax, %0\n\t"
"mov rbx, %1\n\t"
"int 0x80"
:
: "r"(sys_print), "r"(message)
: "rax", "rbx"
);
}
18 changes: 18 additions & 0 deletions source/includes/syscalls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file syscalls.h
* @author Pradosh ([email protected])
* @brief
* @version 0.1
* @date 2023-12-31
*
* @copyright Copyright (c) Pradosh 2023
*
*/
#include <basics.h>
#include <isr.h>

enum {
sys_print = 0,
};

void syscall_handler(InterruptFrame* frame, int syscall_number, ...);
3 changes: 3 additions & 0 deletions source/kernel/C/interrupts/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <keyboard.h>
#include <ps2-mouse.h>
#include <pit.h>
#include <syscalls.h>

extern void* isr_stub_table[];
extern void* irq_stub_table[];
Expand Down Expand Up @@ -66,6 +67,8 @@ void initIdt()
registerInterruptHandler(0x2C, process_mouse);
registerInterruptHandler(0x21, process_keyboard);

registerInterruptHandler(0x30, syscall_handler);

for (uint8_t i = 0; i < 32; i++)
{
setIdtEntry(&idt_entries[i], (uint64_t)isr_stub_table[i], 0x28, 0, 0x8E);
Expand Down
4 changes: 4 additions & 0 deletions source/kernel/C/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ void printf(cstring format, ...) {
case 's':
print(va_arg(argp, char*));
break;

case 'c':
putc(va_arg(argp, char));
break;
}
} else {
putc(*format);
Expand Down
22 changes: 22 additions & 0 deletions source/kernel/C/syscalls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file syscalls.c
* @author Pradosh ([email protected])
* @brief
* @version 0.1
* @date 2023-12-31
*
* @copyright Copyright (c) Pradosh 2023
*
*/
#include <syscalls.h>

void syscall_handler(InterruptFrame* frame, int syscall_number, ...) {
va_list argp;
va_start(argp, syscall_number);
switch (syscall_number) {
case sys_print:
print(va_arg(argp, string));
break;
}
va_end(argp);
}
33 changes: 33 additions & 0 deletions source/linker/desktop-manager/x86_64.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Tell the linker that we want an x86_64 ELF64 output file */
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)

/* We want the symbol main to be our entry point */
ENTRY(fdm_main)

SECTIONS
{
. = 0x100000;

.text : {
*(.text) /* Code */
*(.rodata) /* Read-only data */
}

.data : {
*(.data) /* Data */
}

.bss : {
*(.bss) /* Uninitialized data */
}

. = ALIGN(4096); /* Align the following section to a page boundary */

/* Other sections as needed */

/DISCARD/ : {
*(.comment)
*(.eh_frame)
}
}

0 comments on commit 41f2a9a

Please sign in to comment.