From c552e25bd777e400785832e824e5c275b7dec811 Mon Sep 17 00:00:00 2001 From: David Aylaian Date: Fri, 30 Jun 2017 04:32:16 -0400 Subject: [PATCH] Add C sample (#3698) * Add C sample Sample was incorrectly being identified as C++ * Changed asm.h license to the Unlicense * Changed asm.h license to Apache 2.0 --- samples/C/asm.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 samples/C/asm.h diff --git a/samples/C/asm.h b/samples/C/asm.h new file mode 100644 index 00000000..aa0e5f86 --- /dev/null +++ b/samples/C/asm.h @@ -0,0 +1,27 @@ +/* CarbonOS System/Kernel + * Copyright 2015-2017 David Aylaian + * Licensed under Apache 2.0: https://github.com/DavidAylaian/CarbonOS/blob/master/LICENSE.md + */ + +#ifndef ASM_H +#define ASM_H + +#include + +// macros for enabling and disabling interrupts +#define enable() asm("sti"); +#define disable() asm("cli"); + +// inb instruction +uint8_t inb (uint16_t port) { + uint8_t val; + asm volatile ("inb %0, %1" : "=a"(val): "Nd"(port)); + return val; +} + +// outb instruction +void outb (uint16_t port, uint8_t val) { + asm volatile ("outb %1, %0" : : "a"(val), "Nd"(port)); +} + +#endif