You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

73 lines
1.8 KiB

#include "headers/common.h"
#include "headers/screen.h"
#include <stdint.h>
void memcpy(void *dest, void *src, unsigned int n)
// Typecast src and dest addresses to (char *)
char *csrc = (char *)src;
char *cdest = (char *)dest;
// Copy contents of src[] to dest[]
for (unsigned int i=0; i<n; i++)
cdest[i] = csrc[i];
void memset(void *s, int c, unsigned int n)
unsigned char* p=s;
*p++ = (unsigned char)c;
unsigned char inb(unsigned short port) {
/* a handy c wrapper funciton that reads a byte from the specificed port
"=a" (result) means: put al register in variable RESULT when finished
"d" (port) means: load EDX with port */
unsigned char result;
__asm__("in al, dx" : "=a" (result) : "d" (port));
return result;
void outb(unsigned short port, unsigned char data) {
// "a" (data) means: load EAX with data
// "d" (port) means: load EDX with port
__asm__("out dx, al" : : "a" (data), "d" (port));
unsigned short inw(unsigned short port) {
unsigned short result;
__asm__("in ax, dx" : "=a" (result) : "d" (port));
return result;
void outw(unsigned short port, unsigned short data) {
__asm__("out dx, ax" : : "a" (data), "d" (port));
void panic(const char *message, const char *file, uint32_t line) {
// We encountered a massive problem and have to stop.
asm volatile("cli"); // Disable interrupts.
//Print stack trace
kprintf("PANIC(%s) at %s : %d\n",message,file,line);
void panic_assert(const char *file, uint32_t line, const char *desc) {
// An assertion failed, and we have to panic.
asm volatile("cli"); // Disable interrupts.
kprintf("ASSERTION-FAILED(%s) at %s : %d\n",desc,file,line);
// Halt by going into an infinite loop.