From dc17550ed5b5cb198bb293f8698bb343d634ea2f Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 23 Dec 2018 20:50:17 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d9140ea..41d9385 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0 +Branch kaleid : Development focused on the Kaleid Kernel. For changelog, see src/ChangeLog. For structure of the sources, see src/project-tree.txt. -For code conventions, see src/project-style.txt. +For code conventions, see src/project-style.txt. From 915490fa2473b3371e44eaf6db553581177563e9 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 24 Dec 2018 18:13:58 +0100 Subject: [PATCH 2/5] x --- src/Makefile | 25 ++-- src/boot/loader.s | 5 +- src/boot/loader16.inc | 1 + src/boot/loader64.inc | 1 + src/boot/mbr.inc | 2 +- src/boot/mbr.s | 16 +-- src/boot/types.h | 9 -- src/kaleid/common/assert.h | 22 ++-- src/kaleid/common/atomic.h | 10 +- src/kaleid/common/common.h | 7 +- src/kaleid/common/config.h | 4 +- src/kaleid/common/config.h.in | 4 +- src/kaleid/common/lib/string.c | 19 +-- src/kaleid/common/status.h | 7 +- src/kaleid/common/string.h | 4 +- src/kaleid/common/types.h | 8 +- src/kaleid/kernel/init.c | 8 +- src/kaleid/kernel/init.h | 4 +- src/kaleid/kernel/io/ports.h | 4 +- src/kaleid/kernel/io/terminal.c | 221 +++++++++++++++++++++----------- src/kaleid/kernel/io/terminal.h | 71 ++++++---- src/kernel.ld | 49 +++++++ 22 files changed, 319 insertions(+), 182 deletions(-) delete mode 100644 src/boot/types.h create mode 100644 src/kernel.ld diff --git a/src/Makefile b/src/Makefile index 6d51fb0..a4a69e5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,13 +7,14 @@ # Desc: Project Makefile # #----------------------------------------------------------------------------# -CC_NAME="/opt/cross-cc/bin/x86_64-elf-gcc" -CWARNS=-Wall -Wextra -Werror +CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" +CWARNS=-Wall -Wextra -Werror -pedantic +CLDSCR=-T kernel.ld CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CINCLUDES=-I./kaleid CDEFINES= -CC=$(CC_NAME) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +CC=$(CCNAME) $(CWARNS) $(CLDSCR) $(CFLAGS) $(CDEFINES) $(CINCLUDES) ASM=nasm ASMFLAGS= @@ -53,14 +54,14 @@ testing: bootloader pseudo_kern COBJDIR=$(OBJDIR)/$(COMMDIR) -COMM_DEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(COMMDIR)/config.h \ +COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(COMMDIR)/config.h \ $(COMMDIR)/status.h COBJECTS=$(COBJDIR)/lib/string.o -common: common.lib.string.c $(COMM_DEPS) +common: common.lib.string.c $(COMMDEPS) -common.lib.string.c: $(COMMDIR)/lib/string.c $(COMM_DEPS) +common.lib.string.c: $(COMMDIR)/lib/string.c $(COMMDEPS) $(CC) -c $(COMMDIR)/lib/string.c -o $(OBJDIR)/$(COMMDIR)/lib/string.o #----------------------------------------------------------------------------# @@ -68,21 +69,21 @@ common.lib.string.c: $(COMMDIR)/lib/string.c $(COMM_DEPS) KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERN_DEPS=$(COMM_DEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h +KERNDEPS=$(COMMDEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h kernel: common kernel.io.terminal.c kernel.init.c kernel.io.ports.c - $(CC) -o $(BINDIR)/kaleid-kernel.elf \ - $(COBJECTS) $(KOBJDIR)/init.o \ + $(CC) -o $(BINDIR)/kaleid-kernel.elf \ + $(COBJECTS) $(KOBJDIR)/init.o \ $(KOBJDIR)/io/terminal.o $(KOBJDIR)/io/ports.o -kernel.init.c: $(KERNDIR)/init.c $(KERN_DEPS) +kernel.init.c: $(KERNDIR)/init.c $(KERNDEPS) $(CC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o -kernel.io.ports.c: $(KERNDIR)/io/ports.c $(KERN_DEPS) +kernel.io.ports.c: $(KERNDIR)/io/ports.c $(KERNDEPS) $(CC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o -kernel.io.terminal.c: $(KERNDIR)/io/terminal.c $(KERN_DEPS) +kernel.io.terminal.c: $(KERNDIR)/io/terminal.c $(KERNDEPS) $(CC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o diff --git a/src/boot/loader.s b/src/boot/loader.s index 8c46cd4..ef5bf44 100644 --- a/src/boot/loader.s +++ b/src/boot/loader.s @@ -54,7 +54,8 @@ GDT64: NULL_SELECTOR: ;; null selector within 64 bits dw GDT_LENGTH ; limit of GDT dw GDT64 ; linear address of GDT - dd 0x0 + dd 0x0 ; + CODE_SELECTOR: ;; 32-bit code selector (ring 0) dw 0x0FFFF ; Segment Limit db 0x0, 0x0, 0x0 ; Base Address @@ -113,7 +114,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 10101111b ; |7|6|5|4|3|2|1|0| + db 10101111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 diff --git a/src/boot/loader16.inc b/src/boot/loader16.inc index 56d9840..a30cff9 100644 --- a/src/boot/loader16.inc +++ b/src/boot/loader16.inc @@ -7,6 +7,7 @@ ; Desc: Kernel (second stage) Loader for OS/K INCLUDED FUNCTIONS ; ; (x86_64 architecture only) ; ;=----------------------------------------------------------------------------=; + [BITS 16] disable_cursor: diff --git a/src/boot/loader64.inc b/src/boot/loader64.inc index 2e29af6..10406b3 100644 --- a/src/boot/loader64.inc +++ b/src/boot/loader64.inc @@ -7,6 +7,7 @@ ; Desc: Kernel (second stage) Loader for OS/K INCLUDED FUNCTIONS ; ; (x86_64 architecture only) ; ;=----------------------------------------------------------------------------=; + [BITS 64] clear: diff --git a/src/boot/mbr.inc b/src/boot/mbr.inc index 5e06bc9..0efe8d4 100644 --- a/src/boot/mbr.inc +++ b/src/boot/mbr.inc @@ -33,7 +33,7 @@ read_clusters: add ax, word [UserData] ; add the UserData xor ch, ch mov cl, byte [sectorsPerCluster] ; Sectors to read - call read_sectors ; Read the sectors + call read_sectors ; Read the sectors pop ax ; Current cluster number xor dx, dx ;; Calculate next sector for FAT16 (cluster * 2) diff --git a/src/boot/mbr.s b/src/boot/mbr.s index 3387242..f7a3066 100644 --- a/src/boot/mbr.s +++ b/src/boot/mbr.s @@ -79,8 +79,8 @@ go: ;; INIT STACK cli - mov ax, STACK_SEG ; Init the staaaaaack - mov ss, ax ; Continue init the staaaaaaaack + mov ax, STACK_SEG ; Init the stack + mov ss, ax ; Continue init the stack mov sp, STACK_OFF ; Ok man, the stack is in 4K :O sti mov bp, (0x7c0-STACK_SEG) << 4 ; Correct bp (the disk description table) @@ -88,7 +88,7 @@ go: ;; INITIALIZE BOOT DISK or dl, dl ; Verifying dl points actually to the boot drive jz load_root - mov byte [Bootdrv], dl ; Another soul (the disk) saved ! + mov byte [Bootdrv], dl ; Another soul (the disk) saved! mov ah, 0x08 int 0x13 ; int 0x13 : read drive parameters/geom jc load_root @@ -97,7 +97,7 @@ go: mov dl, dh ; Convert the maximum head number to a word with another vaudou magical trip xor dh, dh inc dx ; because head numbers start at zero - mov word [heads], dx ; Another soul (the heads number) saved ! + mov word [heads], dx ; Another soul (the heads number) saved! ;; LOAD THE ROOT DIRECTORY FROM DISK @@ -117,7 +117,7 @@ load_root: mov di, BUFFER_SEG ; Set the extra segment to the disk buffer mov es, di mov di, BUFFER_OFF ; Set es:di and load the root directory into the disk buffer - call read_sectors ; Read the sectoooooooors ! + call read_sectors ; Read the sectors ;; FIND THE SECOND STAGE LOADER mov di, BUFFER_OFF ; Set es:di to the disk buffer @@ -128,7 +128,7 @@ search_root: mov si, filename ; Load the filename mov cx, 11 ; Compare first 11 bytes rep cmpsb ; Compare si and di cx times - je load_fat ; We found the LOADEEEEEEEER!!! + je load_fat ; We found the loader add ax, 32 ; File entry offset mov di, BUFFER_OFF ; Point back to the start of the entry add di, ax ; Add the offset to point to the next entry @@ -150,14 +150,14 @@ load_fat: mov cx, ax ; Store in cx mov ax, word [reservedSectors] ; Convert the first fat on the disk mov di, BUFFER_OFF ; Set es:di and load the fat sectors into the disk buffer - call read_sectors ; Read the sectooooooooooors !!! + call read_sectors ; Read the sectors ;; LOAD THE CLUSTERS OF THE LOADER AND JUMP mov di, LOAD_SEG mov es, di ; Set es:bx to where the file will load mov di, LOAD_OFF pop ax ; File cluster restored - call read_clusters ; Read clusters from the file + call read_clusters ; Read clusters from the file mov dl, byte [Bootdrv] ; Pass the boot Bootdrv into dl jmp LOAD_SEG:LOAD_OFF ; Jump to the file loaded! diff --git a/src/boot/types.h b/src/boot/types.h deleted file mode 100644 index 71faf9b..0000000 --- a/src/boot/types.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _I386_TYPE_ -#define _I386_TYPE_ - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned char uchar; - -#endif diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h index 5bf73eb..5e109d3 100644 --- a/src/kaleid/common/assert.h +++ b/src/kaleid/common/assert.h @@ -7,28 +7,32 @@ // Desc: Assertions // //----------------------------------------------------------------------------// -#ifndef __kaleid_assert_h -#define __kaleid_assert_h - -#if !defined(NDEBUG) +#ifndef _KALCOMM_ASSERT_H +#define _KALCOMM_ASSERT_H extern const char *panicstr; extern void panic(const char *) __dead; +#if !defined(_NO_DEBUG) + #define assert(x) do{if(!(x))panic(#x);}while(0); -#define assert_never_used(x) do{static bool __anu_##x = FALSE; \ - assert(__anu_##x == FALSE); __anu_##x = TRUE;}while(0); +#define assert_never_used(x) do{static bool __##x##_init = FALSE; \ + assert(__##x##_init == FALSE); __##x##_init = TRUE;}while(0); -#define assert_used_once(x) do{static bool __anu_##x; assert(__anu_##x == TRUE);} while(0); +#define assert_used_once(x) do{static bool __##x##_init; assert(__##x##_init == TRUE);} while(0); -#else // NDEBUG +#else // not debugging + +#if !defined(NDEBUG) +#define NDEBUG 1 +#endif #define assert(x) #define assert_never_used(x) #define assert_used_once(x) -#endif // NDEBUG +#endif #endif diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/atomic.h index 80dfe98..f8d9e72 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/atomic.h @@ -7,14 +7,14 @@ // Desc: Atomic stuff // //----------------------------------------------------------------------------// -#ifndef __kaleid_atomic_h -#define __kaleid_atomic_h +#ifndef _KALCOMM_ATOMIC_H +#define _KALCOMM_ATOMIC_H // atomic_t defined in common/types.h -#define cli() // XXX -#define sti() // XXX -#define hlt() // XXX +#define cli() asm volatile ("cli") +#define sti() asm volatile ("sti") +#define hlt() asm volatile ("hlt") #endif diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 4f85241..6107b21 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -8,8 +8,8 @@ //----------------------------------------------------------------------------// -#ifndef __kaleid_common_h -#define __kaleid_common_h +#ifndef _KALCOMM_COMMON_H +#define _KALCOMM_COMMON_H #define true 1 #define TRUE 1 @@ -27,6 +27,9 @@ #define THROWS(...) #define ERRS(...) +#define likely(x) __builtin_expect((x), 1) +#define unlikely(x) __builtin_expect((x), 0) + #include "common/types.h" #include "common/config.h" #include "common/atomic.h" diff --git a/src/kaleid/common/config.h b/src/kaleid/common/config.h index a31d87f..2374b66 100644 --- a/src/kaleid/common/config.h +++ b/src/kaleid/common/config.h @@ -13,8 +13,8 @@ // We may do a script that generates "config.h" for the user, asking about // the different configuration choices in the terminal. -#ifndef __kaleid_config_h -#define __kaleid_config_h +#ifndef _KALCOMM_CONFIG_H +#define _KALCOMM_CONFIG_H //------------------------------------------// // General configuration choices // diff --git a/src/kaleid/common/config.h.in b/src/kaleid/common/config.h.in index a31d87f..2374b66 100644 --- a/src/kaleid/common/config.h.in +++ b/src/kaleid/common/config.h.in @@ -13,8 +13,8 @@ // We may do a script that generates "config.h" for the user, asking about // the different configuration choices in the terminal. -#ifndef __kaleid_config_h -#define __kaleid_config_h +#ifndef _KALCOMM_CONFIG_H +#define _KALCOMM_CONFIG_H //------------------------------------------// // General configuration choices // diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index 7f1d30b..f7093fe 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -9,23 +9,16 @@ #include "common/string.h" -// XXX several of these should be re-wrote in assembly - -size_t strlen(const char *s) +// +// Return str's length +// TODO multibyte, assembly +// +size_t strlen(const char *str) { size_t i; - for (i = 0; s; s++, i++); + for (i = 0; str; str++, i++); return i; } -/*size_t wcslen(const wchar_t *s); -{ - int i; - - for (i = 0; s; s++, i++); - - return s; -}*/ - diff --git a/src/kaleid/common/status.h b/src/kaleid/common/status.h index c7a1147..72e29a1 100644 --- a/src/kaleid/common/status.h +++ b/src/kaleid/common/status.h @@ -8,8 +8,8 @@ //----------------------------------------------------------------------------// -#ifndef __kaleid_status_h -#define __kaleid_status_h +#ifndef _KALCOMM_STATUS_H +#define _KALCOMM_STATUS_H #define STATUS_FAILED(x) ((x) < 0)) #define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) @@ -23,8 +23,9 @@ #define BAD_ARGUMENT (-4) // invalid arguments, can't be more precise #define BAD_ARG_RANGE (-5) // arguments out of range +#define BAD_ARG_NULL (-6) // unexpected NULL argument -#define TRY_AGAIN (-6) // EAGAIN +#define TRY_AGAIN (-7) // EAGAIN #endif diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index d18053a..2605063 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -8,8 +8,8 @@ //----------------------------------------------------------------------------// -#ifndef __kaleid_string_h -#define __kaleid_string_h +#ifndef _KALCOMM_STRING_H +#define _KALCOMM_STRING_H #include "common/common.h" diff --git a/src/kaleid/common/types.h b/src/kaleid/common/types.h index a48d5b8..57c73bf 100644 --- a/src/kaleid/common/types.h +++ b/src/kaleid/common/types.h @@ -8,8 +8,8 @@ //----------------------------------------------------------------------------// -#ifndef __kaleid_types_h -#define __kaleid_types_h +#ifndef _KALCOMM_TYPES_H +#define _KALCOMM_TYPES_H typedef _Bool bool; typedef unsigned char uchar; @@ -23,10 +23,8 @@ typedef uint wchar_t; typedef ulong size_t; typedef long ssize_t; - -// XXX typedef int atomic_t; -typedef ulong pid_t; // etc... +typedef ulong pid_t; #endif diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index 41e2efc..2ea9311 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -10,11 +10,9 @@ #include "kernel/init.h" #include "kernel/io/terminal.h" -void _start(void) -{ - assert(strlen("test") == 4); - +void kstart(void) +{ kterm_init(); - kterm_print("Hello World!"); + panic("Goodbye World :("); } diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index c4677da..2b85b67 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -7,8 +7,8 @@ // Desc: Include file for init.c // //----------------------------------------------------------------------------// -#ifndef __kaleid_kernel_init_h -#define __kaleid_kernel_init_h +#ifndef _KALKERN_INIT_H +#define _KALKERN_INIT_H #include "common/common.h" #include "common/string.h" diff --git a/src/kaleid/kernel/io/ports.h b/src/kaleid/kernel/io/ports.h index 20d2908..cd4c5cc 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/src/kaleid/kernel/io/ports.h @@ -7,8 +7,8 @@ // Desc: Ports I/O // //----------------------------------------------------------------------------// -#ifndef __kaleid_kernel_io_ports_h -#define __kaleid_kernel_io_ports_h +#ifndef _KALKERN_IO_PORTS_H +#define _KALKERN_IO_PORTS_H #include "common/common.h" diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index 7062819..38285a3 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -9,139 +9,212 @@ #include "kernel/io/terminal.h" -// VGA buffer size -static const size_t kterm_width = 80; -static const size_t kterm_height = 25; - -// position in the buffer -static size_t current_row; -static size_t current_col; - -static uchar current_color; - -// each buffer entry is composed of two bytes -// one is the color code, the other the character -static ushort *const buffer = (ushort *)0xB8000; - +// +// VGA-related macros +// #define ComputeColorCode(fg, bg) ((fg) | (bg) << 4) -#define ComputeEntryOffset(x, y) ((y) * kterm_width + (x)) +#define ComputeEntryOffset(kt, x, y) ((y) * kt->kt_width + (x)) #define ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8) +// +// VGA output +// +static struct kterm _kt_vga = { + .kt_buffer = (ushort *)0xB8000, + .kt_width = 80, + .kt_height = 25, + .kt_curr_x = 0, + .kt_curr_y = 0, + .kt_color = ComputeColorCode(KTERM_COLOR_LGREY, KTERM_COLOR_BLACK), + .kt_lock = NULL, +#ifndef _NO_DEBUG + .kt_init = FALSE, +#endif +}; + +// +// Standard output terminal +// +struct kterm *kt_stdout; + +// +// Initialize standard output +// void kterm_init(void) { - assert_never_used(kterm_init); + assert(!kt_stdout && !_kt_vga.kt_init && "kterm_init() called twice"); + +#ifndef _NO_DEBUG + _kt_vga.kt_init = TRUE; +#endif - kterm_change_color(ComputeColorCode(KTERM_COLOR_LIGHT_GREY, KTERM_COLOR_BLACK)); - kterm_clear(); + // to be switched to VESA + kt_stdout = &_kt_vga; + ktclear(); } -void kterm_clear(void) +// +// Fills terminal with spaces +// XXX would '\0' work too? +// +status_t kterm_clear(struct kterm *kt) { - size_t x, y; + size_t i; - assert_used_once(kterm_init); + if (kt == NULL) + return BAD_ARG_NULL; - for (x = 0; x < kterm_width; x++) { - for (y = 0; y < kterm_height; y++) { - const size_t offset = ComputeEntryOffset(x,y); - buffer[offset] = ComputeEntry(' ', current_color); - } + assert(kt->kt_init && "kterm_clear called before initialization"); + + kterm_lock(kt); + + const ushort filler = ComputeEntry(' ', kt->kt_color); + const size_t bufsize = kt->kt_width * kt->kt_height; + + for (i = 0; i < bufsize; i++) { + // XXX implement memset() + kt->kt_buffer[i] = filler; } - // go back to beginning - current_row = current_col = 0; + kt->kt_curr_x = kt->kt_curr_y = 0; - // XXX cursor update + kterm_unlock(kt); + + return SUCCESS; } -status_t kterm_change_color(uchar color) +// +// Change the color code +// +status_t kterm_change_color(struct kterm *kt, uchar color) { if (color > KTERM_COLOR_WHITE) return BAD_ARG_RANGE; - - current_color = color; + + if (kt == NULL) + return BAD_ARG_NULL; + + kterm_lock(kt); + kt->kt_color = color; + kterm_unlock(kt); return SUCCESS; } -void kterm_putchar(char ch) +// +// Writes a single character on the terminal (UNLOCKED version) +// +// DEPRECATED: +// - always use kterm_putch (LOCKED version) +// - doesn't check for NULL input +// +void kterm_putch_unlocked(struct kterm *kt, char ch) { int i; - size_t prev; - - assert_used_once(kterm_init); + size_t prev_row; // carriage return takes us back to the beginning of the line // no further test should be necessary - if (ch == '\r') { current_col = 0; return; } + if (ch == '\r') { kt->kt_curr_x = 0; return; } // line feed first takes us to the very end of the line // later in this function we actually do the line feed - else if (ch == '\n') { current_col = kterm_width - 1; } + else if (ch == '\n') { kt->kt_curr_y = kt->kt_width - 1; } // tabulations account for 4 spaces else if (ch == '\t') { - prev = current_row; + prev_row = kt->kt_curr_y; // compiler will optimize this away for (i = 0; i < 4; i++) { // tabulations can't spread over two lines - if (current_row != prev) return; - - kterm_putchar(' '); + if (kt->kt_curr_y == prev_row) { + kterm_putch_unlocked(kt, ' '); + } } } // XXX check whether we were given a writable character else { - const size_t offset = ComputeEntryOffset(current_col, current_row); - buffer[offset] = ComputeEntry(ch, current_color); + const size_t offset = ComputeEntryOffset(kt, kt->kt_curr_x, kt->kt_curr_y); + kt->kt_buffer[offset] = ComputeEntry(ch, kt->kt_color); } // end of line? - if (++current_col == kterm_width) { - current_col = 0; + if (++kt->kt_curr_x == kt->kt_width) { + kt->kt_curr_x = 0; - // end of buffer? - if (++current_row == kterm_height) { - current_row = 0; - // XXX save previous buffer(?) and clear + // line feed + end of buffer? + if (++kt->kt_curr_y == kt->kt_height) { + kt->kt_curr_y = 0; } } } -void kterm_print(const char *s) +// +// Writes a single character on the terminal (LOCKED version) +// +status_t kterm_putch(struct kterm *kt, char ch) { - while (*s) { - kterm_putchar(*s); - s++; - } + if (kt == NULL) + return BAD_ARG_NULL; + + kterm_lock(kt); + kterm_putch_unlocked(kt, ch); + kterm_unlock(kt); + + return SUCCESS; } + +// +// Print string on kterminal +// +status_t kterm_print(struct kterm *kt, const char *str) +{ + if (kt == NULL) + return BAD_ARG_NULL; + + kterm_lock(kt); + while (*str) { + kterm_putch_unlocked(kt, *str); + s++; + } + kterm_unlock(kt); + + return SUCCESS; +} + +// +// Panic message +// +const char *panicstr = NULL; + +// +// Your best boy panic() +// void panic(const char *s) { cli(); + ktclear(); + + if (s == NULL) { + s = "(no message given)"; + } + + if (panicstr) { + // shouldn't be possible + ktprint("double panic!\n"); + hlt(); + } + panicstr = s; - kterm_clear(); + ktprint("panic! - "); + ktprint(s); - kterm_print("panic! - "); - kterm_print(s); - - while (1) hlt(); - - __builtin_unreachable(); + while (TRUE) { + hlt(); + } } - - - - - - - - - - - - diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 1ba775a..25ad1cd 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -7,37 +7,60 @@ // Desc: Early terminal functions // //----------------------------------------------------------------------------// -#ifndef __kaleid_kernel_io_terminal_h -#define __kaleid_kernel_io_terminal_h +#ifndef _KALKERN_IO_KTERM_H +#define _KALKERN_IO_KTERM_H #include "common/common.h" // all available colors -enum { - KTERM_COLOR_BLACK, - KTERM_COLOR_BLUE, - KTERM_COLOR_GREEN, - KTERM_COLOR_CYAN, - KTERM_COLOR_RED, - KTERM_COLOR_MAGENTA, - KTERM_COLOR_BROWN, - KTERM_COLOR_LIGHT_GREY, - KTERM_COLOR_DARK_GREY, - KTERM_COLOR_LIGHT_BLUE, - KTERM_COLOR_LIGHT_GREEN, - KTERM_COLOR_LIGHT_CYAN, - KTERM_COLOR_LIGHT_RED, - KTERM_COLOR_LIGHT_MAGENTA, - KTERM_COLOR_LIGHT_BROWN, - KTERM_COLOR_WHITE +enum kterm_color { + KTERM_COLOR_BLACK, KTERM_COLOR_BLUE, + KTERM_COLOR_GREEN, KTERM_COLOR_CYAN, + KTERM_COLOR_RED, KTERM_COLOR_MAGENTA, + KTERM_COLOR_BROWN, KTERM_COLOR_LGREY, + KTERM_COLOR_DARK_GREY, KTERM_COLOR_LBLUE, + KTERM_COLOR_LGREEN, KTERM_COLOR_LCYAN, + KTERM_COLOR_LRED, KTERM_COLOR_LMAGENTA, + KTERM_COLOR_LBROWN, KTERM_COLOR_WHITE }; -void kterm_init(void); -void kterm_clear(void); -void kterm_putchar(char ch); -void kterm_print(const char *s); +struct kterm { + // flags? -status_t kterm_change_color(uchar color) ERRS(BAD_ARG_RANGE); + void *kt_lock; + ushort *kt_buffer; + + uchar kt_color; + size_t kt_width, kt_height; + size_t kt_curr_x, kt_curr_y; + +#ifndef _NO_DEBUG + bool kt_init; +#endif + +}; + +// current "standard" terminal +extern struct kterm *kt_stdout; + +void kterm_init(void); +status_t kterm_clear(struct kterm *); +status_t kterm_putch(struct kterm *, char); +status_t kterm_print(struct kterm *, const char *); +status_t kterm_change_color(struct kterm *, uchar); + +#ifdef _UNLOCKED_IO +void kterm_putch_unlocked(struct kterm *, char ch); +#endif + +#define ktclear() kterm_clear(kt_stdout) +#define ktputch(c) kterm_putch(kt_stdout,c) +#define ktprint(s) kterm_print(kt_stdout,s) +#define ktchcol(c) kterm_change_color(kt_stdout, c) + +#define kterm_lock(kt) +#define kterm_trylock(kt) +#define kterm_unlock(kt) #endif diff --git a/src/kernel.ld b/src/kernel.ld new file mode 100644 index 0000000..86b66ea --- /dev/null +++ b/src/kernel.ld @@ -0,0 +1,49 @@ +ENTRY(kstart) +SECTIONS +{ + . = 0x4000; /* XXX 0x4000 is temporary */ + + .text : AT(ADDR(.text) - 0x4000) + { + _code = .; + *(.text) + *(.rodata*) + . = ALIGN(4096); + } + + .data : AT(ADDR(.data) - 0x4000) + { + _data = .; + *(.data) + . = ALIGN(4096); + } + + .eh_frame : AT(ADDR(.eh_frame) - 0x4000) + { + _ehframe = .; + *(.eh_frame) + . = ALIGN(4096); + } + + .bss : AT(ADDR(.bss) - 0x4000) + { + _bss = .; + *(.bss) + + /* + * You usually need to include generated COMMON symbols + * under kernel BSS section or use gcc's -fno-common + */ + + *(COMMON) + . = ALIGN(4096); + } + + _end = .; + + /DISCARD/ : + { + *(.comment) + } +} + From 003bd3be3c160abc597f4f9b01c987b0ba62ab22 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 24 Dec 2018 22:38:14 +0100 Subject: [PATCH 3/5] x --- src/ChangeLog | 2 +- src/Makefile | 60 ++++++++------------------------- src/boot/loader64.inc | 7 ++-- src/kaleid/common/assert.h | 16 ++++++--- src/kaleid/common/atomic.h | 5 +++ src/kaleid/common/common.h | 2 +- src/kaleid/common/config.h | 17 ++++++++-- src/kaleid/common/config.h.in | 17 ++++++++-- src/kaleid/common/lib/status.c | 31 +++++++++++++++++ src/kaleid/common/lib/string.c | 29 ++++++++++++---- src/kaleid/common/status.h | 3 ++ src/kaleid/common/string.h | 4 ++- src/kaleid/common/types.h | 5 +-- src/kaleid/kernel/init.h | 1 + src/kaleid/kernel/io/ports.h | 4 +-- src/kaleid/kernel/io/terminal.c | 38 ++------------------- src/kaleid/kernel/io/terminal.h | 26 +++++++------- src/kaleid/kernel/ke/panic.c | 59 ++++++++++++++++++++++++++++++++ src/kaleid/kernel/ke/panic.h | 18 ++++++++++ 19 files changed, 221 insertions(+), 123 deletions(-) create mode 100644 src/kaleid/common/lib/status.c create mode 100644 src/kaleid/kernel/ke/panic.c create mode 100644 src/kaleid/kernel/ke/panic.h diff --git a/src/ChangeLog b/src/ChangeLog index e95ff0b..27cc873 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -10,7 +10,7 @@ //----------------------------------------------------------------------------// 2018/10/?? - Started talking about making our own OS -2018/11/?? - Name decided & creation of gnu-os-k.eu +2018/11/?? - Name decided & creation of os-k.eu 2018/12/06 - Actually started project, began MBR, decided directories organization, created this file and others 2018/12/08 - MBR actually supports Long Mode Compatibility Verification - Added A20 line Enabling to MBR diff --git a/src/Makefile b/src/Makefile index a4a69e5..4c61f15 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,11 +8,11 @@ #----------------------------------------------------------------------------# CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" -CWARNS=-Wall -Wextra -Werror -pedantic CLDSCR=-T kernel.ld +CWARNS= -pedantic -Wall -Wextra -Werror CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CDEFINES=-D_KALEID_KERNEL CINCLUDES=-I./kaleid -CDEFINES= CC=$(CCNAME) $(CWARNS) $(CLDSCR) $(CFLAGS) $(CDEFINES) $(CINCLUDES) @@ -57,23 +57,26 @@ COBJDIR=$(OBJDIR)/$(COMMDIR) COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(COMMDIR)/config.h \ $(COMMDIR)/status.h -COBJECTS=$(COBJDIR)/lib/string.o +COBJECTS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o -common: common.lib.string.c $(COMMDEPS) +common: common.lib.string.c common.lib.status.c common.lib.string.c: $(COMMDIR)/lib/string.c $(COMMDEPS) - $(CC) -c $(COMMDIR)/lib/string.c -o $(OBJDIR)/$(COMMDIR)/lib/string.o + $(CC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o + +common.lib.status.c: $(COMMDIR)/lib/status.c $(COMMDEPS) + $(CC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o #----------------------------------------------------------------------------# # KERNEL MAKEFILE KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNDEPS=$(COMMDEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h +KERNDEPS=$(COMMDEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h -kernel: common kernel.io.terminal.c kernel.init.c kernel.io.ports.c +kernel: common kernel.io.terminal.c kernel.init.c kernel.io.ports.c kernel.ke.panic.c $(CC) -o $(BINDIR)/kaleid-kernel.elf \ - $(COBJECTS) $(KOBJDIR)/init.o \ + $(COBJECTS) $(KOBJDIR)/init.o $(KOBJDIR)/ke/panic.o \ $(KOBJDIR)/io/terminal.o $(KOBJDIR)/io/ports.o @@ -85,44 +88,9 @@ kernel.io.ports.c: $(KERNDIR)/io/ports.c $(KERNDEPS) kernel.io.terminal.c: $(KERNDIR)/io/terminal.c $(KERNDEPS) $(CC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +kernel.ke.panic.c: $(KERNDIR)/ke/panic.c $(KERNDEPS) + $(CC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o +#----------------------------------------------------------------------------# diff --git a/src/boot/loader64.inc b/src/boot/loader64.inc index 10406b3..f6611fb 100644 --- a/src/boot/loader64.inc +++ b/src/boot/loader64.inc @@ -5,7 +5,7 @@ ; NeoX ; ; ; ; Desc: Kernel (second stage) Loader for OS/K INCLUDED FUNCTIONS ; -; (x86_64 architecture only) ; +; (x86_64 architecture only) ; ;=----------------------------------------------------------------------------=; [BITS 64] @@ -34,7 +34,7 @@ write: ; bl : color code ; ; esi : string address ; ;-----------------------------------------------------------------------; - mov edi, [NextTRAM] ;TRAM ADDRESS + mov edi, [NextTRAM] ; TRAM ADDRESS push rsi push rdi .pLoop: @@ -49,7 +49,7 @@ write: mov al, bl stosb ; color subpixel add qword [NextTRAM], 0x2 ; Cursor moving - add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels + add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels jmp .pLoop .pEnd: pop rdi @@ -73,3 +73,4 @@ write: .scroll: ; XXX ; jmp .pLoop + diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h index 5e109d3..98aadcc 100644 --- a/src/kaleid/common/assert.h +++ b/src/kaleid/common/assert.h @@ -10,17 +10,19 @@ #ifndef _KALCOMM_ASSERT_H #define _KALCOMM_ASSERT_H -extern const char *panicstr; -extern void panic(const char *) __dead; +#if !defined(_NO_DEBUG) && !defined(NDEBUG) -#if !defined(_NO_DEBUG) +// uses panic() in kernel, abort() in system +noreturn void ___assert_handler(const char *, const char *, int, const char *); -#define assert(x) do{if(!(x))panic(#x);}while(0); +#define assert(x) do{if(!(x))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0); +/* #define assert_never_used(x) do{static bool __##x##_init = FALSE; \ assert(__##x##_init == FALSE); __##x##_init = TRUE;}while(0); #define assert_used_once(x) do{static bool __##x##_init; assert(__##x##_init == TRUE);} while(0); +*/ #else // not debugging @@ -28,9 +30,13 @@ extern void panic(const char *) __dead; #define NDEBUG 1 #endif +#if !defined(_NO_DEBUG) +#define _NO_DEBUG 1 +#endif + #define assert(x) -#define assert_never_used(x) #define assert_used_once(x) +#define assert_never_used(x) #endif diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/atomic.h index f8d9e72..bb4bf04 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/atomic.h @@ -12,9 +12,14 @@ // atomic_t defined in common/types.h +#ifdef _KALEID_KERNEL + +// only available in the kernel #define cli() asm volatile ("cli") #define sti() asm volatile ("sti") #define hlt() asm volatile ("hlt") #endif +#endif + diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 6107b21..9c06922 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -22,7 +22,7 @@ #define NULL ((void*)0) #define PACKED __attribute__((packed)) -#define __dead __attribute__((noreturn)) +#define noreturn __attribute__((noreturn)) #define THROWS(...) #define ERRS(...) diff --git a/src/kaleid/common/config.h b/src/kaleid/common/config.h index 2374b66..501be3d 100644 --- a/src/kaleid/common/config.h +++ b/src/kaleid/common/config.h @@ -20,11 +20,22 @@ // General configuration choices // //------------------------------------------// -// Enable multiprocessor support? -// Right now this has to be left to NO +// +// Enable/disable multiprocessor support +// #define MULTIPROCESSOR NO -// etc... +// +// Enable/disable preemptivity +// +#define PREEMPTIVE YES + +// +// Size of a tabulation in spaces +// Default: 4 spaces/tab +// +#define TABSIZE 4 + // this file is to be progressively filled #endif diff --git a/src/kaleid/common/config.h.in b/src/kaleid/common/config.h.in index 2374b66..501be3d 100644 --- a/src/kaleid/common/config.h.in +++ b/src/kaleid/common/config.h.in @@ -20,11 +20,22 @@ // General configuration choices // //------------------------------------------// -// Enable multiprocessor support? -// Right now this has to be left to NO +// +// Enable/disable multiprocessor support +// #define MULTIPROCESSOR NO -// etc... +// +// Enable/disable preemptivity +// +#define PREEMPTIVE YES + +// +// Size of a tabulation in spaces +// Default: 4 spaces/tab +// +#define TABSIZE 4 + // this file is to be progressively filled #endif diff --git a/src/kaleid/common/lib/status.c b/src/kaleid/common/lib/status.c new file mode 100644 index 0000000..5e8115c --- /dev/null +++ b/src/kaleid/common/lib/status.c @@ -0,0 +1,31 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Implementation of describe_status() // +//----------------------------------------------------------------------------// + +#include "common/common.h" + +static const char *descriptions[] = { + [-SUCCESS] = "Success", + [-FAILED] = "Failed (no precision)", + [-NOT_PERMITTED] = "Operation not permitted", + [-ACCESS_DENIED] = "Access denied", + + [-BAD_ARGUMENT] = "Bad argument", + [-BAD_ARG_RANGE] = "Bad argument (not in range)", + [-BAD_ARG_NULL] = "Bad argument (null pointer)", +}; + +const char *describe_status(status_t status) +{ + (void)descriptions; + (void)status; + + // XXX + return ""; +} + diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index f7093fe..083f269 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -4,21 +4,38 @@ // Authors: spectral` // // NeoX // // // -// Desc: strlen() function // +// Desc: String-related functions // //----------------------------------------------------------------------------// #include "common/string.h" -// -// Return str's length // TODO multibyte, assembly -// + size_t strlen(const char *str) +{ + const char *base = str; + + while (str) str++; + + return (str - base); +} + +char *strcpy(char *dest, const char *src) +{ + char *base = dest; + while ((*dest++ = *src++)); + return base; +} + +char *strncpy(char *dest, const char *src, size_t n) { size_t i; - for (i = 0; str; str++, i++); + for (i = 0; i < n && src[i]; i++) { + dest[i] = src[i]; + } - return i; + while (i < n) dest[i++] = 0; + return dest; } diff --git a/src/kaleid/common/status.h b/src/kaleid/common/status.h index 72e29a1..ee9516e 100644 --- a/src/kaleid/common/status.h +++ b/src/kaleid/common/status.h @@ -14,6 +14,9 @@ #define STATUS_FAILED(x) ((x) < 0)) #define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) +// see in common/lib/status.c for status messages +const char *describe_status(status_t); + #define SUCCESS (0) // everything went fine #define FAILED (-1) diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index 2605063..bf5fdf3 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -13,7 +13,9 @@ #include "common/common.h" -size_t strlen(const char *s); +size_t strlen(const char *); +char *strcpy(char *, const char *); +char *strncpy(char *, const char *, size_t); #endif diff --git a/src/kaleid/common/types.h b/src/kaleid/common/types.h index 57c73bf..abe48a5 100644 --- a/src/kaleid/common/types.h +++ b/src/kaleid/common/types.h @@ -22,9 +22,10 @@ typedef short port_t; typedef uint wchar_t; typedef ulong size_t; typedef long ssize_t; +typedef size_t off_t; -typedef int atomic_t; -typedef ulong pid_t; +typedef int atomic_t; +typedef ulong pid_t; #endif diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index 2b85b67..8238842 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -12,6 +12,7 @@ #include "common/common.h" #include "common/string.h" +#include "kernel/ke/panic.h" // kernel entry point void kstart(void); diff --git a/src/kaleid/kernel/io/ports.h b/src/kaleid/kernel/io/ports.h index cd4c5cc..b2adfbe 100644 --- a/src/kaleid/kernel/io/ports.h +++ b/src/kaleid/kernel/io/ports.h @@ -14,8 +14,8 @@ #define outb(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value)) -uchar inb(port_t port); -ushort inw(port_t port); +uchar inb(port_t); +ushort inw(port_t); #endif diff --git a/src/kaleid/kernel/io/terminal.c b/src/kaleid/kernel/io/terminal.c index 38285a3..503dfcd 100644 --- a/src/kaleid/kernel/io/terminal.c +++ b/src/kaleid/kernel/io/terminal.c @@ -125,7 +125,7 @@ void kterm_putch_unlocked(struct kterm *kt, char ch) else if (ch == '\t') { prev_row = kt->kt_curr_y; // compiler will optimize this away - for (i = 0; i < 4; i++) { + for (i = 0; i < TABSIZE; i++) { // tabulations can't spread over two lines if (kt->kt_curr_y == prev_row) { kterm_putch_unlocked(kt, ' '); @@ -176,45 +176,11 @@ status_t kterm_print(struct kterm *kt, const char *str) kterm_lock(kt); while (*str) { - kterm_putch_unlocked(kt, *str); - s++; + kterm_putch_unlocked(kt, *str++); } kterm_unlock(kt); return SUCCESS; } -// -// Panic message -// -const char *panicstr = NULL; - -// -// Your best boy panic() -// -void panic(const char *s) -{ - cli(); - - ktclear(); - - if (s == NULL) { - s = "(no message given)"; - } - - if (panicstr) { - // shouldn't be possible - ktprint("double panic!\n"); - hlt(); - } - - panicstr = s; - - ktprint("panic! - "); - ktprint(s); - - while (TRUE) { - hlt(); - } -} diff --git a/src/kaleid/kernel/io/terminal.h b/src/kaleid/kernel/io/terminal.h index 25ad1cd..5cb39bf 100644 --- a/src/kaleid/kernel/io/terminal.h +++ b/src/kaleid/kernel/io/terminal.h @@ -25,17 +25,15 @@ enum kterm_color { }; struct kterm { - // flags? - - void *kt_lock; - ushort *kt_buffer; - - uchar kt_color; - size_t kt_width, kt_height; - size_t kt_curr_x, kt_curr_y; - + void *kt_lock; + ushort *kt_buffer; + uchar kt_color; + size_t kt_width; + size_t kt_height; + off_t kt_curr_x; + off_t kt_curr_y; #ifndef _NO_DEBUG - bool kt_init; + bool kt_init; #endif }; @@ -50,13 +48,13 @@ status_t kterm_print(struct kterm *, const char *); status_t kterm_change_color(struct kterm *, uchar); #ifdef _UNLOCKED_IO -void kterm_putch_unlocked(struct kterm *, char ch); +void kterm_putch_unlocked(struct kterm *, char); #endif #define ktclear() kterm_clear(kt_stdout) -#define ktputch(c) kterm_putch(kt_stdout,c) -#define ktprint(s) kterm_print(kt_stdout,s) -#define ktchcol(c) kterm_change_color(kt_stdout, c) +#define ktputch(c) kterm_putch(kt_stdout, (c)) +#define ktprint(s) kterm_print(kt_stdout, (s)) +#define ktchcol(c) kterm_change_color(kt_stdout, (c)) #define kterm_lock(kt) #define kterm_trylock(kt) diff --git a/src/kaleid/kernel/ke/panic.c b/src/kaleid/kernel/ke/panic.c new file mode 100644 index 0000000..04310c6 --- /dev/null +++ b/src/kaleid/kernel/ke/panic.c @@ -0,0 +1,59 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: How NOT to panic 101 // +//----------------------------------------------------------------------------// + +#include "kernel/ke/panic.h" + +// +// Panic message +// +const char *panicstr = NULL; + +// +// Failed assert() handler +// +noreturn void ___assert_handler(const char *msg, const char *file, int line, const char *func) +{ + // not getting out of here + cli(); + + (void)file; (void)line; (void)func; + + // XXX sprintf() to create a proper panicstr + panic(msg); +} + +// +// Your best boy panic() +// +void panic(const char *str) +{ + cli(); + + ktclear(); + + if (str == NULL) { + str = "(no message given)"; + } + + if (panicstr) { + // shouldn't be possible + ktprint("double panic!\n"); + hlt(); + } + + panicstr = str; + + ktprint("panic! - "); + ktprint(str); + + while (TRUE) { + hlt(); + } +} + diff --git a/src/kaleid/kernel/ke/panic.h b/src/kaleid/kernel/ke/panic.h new file mode 100644 index 0000000..403d728 --- /dev/null +++ b/src/kaleid/kernel/ke/panic.h @@ -0,0 +1,18 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Looking to create some panic? Look no further! // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_KE_PANIC_H +#define _KALKERN_KE_PANIC_H + +#include "kernel/io/terminal.h" + +extern const char *panicstr; +noreturn void panic(const char *); + +#endif From f6ea17d9e07727b1f144d6f397194bc0ed15ef3d Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 25 Dec 2018 19:09:58 +0100 Subject: [PATCH 4/5] Expanded standard library --- src/Makefile | 51 +++++++++++----------- src/kaleid/common/assert.h | 27 +++++++----- src/kaleid/common/atomic.h | 4 ++ src/kaleid/common/common.h | 39 +++++++++++------ src/kaleid/common/convert.h | 24 +++++++++++ src/kaleid/common/lib/convert.c | 52 +++++++++++++++++++++++ src/kaleid/common/lib/memory.c | 11 +++++ src/kaleid/common/lib/sprintf.c | 75 +++++++++++++++++++++++++++++++++ src/kaleid/common/lib/string.c | 30 ++++++++++++- src/kaleid/common/memory.h | 18 ++++++++ src/kaleid/common/status.h | 13 ++++-- src/kaleid/common/string.h | 22 ++++++++++ src/kaleid/common/types.h | 38 +++++++++++------ src/kaleid/kernel/init.c | 4 ++ src/kaleid/kernel/init.h | 2 - src/kaleid/linux/test-common.c | 45 ++++++++++++++++++++ 16 files changed, 384 insertions(+), 71 deletions(-) create mode 100644 src/kaleid/common/convert.h create mode 100644 src/kaleid/common/lib/convert.c create mode 100644 src/kaleid/common/lib/memory.c create mode 100644 src/kaleid/common/lib/sprintf.c create mode 100644 src/kaleid/common/memory.h create mode 100644 src/kaleid/linux/test-common.c diff --git a/src/Makefile b/src/Makefile index 4c61f15..79c8836 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,13 +8,15 @@ #----------------------------------------------------------------------------# CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" +CC2NAME=gcc # compiler for testing CLDSCR=-T kernel.ld CWARNS= -pedantic -Wall -Wextra -Werror CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -CDEFINES=-D_KALEID_KERNEL CINCLUDES=-I./kaleid +CDEFINES= -CC=$(CCNAME) $(CWARNS) $(CLDSCR) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +CC=$(CCNAME) $(CWARNS) $(CFLAGS) $(CDEFINES) $(CINCLUDES) +KCC=$(CC) -D_KALEID_KERNEL ASM=nasm ASMFLAGS= @@ -27,6 +29,7 @@ BOOTDIR=boot COMMDIR=kaleid/common KERNDIR=kaleid/kernel SYSTDIR=kaleid/system +LINXDIR=kaleid/linux all: bootloader @@ -53,44 +56,40 @@ testing: bootloader pseudo_kern # COMMON MAKEFILE COBJDIR=$(OBJDIR)/$(COMMDIR) +LOBJDIR=$(OBJDIR)/$(LINXDIR) COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(COMMDIR)/config.h \ $(COMMDIR)/status.h -COBJECTS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o +COMMOBJS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o -common: common.lib.string.c common.lib.status.c +common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c + $(KCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o + $(KCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o -common.lib.string.c: $(COMMDIR)/lib/string.c $(COMMDEPS) - $(CC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o +CCC=$(CC2NAME) $(CWARNS) $(CDEFINES) $(CINCLUDES) -common.lib.status.c: $(COMMDIR)/lib/status.c $(COMMDEPS) - $(CC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o +common-test: + $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o + $(CCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o + $(CCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o + $(CCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf #----------------------------------------------------------------------------# # KERNEL MAKEFILE KOBJDIR=$(OBJDIR)/$(KERNDIR) -KERNDEPS=$(COMMDEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h +KERNDEPS=common $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h +KERNSRCS=$(KERNDIR)/init.c $(KERNDIR)/ke/panic.c $(KERNDIR)/io/ports.c $(KERNDIR)/io/terminal.c +KERNOBJS=$(KOBJDIR)/init.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/io/ports.o $(KOBJDIR)/io/terminal.o -kernel: common kernel.io.terminal.c kernel.init.c kernel.io.ports.c kernel.ke.panic.c - $(CC) -o $(BINDIR)/kaleid-kernel.elf \ - $(COBJECTS) $(KOBJDIR)/init.o $(KOBJDIR)/ke/panic.o \ - $(KOBJDIR)/io/terminal.o $(KOBJDIR)/io/ports.o - - -kernel.init.c: $(KERNDIR)/init.c $(KERNDEPS) - $(CC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o - -kernel.io.ports.c: $(KERNDIR)/io/ports.c $(KERNDEPS) - $(CC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o - -kernel.io.terminal.c: $(KERNDIR)/io/terminal.c $(KERNDEPS) - $(CC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o - -kernel.ke.panic.c: $(KERNDIR)/ke/panic.c $(KERNDEPS) - $(CC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o +kernel: common $(KERNSRCS) + $(KCC) -c $(KERNDIR)/init.c -o $(KOBJDIR)/init.o + $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o + $(KCC) -c $(KERNDIR)/io/ports.c -o $(KOBJDIR)/io/ports.o + $(KCC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o + $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf #----------------------------------------------------------------------------# diff --git a/src/kaleid/common/assert.h b/src/kaleid/common/assert.h index 98aadcc..da80ace 100644 --- a/src/kaleid/common/assert.h +++ b/src/kaleid/common/assert.h @@ -10,19 +10,18 @@ #ifndef _KALCOMM_ASSERT_H #define _KALCOMM_ASSERT_H +#ifndef _KALCOMM_COMMON_H +#error "don't include common/types.h without common/common.h" +#endif + +#ifdef _OSK_SOURCE + #if !defined(_NO_DEBUG) && !defined(NDEBUG) // uses panic() in kernel, abort() in system noreturn void ___assert_handler(const char *, const char *, int, const char *); -#define assert(x) do{if(!(x))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0); - -/* -#define assert_never_used(x) do{static bool __##x##_init = FALSE; \ - assert(__##x##_init == FALSE); __##x##_init = TRUE;}while(0); - -#define assert_used_once(x) do{static bool __##x##_init; assert(__##x##_init == TRUE);} while(0); -*/ +#define assert(x) do{if(unlikely(!(x)))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0); #else // not debugging @@ -35,8 +34,16 @@ noreturn void ___assert_handler(const char *, const char *, int, const char *); #endif #define assert(x) -#define assert_used_once(x) -#define assert_never_used(x) + +#endif + +#else // !defined(_OSK_SOURCE) + +#if defined(_NO_DEBUG) && !defined(NDEBUG) +#define NDEBUG 1 +#endif + +#include #endif diff --git a/src/kaleid/common/atomic.h b/src/kaleid/common/atomic.h index bb4bf04..a1daef3 100644 --- a/src/kaleid/common/atomic.h +++ b/src/kaleid/common/atomic.h @@ -10,6 +10,10 @@ #ifndef _KALCOMM_ATOMIC_H #define _KALCOMM_ATOMIC_H +#ifndef _KALCOMM_COMMON_H +#error "don't include common/types.h without common/common.h" +#endif + // atomic_t defined in common/types.h #ifdef _KALEID_KERNEL diff --git a/src/kaleid/common/common.h b/src/kaleid/common/common.h index 9c06922..9c9dd6a 100644 --- a/src/kaleid/common/common.h +++ b/src/kaleid/common/common.h @@ -7,28 +7,39 @@ // Desc: Standard include file for both kernel/ and system/ // //----------------------------------------------------------------------------// - #ifndef _KALCOMM_COMMON_H #define _KALCOMM_COMMON_H -#define true 1 -#define TRUE 1 -#define YES 1 +#if !defined(_OSK_SOURCE) && (defined(_KALEID_KERNEL) || defined(_KALEID_SYSTEM)) +#define _OSK_SOURCE 1 +#endif -#define false 0 -#define FALSE 0 -#define NO 0 +#if !defined(TRUE) && !defined(FALSE) +# define TRUE 1 +# define FALSE 0 +#endif -#define NULL ((void*)0) +#ifdef _OSK_SOURCE +# define YES 1 +# define NO 0 +#endif -#define PACKED __attribute__((packed)) -#define noreturn __attribute__((noreturn)) +#ifndef NULL +# define NULL ((void*)0) +#endif -#define THROWS(...) -#define ERRS(...) +#ifndef PACKED +# define PACKED __attribute__((packed)) +#endif -#define likely(x) __builtin_expect((x), 1) -#define unlikely(x) __builtin_expect((x), 0) +#ifndef noreturn +# define noreturn __attribute__((noreturn)) +#endif + +#if !defined(likely) && !defined(unlikely) +# define likely(x) __builtin_expect((x), 1) +# define unlikely(x) __builtin_expect((x), 0) +#endif #include "common/types.h" #include "common/config.h" diff --git a/src/kaleid/common/convert.h b/src/kaleid/common/convert.h new file mode 100644 index 0000000..737f016 --- /dev/null +++ b/src/kaleid/common/convert.h @@ -0,0 +1,24 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Conversion utilities // +//----------------------------------------------------------------------------// + +#ifndef _KALCOMM_CONVERT_H +#define _KALCOMM_CONVERT_H + +#ifndef _KALCOMM_COMMON_H +#include "common/common.h" +#endif + +#ifndef _OSK_SOURCE +# define itoa _osk_itoa +# define atoi _osk_atoi +#endif + +char *itoa(int, char *, int); + +#endif diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/lib/convert.c new file mode 100644 index 0000000..2731900 --- /dev/null +++ b/src/kaleid/common/lib/convert.c @@ -0,0 +1,52 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Conversion utilities // +//----------------------------------------------------------------------------// + +#include "common/convert.h" + +// +// Digits table for bases <=36 +// +static const char digits[36] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +// +// Integer to string in any base between 2 and 36 (included) +// +char *itoa(int i, char *str, int base) +{ + int neg = 0; + char *orig = str; + + if (base < 2 || base > 36) + return NULL; + + // deal with negatives + if (i < 0) { + neg = 1; + i = -i; + } + + // deal with zero separatly + if (i == 0) { + *str++ = '0'; + } + + // compute digits... in reverse order (XXX?) + while (i > 0) { + *str++ = digits[i % base]; + i /= base; + } + + if (neg) *str++ = '-'; + *str = '\0'; + + return reverse(orig); +} + + diff --git a/src/kaleid/common/lib/memory.c b/src/kaleid/common/lib/memory.c new file mode 100644 index 0000000..3ebe6ee --- /dev/null +++ b/src/kaleid/common/lib/memory.c @@ -0,0 +1,11 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: mem*() functions // +//----------------------------------------------------------------------------// + +#include "common/memory.h" + diff --git a/src/kaleid/common/lib/sprintf.c b/src/kaleid/common/lib/sprintf.c new file mode 100644 index 0000000..1785a01 --- /dev/null +++ b/src/kaleid/common/lib/sprintf.c @@ -0,0 +1,75 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: sprintf()-related functions // +//----------------------------------------------------------------------------// + +#include "common/string.h" + +// +// Format str according to fmt using ellipsed arguments +// +int sprintf(char *str, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap); + ret = vsnprintf(str, SIZE_T_MAX, fmt, ap); + va_end(ap); + + return ret; +} + +// +// Format str according to fmt, using the va_list ap +// +int vsprintf(char *str, const char *fmt, va_list ap) +{ + return vsnprintf(str, SIZE_T_MAX, fmt, ap); +} + +// +// sprintf() but with a size limit: no more than n bytes are written in str +// XXX null termination behavior? +// +int snprintf(char *str, size_t n, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap); + ret = vsnprintf(str, n, fmt, ap) + va_end(ap); + + return ret; +} + +// +// snprintf() but arguments +// +int vsnprintf(char *str, size_t n, const char *fmt, va_list ap) +{ + int ret = 0; + + while (*fmt && ret < n) { + if (*fmt != '%') { + *str++ = *fmt++; + ret++; + continue; + } + + switch (*fmt) { + case 'd': + default: + break; + } + } + + return ret; +} + + diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index 083f269..f81f60c 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -11,15 +11,21 @@ // TODO multibyte, assembly +// +// Returns str's length +// size_t strlen(const char *str) { const char *base = str; - while (str) str++; + while (*str++); - return (str - base); + return (str - base - 1); } +// +// Copy the string src into dest +// char *strcpy(char *dest, const char *src) { char *base = dest; @@ -27,6 +33,9 @@ char *strcpy(char *dest, const char *src) return base; } +// +// strcpy() but safer +// char *strncpy(char *dest, const char *src, size_t n) { size_t i; @@ -39,3 +48,20 @@ char *strncpy(char *dest, const char *src, size_t n) return dest; } +// +// Reverses a string +// +char *reverse(char *str) +{ + char ch, *orig = str; + size_t n = strlen(str); + char *temp = str + n - 1; + + while (temp > str) { + ch = *temp; + *temp-- = *str; + *str++ = ch; + } + + return orig; +} diff --git a/src/kaleid/common/memory.h b/src/kaleid/common/memory.h new file mode 100644 index 0000000..a877e1a --- /dev/null +++ b/src/kaleid/common/memory.h @@ -0,0 +1,18 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: mem*() functions // +//----------------------------------------------------------------------------// + +#ifndef _KALCOMM_MEMORY_H +#define _KALCOMM_MEMORY_H + +#ifndef _KALCOMM_COMMON_H +#include "common/common.h" +#endif + +#endif + diff --git a/src/kaleid/common/status.h b/src/kaleid/common/status.h index ee9516e..82387da 100644 --- a/src/kaleid/common/status.h +++ b/src/kaleid/common/status.h @@ -7,16 +7,23 @@ // Desc: Values for status_t // //----------------------------------------------------------------------------// - #ifndef _KALCOMM_STATUS_H #define _KALCOMM_STATUS_H -#define STATUS_FAILED(x) ((x) < 0)) -#define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) +#ifndef _KALCOMM_COMMON_H +#error "don't include common/types.h without common/common.h" +#endif + +#ifndef _OSK_SOURCE +# define describe_status _osk_describe_status +#endif // see in common/lib/status.c for status messages const char *describe_status(status_t); +#define STATUS_FAILED(x) ((x) < 0)) +#define STATUS_SUCCESS(x) (!STATUS_FAILED(x)) + #define SUCCESS (0) // everything went fine #define FAILED (-1) diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index bf5fdf3..0f8542d 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -11,11 +11,33 @@ #ifndef _KALCOMM_STRING_H #define _KALCOMM_STRING_H +#ifndef _KALCOMM_COMMON_H #include "common/common.h" +#endif + +#ifndef _OSK_SOURCE + +# define strlen _osk_strlen +# define strcpy _osk_strcpy +# define strncpy _osk_strncpy +# define reverse _osk_reverse + +# define sprintf _osk_sprintf +# define snprintf _osk_snprintf +# define vsprintf _osk_vsprintf +# define vsnprintf _osk_vsnprintf + +#endif size_t strlen(const char *); char *strcpy(char *, const char *); char *strncpy(char *, const char *, size_t); +char *reverse(char *); + +int sprintf(char *, const char *, ...); +int snprintf(char *, size_t, const char *, ...); +int vsprintf(char *, const char *, va_list); +int vsnprintf(char *, size_t, const char *, va_list); #endif diff --git a/src/kaleid/common/types.h b/src/kaleid/common/types.h index abe48a5..fb7d4ff 100644 --- a/src/kaleid/common/types.h +++ b/src/kaleid/common/types.h @@ -11,21 +11,31 @@ #ifndef _KALCOMM_TYPES_H #define _KALCOMM_TYPES_H -typedef _Bool bool; -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned int uint; -typedef unsigned long ulong; -typedef long double ldouble; -typedef short status_t; -typedef short port_t; -typedef uint wchar_t; -typedef ulong size_t; -typedef long ssize_t; -typedef size_t off_t; +#ifndef _KALCOMM_COMMON_H +#error "don't include common/types.h without common/common.h" +#endif -typedef int atomic_t; -typedef ulong pid_t; +#ifndef KEEP_KALCOMM_TYPES_MINIMAL +typedef _Bool bool; +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; +typedef long long llong; +typedef unsigned long long ullong; +typedef long double ldouble; +typedef uint wchar_t; +typedef ullong size_t; +typedef llong ssize_t; +typedef size_t off_t; +typedef int atomic_t; +typedef ulong pid_t; +typedef void *va_list; +#endif + +typedef short port_t; +typedef short status_t; +// XXX limits #endif diff --git a/src/kaleid/kernel/init.c b/src/kaleid/kernel/init.c index 2ea9311..b6f268a 100644 --- a/src/kaleid/kernel/init.c +++ b/src/kaleid/kernel/init.c @@ -8,8 +8,12 @@ //----------------------------------------------------------------------------// #include "kernel/init.h" +#include "kernel/ke/panic.h" #include "kernel/io/terminal.h" +// +// Entry point of kaleid-kernel.elf +// void kstart(void) { kterm_init(); diff --git a/src/kaleid/kernel/init.h b/src/kaleid/kernel/init.h index 8238842..bb80788 100644 --- a/src/kaleid/kernel/init.h +++ b/src/kaleid/kernel/init.h @@ -11,8 +11,6 @@ #define _KALKERN_INIT_H #include "common/common.h" -#include "common/string.h" -#include "kernel/ke/panic.h" // kernel entry point void kstart(void); diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c new file mode 100644 index 0000000..a8c746e --- /dev/null +++ b/src/kaleid/linux/test-common.c @@ -0,0 +1,45 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Test file for common/ // +//----------------------------------------------------------------------------// + +#include +#include +#include + +#define KEEP_KALCOMM_TYPES_MINIMAL + +#include "common/common.h" +#include "common/string.h" + +int main(int argc, char *argv[]) +{ + (void)argc; + (void)argv; + + const char *test1 = "test string\n"; + char *test2 = malloc(strlen(test1)); + char *test3 = malloc(strlen(test1)); + + printf("1\n"); + + #undef strlen + assert(strlen("test string") == _osk_strlen("test string")); + + #undef strcpy + assert(strcmp(strcpy(test2, test1), _osk_strcpy(test3, test1)) == 0); + + + // tests done + printf("2\n"); + + free(test2); + free(test3); + + return 0; +} + From fdcf18e988bfaec933380c59e21ce57c6a4c810c Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 25 Dec 2018 19:40:32 +0100 Subject: [PATCH 5/5] Cleaned up some things --- src/kaleid/common/lib/convert.c | 2 +- src/kaleid/common/lib/sprintf.c | 10 ++-------- src/kaleid/kernel/mm/malloc.c | 12 ++++++++++++ src/kaleid/kernel/mm/malloc.h | 16 ++++++++++++++++ src/kaleid/linux/test-common.c | 1 - src/making.sh | 0 src/project-tree.txt | 2 ++ src/script.sh | 4 ---- 8 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 src/kaleid/kernel/mm/malloc.c create mode 100644 src/kaleid/kernel/mm/malloc.h delete mode 100644 src/making.sh delete mode 100644 src/script.sh diff --git a/src/kaleid/common/lib/convert.c b/src/kaleid/common/lib/convert.c index 2731900..0f76565 100644 --- a/src/kaleid/common/lib/convert.c +++ b/src/kaleid/common/lib/convert.c @@ -37,7 +37,7 @@ char *itoa(int i, char *str, int base) *str++ = '0'; } - // compute digits... in reverse order (XXX?) + // compute digits... in reverse order while (i > 0) { *str++ = digits[i % base]; i /= base; diff --git a/src/kaleid/common/lib/sprintf.c b/src/kaleid/common/lib/sprintf.c index 1785a01..e26ded9 100644 --- a/src/kaleid/common/lib/sprintf.c +++ b/src/kaleid/common/lib/sprintf.c @@ -24,17 +24,14 @@ int sprintf(char *str, const char *fmt, ...) return ret; } -// -// Format str according to fmt, using the va_list ap -// int vsprintf(char *str, const char *fmt, va_list ap) { return vsnprintf(str, SIZE_T_MAX, fmt, ap); } // -// sprintf() but with a size limit: no more than n bytes are written in str -// XXX null termination behavior? +// (v)sprintf() but with a size limit: no more than n bytes are written in str +// XXX null termination behavior? // int snprintf(char *str, size_t n, const char *fmt, ...) { @@ -48,9 +45,6 @@ int snprintf(char *str, size_t n, const char *fmt, ...) return ret; } -// -// snprintf() but arguments -// int vsnprintf(char *str, size_t n, const char *fmt, va_list ap) { int ret = 0; diff --git a/src/kaleid/kernel/mm/malloc.c b/src/kaleid/kernel/mm/malloc.c new file mode 100644 index 0000000..5c62036 --- /dev/null +++ b/src/kaleid/kernel/mm/malloc.c @@ -0,0 +1,12 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Memory allocation routines // +// Only exists to trigger Neox // +//----------------------------------------------------------------------------// + +#include "kernel/mm/malloc.h" + diff --git a/src/kaleid/kernel/mm/malloc.h b/src/kaleid/kernel/mm/malloc.h new file mode 100644 index 0000000..2669121 --- /dev/null +++ b/src/kaleid/kernel/mm/malloc.h @@ -0,0 +1,16 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Memory allocation routines // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_MM_MALLOC_H +#define _KALKERN_MM_MALLOC_H + +#include "common/common.h" + +#endif + diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index a8c746e..a1707c6 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -33,7 +33,6 @@ int main(int argc, char *argv[]) #undef strcpy assert(strcmp(strcpy(test2, test1), _osk_strcpy(test3, test1)) == 0); - // tests done printf("2\n"); diff --git a/src/making.sh b/src/making.sh deleted file mode 100644 index e69de29..0000000 diff --git a/src/project-tree.txt b/src/project-tree.txt index 1304d6a..7e342f8 100644 --- a/src/project-tree.txt +++ b/src/project-tree.txt @@ -7,6 +7,8 @@ // Desc: Project Tree // //----------------------------------------------------------------------------// +// XXX *not* up to date + src/ | + boot/ diff --git a/src/script.sh b/src/script.sh deleted file mode 100644 index 1ef10e1..0000000 --- a/src/script.sh +++ /dev/null @@ -1,4 +0,0 @@ -make -cp ../bin/bootloader.bin "~/Documents/GNU OSK/bin/bootloader.bin" -qemu-system-x86_64 -hda "~/Documents/GNU OSK/bin/bootloader.bin" -qemu-system-i386 -hda "~/Documents/GNU OSK/bin/bootloader.bin"