aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/graphics/vesa.c5
-rw-r--r--src/kernel/graphics/vesa.h4
-rw-r--r--src/kernel/graphics/vga.c4
-rw-r--r--src/kernel/input/ps2/mouse.c4
-rw-r--r--src/kernel/linker.ld46
-rw-r--r--src/kernel/system.h53
6 files changed, 83 insertions, 33 deletions
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index f3fd865..f6bdba0 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -63,6 +63,9 @@ void set_optimal_resolution() {
struct vbe_info *info;
struct vbe_mode_info *mode_info;
+ // info = lmalloc(sizeof(struct vbe_info));
+ // mode_info = lmalloc(sizeof(struct vbe_mode_info));
+
info->signature[0] = 'V';
info->signature[1] = 'B';
info->signature[2] = 'E';
@@ -96,6 +99,8 @@ void set_optimal_resolution() {
}
}
+ // lfree(info);
+
/*if (strcmp((const char *) info->version, (const char *) 0x300) == 0) {
init();
terminal_write_string("SUCCESS!\n");
diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h
index d163fb3..33272f8 100644
--- a/src/kernel/graphics/vesa.h
+++ b/src/kernel/graphics/vesa.h
@@ -11,9 +11,9 @@
struct vbe_info {
char signature[4];
uint32_t version;
- uint32_t oem;
+ far_ptr_t oem;
uint32_t capabilities;
- struct far_ptr video_modes;
+ far_ptr_t video_modes;
uint32_t video_memory;
uint32_t software_rev;
uint32_t vendor;
diff --git a/src/kernel/graphics/vga.c b/src/kernel/graphics/vga.c
index fa1f330..8fde84f 100644
--- a/src/kernel/graphics/vga.c
+++ b/src/kernel/graphics/vga.c
@@ -25,11 +25,11 @@ enum vga_color {
VGA_COLOR_WHITE = 15,
};
-static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
+inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;
}
-static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
+inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
return (uint16_t) uc | (uint16_t) color << 8;
}
diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c
index 45a4664..a637347 100644
--- a/src/kernel/input/ps2/mouse.c
+++ b/src/kernel/input/ps2/mouse.c
@@ -35,7 +35,7 @@ void mouse_handler(struct regs *a_r) {
terminal_write_line("CLICK!");
}
-inline void mouse_wait(unsigned char a_type) {
+void mouse_wait(unsigned char a_type) {
unsigned int time_out = 100000;
if (a_type == 0) {
while (time_out--)
@@ -50,7 +50,7 @@ inline void mouse_wait(unsigned char a_type) {
}
}
-inline void mouse_write(unsigned char a_write) {
+void mouse_write(unsigned char a_write) {
mouse_wait(1);
send_b(0x64, 0xD4);
mouse_wait(1);
diff --git a/src/kernel/linker.ld b/src/kernel/linker.ld
index 2f74866..2abbaeb 100644
--- a/src/kernel/linker.ld
+++ b/src/kernel/linker.ld
@@ -1,25 +1,27 @@
-OUTPUT_FORMAT("binary")
ENTRY(start)
-phys = 0x00100000;
SECTIONS
{
- .text phys : AT(phys) {
- code = .;
- *(.text)
- *(.rodata*)
- . = ALIGN(4096);
- }
- .data : AT(phys + (data - code))
- {
- data = .;
- *(.data)
- . = ALIGN(4096);
- }
- .bss : AT(phys + (bss - code))
- {
- bss = .;
- *(.bss)
- . = ALIGN(4096);
- }
- end = .;
-} \ No newline at end of file
+ .text 0x100000 :
+ {
+ code = .; _code = .; __code = .;
+ *(.text)
+ . = ALIGN(4096);
+ }
+
+ .data :
+ {
+ data = .; _data = .; __data = .;
+ *(.data)
+ *(.rodata)
+ . = ALIGN(4096);
+ }
+
+ .bss :
+ {
+ bss = .; _bss = .; __bss = .;
+ *(.bss)
+ . = ALIGN(4096);
+ }
+
+ end = .; _end = .; __end = .;
+}
diff --git a/src/kernel/system.h b/src/kernel/system.h
index c7ed2fd..b310d5b 100644
--- a/src/kernel/system.h
+++ b/src/kernel/system.h
@@ -1,6 +1,8 @@
#ifndef MELVIX_SYSTEM_H
#define MELVIX_SYSTEM_H
+#include "graphics/graphics.h"
+
/**
* Initialize the basic features of the OS
*/
@@ -33,17 +35,19 @@ struct far_ptr {
};
} __attribute__ ((packed));
+typedef struct far_ptr far_ptr_t;
+
/**
* Get offset from ASM segment:offset pointer
*/
-static inline uint16_t get_offset(const volatile void *p) {
+uint16_t get_offset(const volatile void *p) {
return (uint16_t) (uintptr_t) p & 0x000F;
}
/**
* Get segment from ASM segment:offset pointer
*/
-static inline uint16_t get_segment(const volatile void *p) {
+uint16_t get_segment(const volatile void *p) {
return (uint16_t) (((uintptr_t) p) >> 4);
}
@@ -52,8 +56,8 @@ static inline uint16_t get_segment(const volatile void *p) {
* @param __ptr The ASM segment:offset pointer
* @return The new far pointer
*/
-static inline struct far_ptr FAR_PTR(void *__ptr) {
- struct far_ptr __fptr;
+far_ptr_t FAR_PTR(void *__ptr) {
+ far_ptr_t __fptr;
__fptr.offset = get_offset(__ptr);
__fptr.segment = get_segment(__ptr);
return __fptr;
@@ -64,8 +68,47 @@ static inline struct far_ptr FAR_PTR(void *__ptr) {
* @param fptr The ASM far pointer
* @return The normalized pointer
*/
-static inline void *get_ptr(struct far_ptr fptr) {
+void *get_ptr(far_ptr_t fptr) {
return (void *) (unsigned long) ((fptr.segment << 4) + fptr.offset);
}
+/**
+ * Display a warning message
+ * TODO: Add line number and file name
+ * @param msg The warning cause/reason
+ */
+void warn(char *msg) {
+ asm volatile ("cli");
+ terminal_set_color(6);
+ terminal_write_line("WARNING");
+ terminal_write_string(msg);
+ terminal_set_color(7);
+}
+
+/**
+ * Halt the entire system and display a message
+ * TODO: Add line number and file name
+ * @param msg The error cause/reason
+ */
+void panic(char *msg) {
+ asm volatile ("cli");
+ terminal_set_color(4);
+ terminal_write_line("PANIC");
+ terminal_write_string(msg);
+ loop:
+ asm volatile ("hlt");
+ goto loop;
+}
+
+/**
+ * Assert that a value is non-zero, else panic
+ * TODO: Add line number and file name
+ * @param x The value
+ */
+void assert(int x) {
+ if (x == 0) {
+ panic("Assertion failed");
+ }
+}
+
#endif