[core] Some extra macros to make life easier
This commit is contained in:
parent
f2b745faa9
commit
e604e4d655
@ -21,12 +21,12 @@ cmos_dump(
|
||||
uint16_t * values
|
||||
) {
|
||||
uint16_t index;
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
for (index = 0; index < 128; ++index) {
|
||||
outportb(0x70, index);
|
||||
values[index] = inportb(0x71);
|
||||
}
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ int do_intel(void);
|
||||
int do_amd(void);
|
||||
void printregs(int eax, int ebx, int ecx, int edx);
|
||||
|
||||
#define cpuid(in, a, b, c, d) __asm__("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
|
||||
#define cpuid(in, a, b, c, d) asm("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
|
||||
|
||||
/* Simply call this function detect_cpu(); */
|
||||
int detect_cpu(void) { /* or main() if your trying to port this as an independant application */
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
void
|
||||
set_fpu_cw(const uint16_t cw) {
|
||||
__asm__ __volatile__("fldcw %0" :: "m"(cw));
|
||||
asm volatile("fldcw %0" :: "m"(cw));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,9 +28,9 @@ set_fpu_cw(const uint16_t cw) {
|
||||
void
|
||||
enable_fpu() {
|
||||
size_t cr4;
|
||||
__asm__ __volatile__ ("mov %%cr4, %0" : "=r"(cr4));
|
||||
asm volatile ("mov %%cr4, %0" : "=r"(cr4));
|
||||
cr4 |= 0x200;
|
||||
__asm__ __volatile__ ("mov %0, %%cr4" :: "r"(cr4));
|
||||
asm volatile ("mov %0, %%cr4" :: "r"(cr4));
|
||||
set_fpu_cw(0x37F);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ void ide_detect() {
|
||||
}
|
||||
|
||||
void ide_read_sector(uint16_t bus, uint8_t slave, uint32_t lba, char * buf) {
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
outportb(bus + ATA_REG_FEATURES, 0x00);
|
||||
outportb(bus + ATA_REG_SECCOUNT0, 1);
|
||||
outportb(bus + ATA_REG_HDDEVSEL, 0xe0 | slave << 4 |
|
||||
@ -34,11 +34,11 @@ void ide_read_sector(uint16_t bus, uint8_t slave, uint32_t lba, char * buf) {
|
||||
buf[i+1] = (s & 0xFF00) >> 8;
|
||||
}
|
||||
outportb(0x177, 0xe7);
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
}
|
||||
|
||||
void ide_write_sector(uint16_t bus, uint8_t slave, uint32_t lba, char * buf) {
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
outportb(bus + ATA_REG_FEATURES, 0x00);
|
||||
outportb(bus + ATA_REG_SECCOUNT0, 1);
|
||||
outportb(bus + ATA_REG_HDDEVSEL, 0xe0 | slave << 4 |
|
||||
@ -55,5 +55,5 @@ void ide_write_sector(uint16_t bus, uint8_t slave, uint32_t lba, char * buf) {
|
||||
}
|
||||
outportb(bus + 0x07, ATA_CMD_CACHE_FLUSH);
|
||||
outportb(0x177, 0xe7);
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void
|
||||
irq_install() {
|
||||
irq_remap();
|
||||
irq_gates();
|
||||
__asm__ __volatile__("sti");
|
||||
IRQ_ON;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -182,7 +182,7 @@ kgets(
|
||||
keyboard_buffer_handler = kgets_handler;
|
||||
while ((kgets_collected < size) && (!kgets_newline)) {
|
||||
/* Wait until the buffer is ready */
|
||||
__asm__ __volatile__ ("hlt");
|
||||
PAUSE;
|
||||
}
|
||||
/* Fix any missing nulls */
|
||||
buffer[kgets_collected] = '\0';
|
||||
|
@ -230,11 +230,11 @@ switch_page_directory(
|
||||
page_directory_t * dir
|
||||
) {
|
||||
current_directory = dir;
|
||||
__asm__ __volatile__ ("mov %0, %%cr3":: "r"(dir->physical_address));
|
||||
asm volatile ("mov %0, %%cr3":: "r"(dir->physical_address));
|
||||
uint32_t cr0;
|
||||
__asm__ __volatile__ ("mov %%cr0, %0": "=r"(cr0));
|
||||
asm volatile ("mov %%cr0, %0": "=r"(cr0));
|
||||
cr0 |= 0x80000000;
|
||||
__asm__ __volatile__ ("mov %0, %%cr0":: "r"(cr0));
|
||||
asm volatile ("mov %0, %%cr0":: "r"(cr0));
|
||||
}
|
||||
|
||||
page_t *
|
||||
@ -262,7 +262,7 @@ void
|
||||
page_fault(
|
||||
struct regs *r) {
|
||||
uint32_t faulting_address;
|
||||
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
|
||||
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
|
||||
|
||||
int present = !(r->err_code & 0x1);
|
||||
int rw = r->err_code & 0x2;
|
||||
|
@ -5,13 +5,13 @@ void kernel_halt() {
|
||||
kprintf("\n \x13 System Halted!\n\n");
|
||||
|
||||
while (1) {
|
||||
__asm__ __volatile__ ("cli");
|
||||
__asm__ __volatile__ ("hlt");
|
||||
IRQ_OFF;
|
||||
PAUSE;
|
||||
}
|
||||
}
|
||||
|
||||
void halt_and_catch_fire(char * error_message, const char * file, int line, struct regs * regs) {
|
||||
__asm__ __volatile__("cli");
|
||||
IRQ_OFF;
|
||||
settextcolor(0,11);
|
||||
kprintf("Process %d did a dumb.\n", getpid());
|
||||
kprintf("PANIC! %s\n", error_message);
|
||||
@ -33,7 +33,7 @@ void halt_and_catch_fire(char * error_message, const char * file, int line, stru
|
||||
}
|
||||
|
||||
void assert_failed(const char *file, uint32_t line, const char *desc) {
|
||||
__asm__ __volatile__("cli");
|
||||
IRQ_OFF;
|
||||
settextcolor(14,3);
|
||||
kprintf("Kernel Assertion Failed: %s\n", desc);
|
||||
kprintf("File: %s\n", file);
|
||||
|
48
kernel/core/pci.c
Normal file
48
kernel/core/pci.c
Normal file
@ -0,0 +1,48 @@
|
||||
/* vim: noexpandtab tabstop=4 shiftwidth=4
|
||||
*
|
||||
* ToAruOS PCI Initialization
|
||||
*/
|
||||
|
||||
#include <system.h>
|
||||
|
||||
void
|
||||
pci_install() {
|
||||
/* No op */
|
||||
}
|
||||
|
||||
#define PCI_CONFIG_ADDRESS 0xCF8
|
||||
#define PCI_CONFIG_DATA 0xCFC
|
||||
|
||||
/*
|
||||
* Read a PCI config value for the given bus/slot/function/offset
|
||||
*/
|
||||
uint16_t
|
||||
pci_read_word(
|
||||
uint32_t bus,
|
||||
uint32_t slot,
|
||||
uint32_t func,
|
||||
uint16_t offset
|
||||
) {
|
||||
uint32_t address = (uint32_t)((bus << 16) || (slot << 11) |
|
||||
(func << 8) | (offset & 0xFC) | ((uint32_t)0x80000000));
|
||||
outportl(PCI_CONFIG_ADDRESS, address);
|
||||
return (uint16_t)((inportl(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a PCI config value for the given bus/slot/function/offset
|
||||
*/
|
||||
void
|
||||
pci_write_word(
|
||||
uint32_t bus,
|
||||
uint32_t slot,
|
||||
uint32_t func,
|
||||
uint16_t offset,
|
||||
uint32_t data
|
||||
) {
|
||||
uint32_t address = (uint32_t)((bus << 16) || (slot << 11) |
|
||||
(func << 8) | (offset & 0xFC) | ((uint32_t)0x80000000));
|
||||
outportl(PCI_CONFIG_ADDRESS, address);
|
||||
outportl(PCI_CONFIG_DATA, data);
|
||||
}
|
||||
|
@ -112,6 +112,9 @@ start_shell() {
|
||||
i++;
|
||||
entry = readdir_fs(node, i);
|
||||
}
|
||||
} else if (!strcmp(cmd, "reset")) {
|
||||
while (inportb(0x64) & 0x10);
|
||||
outportb(0x64,0xFE);
|
||||
} else if (!strcmp(cmd, "out")) {
|
||||
if (tokenid < 3) {
|
||||
kprintf("Need a port and a character (both as numbers, please) to write...\n");
|
||||
|
@ -41,9 +41,9 @@ static int exit(int retval) {
|
||||
static int read(int fd, char * ptr, int len) {
|
||||
#ifdef SPECIAL_CASE_STDIO
|
||||
if (fd == 0) {
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
kgets(ptr, len);
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
if (strlen(ptr) < len) {
|
||||
int j = strlen(ptr);
|
||||
ptr[j] = '\n';
|
||||
@ -156,7 +156,7 @@ static int kbd_mode(int mode) {
|
||||
|
||||
static int kbd_get() {
|
||||
/* If we're requesting keyboard input, we better damn well be getting it */
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
char x = kbd_last;
|
||||
kbd_last = 0;
|
||||
return (int)x;
|
||||
@ -229,7 +229,7 @@ syscall_handler(
|
||||
uintptr_t location = syscalls[r->eax];
|
||||
|
||||
uint32_t ret;
|
||||
__asm__ __volatile__ (
|
||||
asm volatile (
|
||||
"push %1\n"
|
||||
"push %2\n"
|
||||
"push %3\n"
|
||||
|
@ -15,7 +15,7 @@ memcpy(
|
||||
const void * restrict src,
|
||||
size_t count
|
||||
) {
|
||||
__asm__ __volatile__ ("cld; rep movsb" : "+c" (count), "+S" (src), "+D" (dest) :: "memory");
|
||||
asm volatile ("cld; rep movsb" : "+c" (count), "+S" (src), "+D" (dest) :: "memory");
|
||||
return dest;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ memset(
|
||||
int val,
|
||||
size_t count
|
||||
) {
|
||||
__asm__ __volatile__ ("cld; rep stosb" : "+c" (count), "+D" (b) : "a" (val) : "memory");
|
||||
asm volatile ("cld; rep stosb" : "+c" (count), "+D" (b) : "a" (val) : "memory");
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ inports(
|
||||
unsigned short _port
|
||||
) {
|
||||
unsigned short rv;
|
||||
__asm__ __volatile__ ("inw %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
asm volatile ("inw %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ outports(
|
||||
unsigned short _port,
|
||||
unsigned short _data
|
||||
) {
|
||||
__asm__ __volatile__ ("outw %1, %0" : : "dN" (_port), "a" (_data));
|
||||
asm volatile ("outw %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
||||
unsigned int
|
||||
@ -178,7 +178,7 @@ inportl(
|
||||
unsigned short _port
|
||||
) {
|
||||
unsigned short rv;
|
||||
__asm__ __volatile__ ("inl %%dx, %%eax" : "=a" (rv) : "dN" (_port));
|
||||
asm volatile ("inl %%dx, %%eax" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ outportl(
|
||||
unsigned short _port,
|
||||
unsigned int _data
|
||||
) {
|
||||
__asm__ __volatile__ ("outl %%eax, %%dx" : : "dN" (_port), "a" (_data));
|
||||
asm volatile ("outl %%eax, %%dx" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +200,7 @@ inportb(
|
||||
unsigned short _port
|
||||
) {
|
||||
unsigned char rv;
|
||||
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
asm volatile ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ outportb(
|
||||
unsigned short _port,
|
||||
unsigned char _data
|
||||
) {
|
||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
asm volatile ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include <system.h>
|
||||
#define KERNEL_STACK_SIZE 0x2000
|
||||
|
||||
__volatile__ task_t * current_task = NULL;
|
||||
__volatile__ task_t * ready_queue = NULL;
|
||||
volatile task_t * current_task = NULL;
|
||||
volatile task_t * ready_queue = NULL;
|
||||
|
||||
uint32_t next_pid = 0;
|
||||
|
||||
@ -61,7 +61,7 @@ clone_table(
|
||||
|
||||
void
|
||||
tasking_install() {
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
|
||||
current_task = (task_t *)kmalloc(sizeof(task_t));
|
||||
ready_queue = current_task;
|
||||
@ -78,7 +78,7 @@ tasking_install() {
|
||||
|
||||
//switch_page_directory(current_task->page_directory);
|
||||
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
}
|
||||
|
||||
task_t *
|
||||
@ -94,7 +94,7 @@ gettask(
|
||||
|
||||
uint32_t
|
||||
fork() {
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
task_t * parent = (task_t *)current_task;
|
||||
page_directory_t * directory = clone_directory(current_directory);
|
||||
task_t * new_task = (task_t *)kmalloc(sizeof(task_t));
|
||||
@ -126,8 +126,8 @@ fork() {
|
||||
if (current_task == parent) {
|
||||
uintptr_t esp;
|
||||
uintptr_t ebp;
|
||||
__asm__ __volatile__ ("mov %%esp, %0" : "=r" (esp));
|
||||
__asm__ __volatile__ ("mov %%ebp, %0" : "=r" (ebp));
|
||||
asm volatile ("mov %%esp, %0" : "=r" (esp));
|
||||
asm volatile ("mov %%ebp, %0" : "=r" (ebp));
|
||||
if (current_task->stack > new_task->stack) {
|
||||
new_task->esp = esp - (current_task->stack - new_task->stack);
|
||||
new_task->ebp = ebp - (current_task->stack - new_task->stack);
|
||||
@ -138,7 +138,7 @@ fork() {
|
||||
// kprintf("old: %x new: %x; end: %x %x\n", esp, new_task->esp, current_task->stack, new_task->stack);
|
||||
memcpy((void *)(new_task->stack - KERNEL_STACK_SIZE), (void *)(current_task->stack - KERNEL_STACK_SIZE), KERNEL_STACK_SIZE);
|
||||
new_task->eip = eip;
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
return new_task->id;
|
||||
} else {
|
||||
return 0;
|
||||
@ -158,11 +158,11 @@ switch_task() {
|
||||
if (!current_task->next && current_task == ready_queue) return;
|
||||
|
||||
uintptr_t esp, ebp, eip;
|
||||
__asm__ __volatile__ ("mov %%esp, %0" : "=r" (esp));
|
||||
__asm__ __volatile__ ("mov %%ebp, %0" : "=r" (ebp));
|
||||
asm volatile ("mov %%esp, %0" : "=r" (esp));
|
||||
asm volatile ("mov %%ebp, %0" : "=r" (ebp));
|
||||
eip = read_eip();
|
||||
if (eip == 0x10000) {
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
return;
|
||||
}
|
||||
current_task->eip = eip;
|
||||
@ -178,8 +178,8 @@ switch_task() {
|
||||
eip = current_task->eip;
|
||||
esp = current_task->esp;
|
||||
ebp = current_task->ebp;
|
||||
__asm__ __volatile__ (
|
||||
"cli\n"
|
||||
IRQ_OFF;
|
||||
asm volatile (
|
||||
"mov %0, %%ebx\n"
|
||||
"mov %1, %%esp\n"
|
||||
"mov %2, %%ebp\n"
|
||||
@ -195,7 +195,7 @@ switch_task() {
|
||||
void
|
||||
enter_user_jmp(uintptr_t location, int argc, char ** argv, uintptr_t stack) {
|
||||
set_kernel_stack(current_task->stack);
|
||||
__asm__ __volatile__(
|
||||
asm volatile(
|
||||
"mov %3, %%esp\n"
|
||||
"mov $0x23, %%ax\n"
|
||||
"mov %%ax, %%ds\n"
|
||||
@ -217,7 +217,7 @@ enter_user_jmp(uintptr_t location, int argc, char ** argv, uintptr_t stack) {
|
||||
}
|
||||
|
||||
void task_exit(int retval) {
|
||||
__asm__ __volatile__ ("cli");
|
||||
IRQ_OFF;
|
||||
current_task->retval = retval;
|
||||
current_task->finished = 1;
|
||||
/* Free the image memory */
|
||||
@ -240,12 +240,10 @@ void task_exit(int retval) {
|
||||
free((void *)current_task->page_directory);
|
||||
free((void *)current_task->descriptors);
|
||||
//free((void *)current_task);
|
||||
__asm__ __volatile__ ("sti");
|
||||
IRQ_ON;
|
||||
}
|
||||
|
||||
void kexit(int retval) {
|
||||
task_exit(retval);
|
||||
while (1) {
|
||||
__asm__ __volatile__("hlt");
|
||||
}
|
||||
STOP;
|
||||
}
|
||||
|
@ -61,6 +61,6 @@ timer_wait(
|
||||
eticks = (long)timer_ticks + (long)ticks;
|
||||
while(timer_ticks < eticks) {
|
||||
/* Halt for interrupt */
|
||||
__asm__ __volatile__("hlt");
|
||||
PAUSE;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,14 @@
|
||||
#define KERNEL_UNAME "ToAruOS"
|
||||
#define KERNEL_VERSION_STRING "0.0.1"
|
||||
|
||||
#define STOP while (1) { __asm__ __volatile__ ("hlt"); }
|
||||
#define asm __asm__
|
||||
#define volatile __volatile__
|
||||
|
||||
#define IRQ_OFF asm volatile ("cli")
|
||||
#define IRQ_ON asm volatile ("sti")
|
||||
#define PAUSE asm volatile ("hlt")
|
||||
|
||||
#define STOP while (1) { PAUSE; }
|
||||
|
||||
extern void *sbrk(uintptr_t increment);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user