Mon, 25 Dec 2017 20:56:49 +0100
5 files changed,
97 insertions(+),
23 deletions(-)
M
kernel/os_main.c
→
kernel/os_main.c
@@ -1,9 +1,23 @@
#include "os_text.h" int main(void) { + const char* string[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; clear(); - write("Welcome!"); - backspace(); + for (int i = 0; i < 50; i++) { + write("LINE "); + write(string[i / 10]); + write(string[i % 10]); + write("\n"); + } + + write( "SOMEBODY ONCE TOLD ME " + "THE WORLD IS GONNA ROLL ME " + "I AINT THE SHARPEST TOOL IN THE SHED " + "SHE WAS LOOKING KINDA DUMB " + "WITH HER FINGER AND HER THUMB " + "IN THE SHAPE OF AN L ON HER FOREHEAD" + ); + //backspace(); return 0; }
A
kernel/os_string.c
@@ -0,0 +1,21 @@
+#include "os_string.h" + +void *memcpy (void *destination, const void *source, size_t num) { + if (destination >= source) { + for (uint32_t i = 0; i < num; i++) { + ((uint8_t*)destination)[num - 1 - i] = ((uint8_t*)source)[num - 1 - i]; + } + } else { + for (uint32_t i = 0; i < num; i++) { + ((uint8_t*)destination)[i] = ((uint8_t*)source)[i]; + } + } + return destination; +} + +void *memset (void *ptr, int value, size_t num) { + for (uint32_t i = 0; i < num; i++) { + ((uint8_t*)ptr)[i] = (uint8_t)value; + } + return ptr; +}
A
kernel/os_string.h
@@ -0,0 +1,33 @@
+/*! \file + * Defines several functions to manipulate C strings and arrays. + */ +#ifndef OS_STRING_H +#define OS_STRING_H + +#include <stdint.h> + +/*! + * Unsigned integral type. + */ +typedef uint32_t size_t; + +/*! + * Copies a block of memory. + * \param destination Pointer to the destination array where the content is to be copied. + * \param source Pointer to the source of the data to be copied. + * \param num Number of bytes to be copied. + * \return \p destination is returned. + */ +void *memcpy (void *destination, const void *source, size_t num); + +/*! + * Sets the \p num first bytes of the block of memory pointed to by \p ptr + * to the specified \p value + * \param ptr Pointer to the block of memory to be filled. + * \param value Value to be set (Passed as int, but converted to unsigned char) + * \param num Number of bytes to set to \p value. + * \return \p ptr is returned. + */ +void *memset (void *ptr, int value, size_t num); + +#endif
M
kernel/os_text.c
→
kernel/os_text.c
@@ -1,13 +1,18 @@
#include "linker.h" #include "assembly.h" +#include "os_string.h" #define VGA_TEXTMODE_COLUMNS 80 #define VGA_TEXTMODE_LINES 25 +#define VGA_TEXTMODE_BPC 2 +#define VGA_TEXTMODE_LINE_WIDTH (VGA_TEXTMODE_COLUMNS * VGA_TEXTMODE_BPC) #define VGA_TEXTMODE_CELLS (VGA_TEXTMODE_COLUMNS * VGA_TEXTMODE_LINES) -#define VGA_TEXTMODE_BPC 2 #define VGA_MEM_POS(line, column) ((line) * VGA_TEXTMODE_COLUMNS * VGA_TEXTMODE_BPC + (column) * VGA_TEXTMODE_BPC) #define VGA_TEXTMODE_MEM ((uint8_t*)0xB8000) +#define VGA_MEM_VALUE(line, column) (VGA_TEXTMODE_MEM[VGA_MEM_POS((line), (column))]) +#define VGA_MEM_COLOR(line, column) (VGA_TEXTMODE_MEM[VGA_MEM_POS((line), (column)) + 1]) +#define VGA_MEM_ADDR(line, column) (&(VGA_MEM_VALUE((line), (column)))) #define VGA_INDEX_REG ((uint16_t)0x3D4) #define VGA_DATA_REG ((uint16_t)0x3D5)@@ -17,23 +22,36 @@ uint32_t column = 0;
uint8_t color = 0x0F; __attribute((always_inline)) inline void set_char(char value) { - VGA_TEXTMODE_MEM[VGA_MEM_POS(line, column)] = value; - VGA_TEXTMODE_MEM[VGA_MEM_POS(line, column) + 1] = color; + VGA_MEM_VALUE(line, column) = value; + VGA_MEM_COLOR(line, column) = color; } __attribute((always_inline)) inline void lfcr() { - if (line < VGA_TEXTMODE_LINES) { - line++; - } else { + line++; + column = 0; + + if (line >= VGA_TEXTMODE_LINES) { + memcpy( + VGA_MEM_ADDR(0, 0), + VGA_MEM_ADDR(1, 0), + VGA_TEXTMODE_LINE_WIDTH * (VGA_TEXTMODE_LINES - 1) + ); + memset( + VGA_MEM_ADDR(VGA_TEXTMODE_LINES - 1, 0), + 0, + VGA_TEXTMODE_LINE_WIDTH + ); line = VGA_TEXTMODE_LINES - 1; } - column = 0; } __attribute((always_inline)) inline void write_char(char value) { + if (column >= VGA_TEXTMODE_COLUMNS || value == '\n') { + lfcr(); + } + switch (value) { case '\n': - lfcr(); break; case '\0': break;@@ -41,10 +59,6 @@ default:
set_char(value); column++; break; - } - - if (column >= VGA_TEXTMODE_COLUMNS) { - lfcr(); } }
M
second_stage/entry.s
→
second_stage/entry.s
@@ -21,12 +21,4 @@ ljmp $8, $__KERNEL_VMA
# loop until the heat death of the universe loop: - jmp loop - - -.section .data -low_kernel_welcome: - .ascii "Welcome to the low kernel!" - .byte 13 - .byte 10 - .byte 0 + jmp loop