[fpu][bochs][sys] FPU enabled, line drawing function, abs(), max()
This commit is contained in:
parent
488d6bc8ca
commit
9c85c544eb
20
kernel/core/fpu.c
Normal file
20
kernel/core/fpu.c
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* vim:tabstop=4
|
||||
* vim:noexpandtab
|
||||
*/
|
||||
#include <system.h>
|
||||
|
||||
void
|
||||
set_fpu_cw(const uint16_t cw) {
|
||||
__asm__ __volatile__("fldcw %0" :: "m"(cw));
|
||||
}
|
||||
|
||||
void
|
||||
enable_fpu() {
|
||||
size_t cr4;
|
||||
/* Trust me, we have an FPU */
|
||||
__asm__ __volatile__ ("mov %%cr4, %0" : "=r"(cr4));
|
||||
cr4 |= 0x200;
|
||||
__asm__ __volatile__ ("mov %0, %%cr4" :: "r"(cr4));
|
||||
set_fpu_cw(0x37F);
|
||||
}
|
@ -222,6 +222,20 @@ start_shell() {
|
||||
} else {
|
||||
bochs_draw_logo(argv[1]);
|
||||
}
|
||||
} else if (!strcmp(cmd, "line")) {
|
||||
if (tokenid < 5) {
|
||||
bochs_draw_line(0,1024,0,768, 0xFFFFFF);
|
||||
} else {
|
||||
bochs_draw_line(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),0xFFFFFF);
|
||||
}
|
||||
} else if (!strcmp(cmd, "boredom")) {
|
||||
for (int derp = 0; derp < 30; ++derp) {
|
||||
int x0 = krand() % 1024;
|
||||
int x1 = krand() % 1024;
|
||||
int y0 = krand() % 768;
|
||||
int y1 = krand() % 768;
|
||||
bochs_draw_line(x0,x1,y0,y1, krand() % 0xFFFFFF);
|
||||
}
|
||||
} else {
|
||||
kprintf("Unrecognized command: %s\n", cmd);
|
||||
}
|
||||
|
@ -24,6 +24,23 @@ memcpy(
|
||||
return dest;
|
||||
}
|
||||
|
||||
int
|
||||
max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
int
|
||||
abs(int a) {
|
||||
return (a >= 0) ? a : -a;
|
||||
}
|
||||
|
||||
void
|
||||
swap(int *a, int *b) {
|
||||
int t = *a;
|
||||
*a = *b;
|
||||
*b = t;
|
||||
}
|
||||
|
||||
void *
|
||||
memmove(
|
||||
void * restrict dest,
|
||||
|
@ -188,6 +188,7 @@ bochs_write_char(
|
||||
__asm__ __volatile__ ("sti");
|
||||
}
|
||||
|
||||
/* This is mapped to ANSI */
|
||||
uint32_t bochs_colors[16] = {
|
||||
/* black */ 0x000000,
|
||||
/* red */ 0xcc0000,
|
||||
@ -318,3 +319,25 @@ void bochs_write(char c) {
|
||||
draw_cursor();
|
||||
__asm__ __volatile__ ("sti");
|
||||
}
|
||||
|
||||
|
||||
void bochs_draw_line(uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1, uint32_t color) {
|
||||
int deltax = abs(x1 - x0);
|
||||
int deltay = abs(y1 - y0);
|
||||
int sx = (x0 < x1) ? 1 : -1;
|
||||
int sy = (y0 < y1) ? 1 : -1;
|
||||
int error = deltax - deltay;
|
||||
while (1) {
|
||||
bochs_set_point(x0, y0, color);
|
||||
if (x0 == x1 && y0 == y1) break;
|
||||
int e2 = 2 * error;
|
||||
if (e2 > -deltay) {
|
||||
error -= deltay;
|
||||
x0 += sx;
|
||||
}
|
||||
if (e2 < deltax) {
|
||||
error += deltax;
|
||||
y0 += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ extern void *sbrk(uintptr_t increment);
|
||||
extern uint16_t pci_get_lfb_addr(uint16_t id);
|
||||
|
||||
/* Kernel Main */
|
||||
extern int max(int,int);
|
||||
extern int abs(int);
|
||||
extern void swap(int *, int *);
|
||||
extern void *memcpy(void *restrict dest, const void *restrict src, size_t count);
|
||||
extern void *memmove(void *restrict dest, const void *restrict src, size_t count);
|
||||
extern void *memset(void *dest, int val, size_t count);
|
||||
@ -213,7 +216,13 @@ extern void bochs_term_clear();
|
||||
extern void bochs_write(char c);
|
||||
extern void bochs_reset_colors();
|
||||
extern void bochs_set_colors(uint8_t, uint8_t);
|
||||
extern void bochs_draw_line(uint16_t,uint16_t,uint16_t,uint16_t,uint32_t);
|
||||
|
||||
extern uint8_t number_font[][12];
|
||||
|
||||
/* Floating Point Unit */
|
||||
|
||||
void set_fpu_cw(const uint16_t);
|
||||
void enable_fpu();
|
||||
|
||||
#endif
|
||||
|
@ -108,6 +108,7 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp)
|
||||
paging_install(mboot_ptr->mem_upper); /* Paging */
|
||||
heap_install(); /* Kernel heap */
|
||||
tasking_install(); /* Multi-tasking */
|
||||
enable_fpu();
|
||||
|
||||
/* Kernel Version */
|
||||
settextcolor(12, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user