From ca84a46815ee9bff6fc539e2a845bad31a831c61 Mon Sep 17 00:00:00 2001 From: Christian klahn Date: Mon, 14 Feb 2011 21:59:13 +0100 Subject: [PATCH] =?UTF-8?q?Die=20Zeilenumbr=C3=BCche=20in=20den=20Dateien=20vereinheitlicht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Alle Dateien die CRLF benutzt haben ins Unix Format konvertiert Signed-off-by: Christian Klahn --- src/kernel/include/bitops.h | 44 +- src/kernel/include/console.h | 20 +- src/kernel/include/cpu.h | 58 +- src/kernel/include/debug.h | 62 +- src/kernel/include/kernel.h | 14 +- src/kernel/include/kprintf.h | 14 +- src/kernel/include/multiboot.h | 378 ++++++------ src/kernel/include/tss.h | 98 ++-- src/kernel/include/vmm.h | 106 ++-- src/kernel/src/kernel.ld | 74 ++-- src/kernel/src/stubs.asm | 290 +++++----- src/kernel2/include/console.h | 94 ++-- src/kernel2/include/debug.h | 112 ++-- src/kernel2/include/gdt.h | 88 ++-- src/kernel2/include/im.h | 128 ++-- src/kernel2/include/multiboot.h | 376 ++++++------ src/kernel2/include/smp.h | 86 ++-- src/kernel2/src/module.mk | 32 +- src/kernel2/src/pv.c | 8 +- src/lib/stdlibc/malloc.c | 44 +- src/modules/include/wchar.h | 1176 ++++++++++++++++++------------------ src/modules/init/module.mk | 8 +- src/modules/testlib/test_printf.c | 104 ++-- 23 files changed, 1707 insertions(+), 1707 deletions(-) diff --git a/src/kernel/include/bitops.h b/src/kernel/include/bitops.h index 5f3e4e1..57734dd 100644 --- a/src/kernel/include/bitops.h +++ b/src/kernel/include/bitops.h @@ -1,22 +1,22 @@ -#ifndef BITOPS_H -#define BITOPS_H - -/* Voraussetzung: Mindestens ein Bit von i muss gesetzt sein. */ -static inline unsigned int bit_scan_forward(unsigned int i) -{ - unsigned int j; -#if 0 - for(j = 0; j < 32; j++) - { - if(i & (1 << j)) - { - return j; - } - } -#else - __asm__("bsfl %1, %0\n\t" : "=r"(j) : "g"(i)); - return j; -#endif -} - -#endif /* ndef BITOPS_H */ +#ifndef BITOPS_H +#define BITOPS_H + +/* Voraussetzung: Mindestens ein Bit von i muss gesetzt sein. */ +static inline unsigned int bit_scan_forward(unsigned int i) +{ + unsigned int j; +#if 0 + for(j = 0; j < 32; j++) + { + if(i & (1 << j)) + { + return j; + } + } +#else + __asm__("bsfl %1, %0\n\t" : "=r"(j) : "g"(i)); + return j; +#endif +} + +#endif /* ndef BITOPS_H */ diff --git a/src/kernel/include/console.h b/src/kernel/include/console.h index 146e749..ea151c1 100644 --- a/src/kernel/include/console.h +++ b/src/kernel/include/console.h @@ -1,10 +1,10 @@ -#ifndef CONSOLE_H -#define CONSOLE_H - -extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung der ANSI-Codes -extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertung der ANSI-Codes -extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswertung der ANSI-Codes -extern void con_putsn(unsigned int n, const char * s); // wie con_puts, allerdings werden maximal n Bytes ausgewertet -extern void con_flush_ansi_escape_code_sequence(void); // Zwischenspeicher leeren - -#endif /* ndef CONSOLE_H */ +#ifndef CONSOLE_H +#define CONSOLE_H + +extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung der ANSI-Codes +extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertung der ANSI-Codes +extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswertung der ANSI-Codes +extern void con_putsn(unsigned int n, const char * s); // wie con_puts, allerdings werden maximal n Bytes ausgewertet +extern void con_flush_ansi_escape_code_sequence(void); // Zwischenspeicher leeren + +#endif /* ndef CONSOLE_H */ diff --git a/src/kernel/include/cpu.h b/src/kernel/include/cpu.h index 7e02c04..c006d97 100644 --- a/src/kernel/include/cpu.h +++ b/src/kernel/include/cpu.h @@ -1,29 +1,29 @@ -#ifndef CPU_H -#define CPU_H - -#include - -#define CR0_PE 0x00000001 // Protection Enable -#define CR0_PG 0x80000000 // Paging - -#define CR4_PSE 0x00000010 // Page Size Extensions - -// eflags register -#define FL_TF 0x00000100 // Trap Flag -#define FL_IF 0x00000200 // Interrupt Flag -#define FL_IOPL0 0x00000000 // I/O Privilege Level 0 -#define FL_IOPL1 0x00001000 // I/O Privilege Level 1 -#define FL_IOPL2 0x00002000 // I/O Privilege Level 2 -#define FL_IOPL3 0x00003000 // I/O Privilege Level 3 -#define FL_NT 0x00004000 // Nested Task -#define FL_RF 0x00010000 // Resume Flag -#define FL_VM 0x00020000 // Virtual 8086 mode - -static inline uint32_t read_cr2(void) -{ - uint32_t ret; - __asm volatile ("mov %%cr2, %0" : "=r"(ret)); - return ret; -} - -#endif /* ndef CPU_H */ +#ifndef CPU_H +#define CPU_H + +#include + +#define CR0_PE 0x00000001 // Protection Enable +#define CR0_PG 0x80000000 // Paging + +#define CR4_PSE 0x00000010 // Page Size Extensions + +// eflags register +#define FL_TF 0x00000100 // Trap Flag +#define FL_IF 0x00000200 // Interrupt Flag +#define FL_IOPL0 0x00000000 // I/O Privilege Level 0 +#define FL_IOPL1 0x00001000 // I/O Privilege Level 1 +#define FL_IOPL2 0x00002000 // I/O Privilege Level 2 +#define FL_IOPL3 0x00003000 // I/O Privilege Level 3 +#define FL_NT 0x00004000 // Nested Task +#define FL_RF 0x00010000 // Resume Flag +#define FL_VM 0x00020000 // Virtual 8086 mode + +static inline uint32_t read_cr2(void) +{ + uint32_t ret; + __asm volatile ("mov %%cr2, %0" : "=r"(ret)); + return ret; +} + +#endif /* ndef CPU_H */ diff --git a/src/kernel/include/debug.h b/src/kernel/include/debug.h index ce53df5..f6ec363 100644 --- a/src/kernel/include/debug.h +++ b/src/kernel/include/debug.h @@ -1,31 +1,31 @@ -#include -#include - -/* Debug-Funktionen und Helferlein */ - -#define DEBUG_FLAG_INIT 1 -#define DEBUG_FLAG_STACK_BACKTRACE 2 -#define DEBUG_FLAG_PEDANTIC 4 -#define DEBUG_FLAG_SYSCALL 8 -#define DEBUG_FLAG_NO_KCONSOLE 16 - -/* Int2Str , Wandelt signed ints in Strings um */ -char* int2str(signed int value,char *result); - -/* Einfache Print-Funktion für grundlegende Ausgaben */ -void print(char *string,const int len); - -///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader -void debug_parse_cmdline(char* cmdline); - -///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist -bool debug_test_flag(uint32_t flag); - -///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist -void debug_print(uint32_t flag, const char* message); - -/* - * Gibt einen Stack Backtrace aus, beginnend an den übergebenen Werten - * für ebp und eip - */ -void stack_backtrace_ebp(uint32_t start_ebp, uint32_t start_eip); +#include +#include + +/* Debug-Funktionen und Helferlein */ + +#define DEBUG_FLAG_INIT 1 +#define DEBUG_FLAG_STACK_BACKTRACE 2 +#define DEBUG_FLAG_PEDANTIC 4 +#define DEBUG_FLAG_SYSCALL 8 +#define DEBUG_FLAG_NO_KCONSOLE 16 + +/* Int2Str , Wandelt signed ints in Strings um */ +char* int2str(signed int value,char *result); + +/* Einfache Print-Funktion für grundlegende Ausgaben */ +void print(char *string,const int len); + +///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader +void debug_parse_cmdline(char* cmdline); + +///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist +bool debug_test_flag(uint32_t flag); + +///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist +void debug_print(uint32_t flag, const char* message); + +/* + * Gibt einen Stack Backtrace aus, beginnend an den übergebenen Werten + * für ebp und eip + */ +void stack_backtrace_ebp(uint32_t start_ebp, uint32_t start_eip); diff --git a/src/kernel/include/kernel.h b/src/kernel/include/kernel.h index e5ba427..93a1b42 100644 --- a/src/kernel/include/kernel.h +++ b/src/kernel/include/kernel.h @@ -1,6 +1,6 @@ -#ifndef KERNEL_H -#define KERNEL_H - +#ifndef KERNEL_H +#define KERNEL_H + //#define COOPERATIVE_MULTITASKING #include @@ -21,7 +21,7 @@ void phys_free_page_range(paddr_t page, unsigned int num); extern void kernel_start(void); extern void kernel_phys_start(void); -extern void kernel_end(void); -extern void kernel_phys_end(void); - -#endif /* ndef KERNEL_H */ +extern void kernel_end(void); +extern void kernel_phys_end(void); + +#endif /* ndef KERNEL_H */ diff --git a/src/kernel/include/kprintf.h b/src/kernel/include/kprintf.h index c33ba81..414a9d6 100644 --- a/src/kernel/include/kprintf.h +++ b/src/kernel/include/kprintf.h @@ -1,7 +1,7 @@ -#ifndef KPRINTF_H -#define KPRINTF_H - -extern void kprintf(char * format, ...); -extern void kaprintf(char * format, int ** args); - -#endif /* ndef KPRINTF_H */ +#ifndef KPRINTF_H +#define KPRINTF_H + +extern void kprintf(char * format, ...); +extern void kaprintf(char * format, int ** args); + +#endif /* ndef KPRINTF_H */ diff --git a/src/kernel/include/multiboot.h b/src/kernel/include/multiboot.h index 696679a..c340b5e 100644 --- a/src/kernel/include/multiboot.h +++ b/src/kernel/include/multiboot.h @@ -1,189 +1,189 @@ -/*- - * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Julio M. Merino Vidal. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - - -#ifndef MULTIBOOT_H -#define MULTIBOOT_H - -#include -#include - -/* --------------------------------------------------------------------- */ - -/* - * Multiboot header structure. - */ -#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 -#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 -#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 -#define MULTIBOOT_HEADER_HAS_VBE 0x00000004 -#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 - -struct multiboot_header { - uint32_t mh_magic; - uint32_t mh_flags; - uint32_t mh_checksum; - - /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ - paddr_t mh_header_addr; - paddr_t mh_load_addr; - paddr_t mh_load_end_addr; - paddr_t mh_bss_end_addr; - paddr_t mh_entry_addr; - - /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ - uint32_t mh_mode_type; - uint32_t mh_width; - uint32_t mh_height; - uint32_t mh_depth; -}; - -/* --------------------------------------------------------------------- */ - -/* - * Multiboot information structure. - */ -#define MULTIBOOT_INFO_MAGIC 0x2BADB002 -#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001 -#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002 -#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 -#define MULTIBOOT_INFO_HAS_MODS 0x00000008 -#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010 -#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020 -#define MULTIBOOT_INFO_HAS_MMAP 0x00000040 -#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 -#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100 -#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200 -#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400 -#define MULTIBOOT_INFO_HAS_VBE 0x00000800 - -struct multiboot_info { - uint32_t mi_flags; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ - uint32_t mi_mem_lower; - uint32_t mi_mem_upper; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ - uint8_t mi_boot_device_part3; - uint8_t mi_boot_device_part2; - uint8_t mi_boot_device_part1; - uint8_t mi_boot_device_drive; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ - char * mi_cmdline; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ - uint32_t mi_mods_count; - struct multiboot_module * mi_mods_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ - uint32_t mi_elfshdr_num; - uint32_t mi_elfshdr_size; - vaddr_t mi_elfshdr_addr; - uint32_t mi_elfshdr_shndx; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ - uint32_t mi_mmap_length; - vaddr_t mi_mmap_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ - uint32_t mi_drives_length; - vaddr_t mi_drives_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ - void * unused_mi_config_table; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ - char * mi_loader_name; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ - void * unused_mi_apm_table; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ - void * unused_mi_vbe_control_info; - void * unused_mi_vbe_mode_info; - paddr_t unused_mi_vbe_interface_seg; - paddr_t unused_mi_vbe_interface_off; - uint32_t unused_mi_vbe_interface_len; -}; - -extern struct multiboot_info multiboot_info; - -/* --------------------------------------------------------------------- */ - -/* - * Drive information. This describes an entry in the drives table as - * pointed to by mi_drives_addr. - */ -struct multiboot_drive { - uint32_t md_length; - uint8_t md_number; - uint8_t md_mode; - uint16_t md_cylinders; - uint8_t md_heads; - uint8_t md_sectors; - - /* The variable-sized 'ports' field comes here, so this structure - * can be longer. */ -}; - -/* --------------------------------------------------------------------- */ - -/* - * Memory mapping. This describes an entry in the memory mappings table - * as pointed to by mi_mmap_addr. - * - * Be aware that mm_size specifies the size of all other fields *except* - * for mm_size. In order to jump between two different entries, you - * have to count mm_size + 4 bytes. - */ -struct multiboot_mmap { - uint32_t mm_size; - uint64_t mm_base_addr; - uint64_t mm_length; - uint32_t mm_type; -}; - - -struct multiboot_module { - vaddr_t start; - vaddr_t end; - char* cmdline; - uint32_t reserved; -}; - -#endif +/*- + * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julio M. Merino Vidal. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef MULTIBOOT_H +#define MULTIBOOT_H + +#include +#include + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot header structure. + */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 +#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 +#define MULTIBOOT_HEADER_HAS_VBE 0x00000004 +#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 + +struct multiboot_header { + uint32_t mh_magic; + uint32_t mh_flags; + uint32_t mh_checksum; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ + paddr_t mh_header_addr; + paddr_t mh_load_addr; + paddr_t mh_load_end_addr; + paddr_t mh_bss_end_addr; + paddr_t mh_entry_addr; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ + uint32_t mh_mode_type; + uint32_t mh_width; + uint32_t mh_height; + uint32_t mh_depth; +}; + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot information structure. + */ +#define MULTIBOOT_INFO_MAGIC 0x2BADB002 +#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001 +#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002 +#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 +#define MULTIBOOT_INFO_HAS_MODS 0x00000008 +#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010 +#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020 +#define MULTIBOOT_INFO_HAS_MMAP 0x00000040 +#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 +#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100 +#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200 +#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400 +#define MULTIBOOT_INFO_HAS_VBE 0x00000800 + +struct multiboot_info { + uint32_t mi_flags; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ + uint32_t mi_mem_lower; + uint32_t mi_mem_upper; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ + uint8_t mi_boot_device_part3; + uint8_t mi_boot_device_part2; + uint8_t mi_boot_device_part1; + uint8_t mi_boot_device_drive; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ + char * mi_cmdline; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ + uint32_t mi_mods_count; + struct multiboot_module * mi_mods_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ + uint32_t mi_elfshdr_num; + uint32_t mi_elfshdr_size; + vaddr_t mi_elfshdr_addr; + uint32_t mi_elfshdr_shndx; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ + uint32_t mi_mmap_length; + vaddr_t mi_mmap_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ + uint32_t mi_drives_length; + vaddr_t mi_drives_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ + void * unused_mi_config_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ + char * mi_loader_name; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ + void * unused_mi_apm_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ + void * unused_mi_vbe_control_info; + void * unused_mi_vbe_mode_info; + paddr_t unused_mi_vbe_interface_seg; + paddr_t unused_mi_vbe_interface_off; + uint32_t unused_mi_vbe_interface_len; +}; + +extern struct multiboot_info multiboot_info; + +/* --------------------------------------------------------------------- */ + +/* + * Drive information. This describes an entry in the drives table as + * pointed to by mi_drives_addr. + */ +struct multiboot_drive { + uint32_t md_length; + uint8_t md_number; + uint8_t md_mode; + uint16_t md_cylinders; + uint8_t md_heads; + uint8_t md_sectors; + + /* The variable-sized 'ports' field comes here, so this structure + * can be longer. */ +}; + +/* --------------------------------------------------------------------- */ + +/* + * Memory mapping. This describes an entry in the memory mappings table + * as pointed to by mi_mmap_addr. + * + * Be aware that mm_size specifies the size of all other fields *except* + * for mm_size. In order to jump between two different entries, you + * have to count mm_size + 4 bytes. + */ +struct multiboot_mmap { + uint32_t mm_size; + uint64_t mm_base_addr; + uint64_t mm_length; + uint32_t mm_type; +}; + + +struct multiboot_module { + vaddr_t start; + vaddr_t end; + char* cmdline; + uint32_t reserved; +}; + +#endif diff --git a/src/kernel/include/tss.h b/src/kernel/include/tss.h index fb25620..62c8540 100644 --- a/src/kernel/include/tss.h +++ b/src/kernel/include/tss.h @@ -1,49 +1,49 @@ -#ifndef TSS_H -#define TSS_H - -#include -#include - -#define IO_BITMAP_LENGTH 0xffff - -// Dieser Wert muss ausserhalb des in der GDT definierten Limits -// fuer das TSS liegen -#define TSS_IO_BITMAP_NOT_LOADED (sizeof(tss) + 0x100) -#define TSS_IO_BITMAP_OFFSET offsetof(tss_t, io_bit_map) - -typedef struct tss_s -{ - uint32_t backlink; - uint32_t esp0; - uint32_t ss0; - uint32_t esp1; - uint32_t ss1; - uint32_t esp2; - uint32_t ss2; - uint32_t cr3; - uint32_t eip; - uint32_t eflags; - uint32_t eax; - uint32_t ecx; - uint32_t edx; - uint32_t ebx; - uint32_t esp; - uint32_t ebp; - uint32_t esi; - uint32_t edi; - uint32_t es; - uint32_t cs; - uint32_t ss; - uint32_t ds; - uint32_t fs; - uint32_t gs; - uint32_t ldt; - uint16_t trace_trap; - uint16_t io_bit_map_offset; - uint8_t io_bit_map[IO_BITMAP_LENGTH / 8]; - uint8_t io_bit_map_end; -} __attribute__((packed)) tss_t; - -extern tss_t tss; - -#endif /* ndef TSS_H */ +#ifndef TSS_H +#define TSS_H + +#include +#include + +#define IO_BITMAP_LENGTH 0xffff + +// Dieser Wert muss ausserhalb des in der GDT definierten Limits +// fuer das TSS liegen +#define TSS_IO_BITMAP_NOT_LOADED (sizeof(tss) + 0x100) +#define TSS_IO_BITMAP_OFFSET offsetof(tss_t, io_bit_map) + +typedef struct tss_s +{ + uint32_t backlink; + uint32_t esp0; + uint32_t ss0; + uint32_t esp1; + uint32_t ss1; + uint32_t esp2; + uint32_t ss2; + uint32_t cr3; + uint32_t eip; + uint32_t eflags; + uint32_t eax; + uint32_t ecx; + uint32_t edx; + uint32_t ebx; + uint32_t esp; + uint32_t ebp; + uint32_t esi; + uint32_t edi; + uint32_t es; + uint32_t cs; + uint32_t ss; + uint32_t ds; + uint32_t fs; + uint32_t gs; + uint32_t ldt; + uint16_t trace_trap; + uint16_t io_bit_map_offset; + uint8_t io_bit_map[IO_BITMAP_LENGTH / 8]; + uint8_t io_bit_map_end; +} __attribute__((packed)) tss_t; + +extern tss_t tss; + +#endif /* ndef TSS_H */ diff --git a/src/kernel/include/vmm.h b/src/kernel/include/vmm.h index fefa1db..e08a0e6 100644 --- a/src/kernel/include/vmm.h +++ b/src/kernel/include/vmm.h @@ -1,53 +1,53 @@ -#ifndef VMM_H -#define VMM_H - -#define PAGE_DIRECTORY_LENGTH 1024 -#define PAGE_TABLE_LENGTH 1024 - -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1 << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -// Die Anzahl der Pages, die von n Bytes belegt werden. -#define NUM_PAGES(n) ((((n) + ~PAGE_MASK) & PAGE_MASK) / PAGE_SIZE) - -// Rundet eine Adresse auf das kleinste Vielfache von PAGE_SIZE > n auf -#define PAGE_ALIGN_ROUND_UP(n) (((n) + ~PAGE_MASK) & PAGE_MASK) - -// Rundet eine Adresse auf das größte Vielfache von PAGE_SIZE < n ab -#define PAGE_ALIGN_ROUND_DOWN(n) ((n) & PAGE_MASK) - -#define PGDIR_SHIFT 22 - -#define PTE_P 0x001 // present -#define PTE_W 0x002 // writable -#define PTE_U 0x004 // user -#define PTE_PWT 0x008 // write-through -#define PTE_PCT 0x010 // cache-disable -#define PTE_A 0x020 // accessed -#define PTE_D 0x040 // dirty -#define PTE_PS 0x080 // page size - -#define PTE_AVAIL1 0x200 // available for software use -#define PTE_AVAIL2 0x400 // available for software use -#define PTE_AVAIL3 0x800 // available for software use - -typedef unsigned long * page_directory_t; -typedef unsigned long * page_table_t; - -typedef enum { page_4K, page_4M } page_size_t; - -// Die Adresse, an der der Kernel-Adressraum beginnt -#define KERNEL_BASE 0x00000000 - -// Die Anzahl der Page Tables, die für den Kerneladressraum benötigt werden -#define NUM_KERNEL_PAGE_TABLES (PAGE_DIRECTORY_LENGTH - (KERNEL_BASE >> PGDIR_SHIFT)) - -// Alle Kernel Page Tables werden nach KERNEL_PAGE_TABLES_VADDR gemappt -#define KERNEL_PAGE_TABLES_VADDR 0x3fc00000 - - -#define USER_MEM_START 0x40000000 -#define USER_MEM_END 0xffffffff - -#endif /* ndef VMM_H */ +#ifndef VMM_H +#define VMM_H + +#define PAGE_DIRECTORY_LENGTH 1024 +#define PAGE_TABLE_LENGTH 1024 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +// Die Anzahl der Pages, die von n Bytes belegt werden. +#define NUM_PAGES(n) ((((n) + ~PAGE_MASK) & PAGE_MASK) / PAGE_SIZE) + +// Rundet eine Adresse auf das kleinste Vielfache von PAGE_SIZE > n auf +#define PAGE_ALIGN_ROUND_UP(n) (((n) + ~PAGE_MASK) & PAGE_MASK) + +// Rundet eine Adresse auf das größte Vielfache von PAGE_SIZE < n ab +#define PAGE_ALIGN_ROUND_DOWN(n) ((n) & PAGE_MASK) + +#define PGDIR_SHIFT 22 + +#define PTE_P 0x001 // present +#define PTE_W 0x002 // writable +#define PTE_U 0x004 // user +#define PTE_PWT 0x008 // write-through +#define PTE_PCT 0x010 // cache-disable +#define PTE_A 0x020 // accessed +#define PTE_D 0x040 // dirty +#define PTE_PS 0x080 // page size + +#define PTE_AVAIL1 0x200 // available for software use +#define PTE_AVAIL2 0x400 // available for software use +#define PTE_AVAIL3 0x800 // available for software use + +typedef unsigned long * page_directory_t; +typedef unsigned long * page_table_t; + +typedef enum { page_4K, page_4M } page_size_t; + +// Die Adresse, an der der Kernel-Adressraum beginnt +#define KERNEL_BASE 0x00000000 + +// Die Anzahl der Page Tables, die für den Kerneladressraum benötigt werden +#define NUM_KERNEL_PAGE_TABLES (PAGE_DIRECTORY_LENGTH - (KERNEL_BASE >> PGDIR_SHIFT)) + +// Alle Kernel Page Tables werden nach KERNEL_PAGE_TABLES_VADDR gemappt +#define KERNEL_PAGE_TABLES_VADDR 0x3fc00000 + + +#define USER_MEM_START 0x40000000 +#define USER_MEM_END 0xffffffff + +#endif /* ndef VMM_H */ diff --git a/src/kernel/src/kernel.ld b/src/kernel/src/kernel.ld index 9efbcb0..6ac4663 100644 --- a/src/kernel/src/kernel.ld +++ b/src/kernel/src/kernel.ld @@ -1,37 +1,37 @@ -LOAD_ADDR = 0x100000; -LINK_ADDR = 0x100000; -VIRT_TO_PHYS = LINK_ADDR - LOAD_ADDR; - -ENTRY(_start) -SECTIONS -{ - . = LINK_ADDR; - - kernel_start = .; - kernel_phys_start = . - VIRT_TO_PHYS; - - .text : AT(ADDR(.text) - VIRT_TO_PHYS) - { - *(multiboot) - *(.text) - } - .rodata ALIGN(4096) : AT(ADDR(.rodata) - VIRT_TO_PHYS) - { - *(.rodata) - } - .data ALIGN(4096) : AT(ADDR(.data) - VIRT_TO_PHYS) - { - *(.data) - } - .bss ALIGN(4096) : AT(ADDR(.bss) - VIRT_TO_PHYS) - { - *(.bss) - } - - . = ALIGN(4096); - - kernel_end = .; - kernel_phys_end = . - VIRT_TO_PHYS; - - kernel_size = kernel_end - kernel_start; -} +LOAD_ADDR = 0x100000; +LINK_ADDR = 0x100000; +VIRT_TO_PHYS = LINK_ADDR - LOAD_ADDR; + +ENTRY(_start) +SECTIONS +{ + . = LINK_ADDR; + + kernel_start = .; + kernel_phys_start = . - VIRT_TO_PHYS; + + .text : AT(ADDR(.text) - VIRT_TO_PHYS) + { + *(multiboot) + *(.text) + } + .rodata ALIGN(4096) : AT(ADDR(.rodata) - VIRT_TO_PHYS) + { + *(.rodata) + } + .data ALIGN(4096) : AT(ADDR(.data) - VIRT_TO_PHYS) + { + *(.data) + } + .bss ALIGN(4096) : AT(ADDR(.bss) - VIRT_TO_PHYS) + { + *(.bss) + } + + . = ALIGN(4096); + + kernel_end = .; + kernel_phys_end = . - VIRT_TO_PHYS; + + kernel_size = kernel_end - kernel_start; +} diff --git a/src/kernel/src/stubs.asm b/src/kernel/src/stubs.asm index 681baee..dedf3c5 100644 --- a/src/kernel/src/stubs.asm +++ b/src/kernel/src/stubs.asm @@ -1,145 +1,145 @@ -; -; Copyright (c) 2006 The tyndur Project. All rights reserved. -; -; This code is derived from software contributed to the tyndur Project -; by Burkhard Weseloh. -; -; Redistribution and use in source and binary forms, with or without -; modification, are permitted provided that the following conditions -; are met: -; 1. Redistributions of source code must retain the above copyright -; notice, this list of conditions and the following disclaimer. -; 2. Redistributions in binary form must reproduce the above copyright -; notice, this list of conditions and the following disclaimer in the -; documentation and/or other materials provided with the distribution. -; 3. All advertising materials mentioning features or use of this software -; must display the following acknowledgement: -; This product includes software developed by the tyndur Project -; and its contributors. -; 4. Neither the name of the tyndur Project nor the names of its -; contributors may be used to endorse or promote products derived -; from this software without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR -; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -; - -section .text - -%define IRQ_BASE 0x20 - -extern handle_int - -%macro exception_stub 1 -global exception_stub_%1 -exception_stub_%1: - push dword 0 - push dword %1 - jmp int_bottom -%endmacro - -%macro exception_stub_error_code 1 -global exception_stub_%1 -exception_stub_%1: - push dword %1 - jmp int_bottom -%endmacro - -%macro irq_stub 1 -global irq_stub_%1 -irq_stub_%1: - push dword 0 - push dword %1 + IRQ_BASE - jmp int_bottom -%endmacro - -global null_handler -null_handler: - push dword 0 - push dword 0x1337 - jmp int_bottom - -global syscall_stub -syscall_stub: - push dword 0 - push dword 0x30 - jmp int_bottom - -exception_stub 0 -exception_stub 1 -exception_stub 2 -exception_stub 3 -exception_stub 4 -exception_stub 5 -exception_stub 6 -exception_stub 7 -exception_stub_error_code 8 -exception_stub 9 -exception_stub_error_code 10 -exception_stub_error_code 11 -exception_stub_error_code 12 -exception_stub_error_code 13 -exception_stub_error_code 14 -exception_stub 16 -exception_stub_error_code 17 -exception_stub 18 -exception_stub 19 - -irq_stub 0 -irq_stub 1 -irq_stub 2 -irq_stub 3 -irq_stub 4 -irq_stub 5 -irq_stub 6 -irq_stub 7 -irq_stub 8 -irq_stub 9 -irq_stub 10 -irq_stub 11 -irq_stub 12 -irq_stub 13 -irq_stub 14 -irq_stub 15 - -int_bottom: - ; register sichern - pusha - push ds - push es - push fs - push gs - - ; ring 0 segment register laden - cld - mov ax, 0x10 - mov ds, ax - mov es, ax - - ; c-handler aufrufen - push esp - call handle_int - add esp, 4 - - ; den stack wechseln - mov esp, eax - - ; register laden - pop gs - pop fs - pop es - pop ds - popa - - add esp, 8 ; fehlercode und interrupt nummer überspringen - - iret +; +; Copyright (c) 2006 The tyndur Project. All rights reserved. +; +; This code is derived from software contributed to the tyndur Project +; by Burkhard Weseloh. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; 3. All advertising materials mentioning features or use of this software +; must display the following acknowledgement: +; This product includes software developed by the tyndur Project +; and its contributors. +; 4. Neither the name of the tyndur Project nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR +; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +; + +section .text + +%define IRQ_BASE 0x20 + +extern handle_int + +%macro exception_stub 1 +global exception_stub_%1 +exception_stub_%1: + push dword 0 + push dword %1 + jmp int_bottom +%endmacro + +%macro exception_stub_error_code 1 +global exception_stub_%1 +exception_stub_%1: + push dword %1 + jmp int_bottom +%endmacro + +%macro irq_stub 1 +global irq_stub_%1 +irq_stub_%1: + push dword 0 + push dword %1 + IRQ_BASE + jmp int_bottom +%endmacro + +global null_handler +null_handler: + push dword 0 + push dword 0x1337 + jmp int_bottom + +global syscall_stub +syscall_stub: + push dword 0 + push dword 0x30 + jmp int_bottom + +exception_stub 0 +exception_stub 1 +exception_stub 2 +exception_stub 3 +exception_stub 4 +exception_stub 5 +exception_stub 6 +exception_stub 7 +exception_stub_error_code 8 +exception_stub 9 +exception_stub_error_code 10 +exception_stub_error_code 11 +exception_stub_error_code 12 +exception_stub_error_code 13 +exception_stub_error_code 14 +exception_stub 16 +exception_stub_error_code 17 +exception_stub 18 +exception_stub 19 + +irq_stub 0 +irq_stub 1 +irq_stub 2 +irq_stub 3 +irq_stub 4 +irq_stub 5 +irq_stub 6 +irq_stub 7 +irq_stub 8 +irq_stub 9 +irq_stub 10 +irq_stub 11 +irq_stub 12 +irq_stub 13 +irq_stub 14 +irq_stub 15 + +int_bottom: + ; register sichern + pusha + push ds + push es + push fs + push gs + + ; ring 0 segment register laden + cld + mov ax, 0x10 + mov ds, ax + mov es, ax + + ; c-handler aufrufen + push esp + call handle_int + add esp, 4 + + ; den stack wechseln + mov esp, eax + + ; register laden + pop gs + pop fs + pop es + pop ds + popa + + add esp, 8 ; fehlercode und interrupt nummer überspringen + + iret diff --git a/src/kernel2/include/console.h b/src/kernel2/include/console.h index 60e7e8e..aa29d1c 100644 --- a/src/kernel2/include/console.h +++ b/src/kernel2/include/console.h @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2006-2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Burkhard Weseloh. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the tyndur Project - * and its contributors. - * 4. Neither the name of the tyndur Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CONSOLE_H -#define CONSOLE_H - -extern void init_console(void); - -extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung der ANSI-Codes -extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertung der ANSI-Codes -extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswertung der ANSI-Codes -extern void con_putsn(unsigned int n, const char * s); // wie con_puts, allerdings werden maximal n Bytes ausgewertet -extern void con_flush_ansi_escape_code_sequence(void); // Zwischenspeicher leeren - -#endif /* ndef CONSOLE_H */ +/* + * Copyright (c) 2006-2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Burkhard Weseloh. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONSOLE_H +#define CONSOLE_H + +extern void init_console(void); + +extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung der ANSI-Codes +extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertung der ANSI-Codes +extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswertung der ANSI-Codes +extern void con_putsn(unsigned int n, const char * s); // wie con_puts, allerdings werden maximal n Bytes ausgewertet +extern void con_flush_ansi_escape_code_sequence(void); // Zwischenspeicher leeren + +#endif /* ndef CONSOLE_H */ diff --git a/src/kernel2/include/debug.h b/src/kernel2/include/debug.h index d8540b4..ed8abe3 100644 --- a/src/kernel2/include/debug.h +++ b/src/kernel2/include/debug.h @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2006-2008 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Kevin Wolf. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the tyndur Project - * and its contributors. - * 4. Neither the name of the tyndur Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _DEBUG_H_ -#define _DEBUG_H_ - -#include -#include - -/* Debug-Funktionen und Helferlein */ - -#define DEBUG_FLAG_INIT 1 -#define DEBUG_FLAG_STACK_BACKTRACE 2 -#define DEBUG_FLAG_PEDANTIC 4 -#define DEBUG_FLAG_SYSCALL 8 - -///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader -void debug_parse_cmdline(char* cmdline); - -///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist -bool debug_test_flag(uint32_t flag); - -///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist -void debug_print(uint32_t flag, const char* message); +/* + * Copyright (c) 2006-2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#include +#include + +/* Debug-Funktionen und Helferlein */ + +#define DEBUG_FLAG_INIT 1 +#define DEBUG_FLAG_STACK_BACKTRACE 2 +#define DEBUG_FLAG_PEDANTIC 4 +#define DEBUG_FLAG_SYSCALL 8 + +///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader +void debug_parse_cmdline(char* cmdline); + +///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist +bool debug_test_flag(uint32_t flag); + +///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist +void debug_print(uint32_t flag, const char* message); /* * Gibt einen Stack Backtrace aus, beginnend an den übergebenen Werten diff --git a/src/kernel2/include/gdt.h b/src/kernel2/include/gdt.h index 426775c..243ca70 100644 --- a/src/kernel2/include/gdt.h +++ b/src/kernel2/include/gdt.h @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Kevin Wolf. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the tyndur Project - * and its contributors. - * 4. Neither the name of the tyndur Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _GDT_H_ -#define _GDT_H_ -#include - -void gdt_init(void); -void gdt_init_local(void); - -#endif //ifndef _GDT_H_ - +/* + * Copyright (c) 2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GDT_H_ +#define _GDT_H_ +#include + +void gdt_init(void); +void gdt_init_local(void); + +#endif //ifndef _GDT_H_ + diff --git a/src/kernel2/include/im.h b/src/kernel2/include/im.h index 05f7200..b525a7f 100644 --- a/src/kernel2/include/im.h +++ b/src/kernel2/include/im.h @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Kevin Wolf. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the tyndur Project - * and its contributors. - * 4. Neither the name of the tyndur Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _IM_H_ -#define _IM_H_ - -#include -#include - -#include "cpu.h" -#include "tasks.h" - -#define IM_IRQ_BASE 0x20 -#define IM_NUM_INTERRUPTS 256 - -void im_init(void); -void im_init_local(void); - -void im_enable(void); -void im_disable(void); - -void im_enable_irq(uint8_t irq); -void im_disable_irq(uint8_t irq); - -void im_end_of_interrupt(uint8_t interrupt); -interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf); -interrupt_stack_frame_t* im_prepare_current_thread(void); - -bool im_add_handler(uint32_t intr, pm_process_t* handler); - -#endif //ifndef _IM_H_ - +/* + * Copyright (c) 2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _IM_H_ +#define _IM_H_ + +#include +#include + +#include "cpu.h" +#include "tasks.h" + +#define IM_IRQ_BASE 0x20 +#define IM_NUM_INTERRUPTS 256 + +void im_init(void); +void im_init_local(void); + +void im_enable(void); +void im_disable(void); + +void im_enable_irq(uint8_t irq); +void im_disable_irq(uint8_t irq); + +void im_end_of_interrupt(uint8_t interrupt); +interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf); +interrupt_stack_frame_t* im_prepare_current_thread(void); + +bool im_add_handler(uint32_t intr, pm_process_t* handler); + +#endif //ifndef _IM_H_ + diff --git a/src/kernel2/include/multiboot.h b/src/kernel2/include/multiboot.h index 687fee9..258bebe 100644 --- a/src/kernel2/include/multiboot.h +++ b/src/kernel2/include/multiboot.h @@ -1,188 +1,188 @@ -/*- - * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Julio M. Merino Vidal. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - - -#ifndef MULTIBOOT_H -#define MULTIBOOT_H - -#include - -/* --------------------------------------------------------------------- */ - -/* - * Multiboot header structure. - */ -#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 -#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 -#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 -#define MULTIBOOT_HEADER_HAS_VBE 0x00000004 -#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 - -struct multiboot_header { - uint32_t mh_magic; - uint32_t mh_flags; - uint32_t mh_checksum; - - /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ - uint32_t mh_header_addr; - uint32_t mh_load_addr; - uint32_t mh_load_end_addr; - uint32_t mh_bss_end_addr; - uint32_t mh_entry_addr; - - /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ - uint32_t mh_mode_type; - uint32_t mh_width; - uint32_t mh_height; - uint32_t mh_depth; -} __attribute((packed)); - -/* --------------------------------------------------------------------- */ - -/* - * Multiboot information structure. - */ -#define MULTIBOOT_INFO_MAGIC 0x2BADB002 -#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001 -#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002 -#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 -#define MULTIBOOT_INFO_HAS_MODS 0x00000008 -#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010 -#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020 -#define MULTIBOOT_INFO_HAS_MMAP 0x00000040 -#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 -#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100 -#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200 -#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400 -#define MULTIBOOT_INFO_HAS_VBE 0x00000800 - -struct multiboot_info { - uint32_t mi_flags; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ - uint32_t mi_mem_lower; - uint32_t mi_mem_upper; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ - uint8_t mi_boot_device_part3; - uint8_t mi_boot_device_part2; - uint8_t mi_boot_device_part1; - uint8_t mi_boot_device_drive; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ - uint32_t mi_cmdline; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ - uint32_t mi_mods_count; - uint32_t mi_mods_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ - uint32_t mi_elfshdr_num; - uint32_t mi_elfshdr_size; - uint32_t mi_elfshdr_addr; - uint32_t mi_elfshdr_shndx; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ - uint32_t mi_mmap_length; - uint32_t mi_mmap_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ - uint32_t mi_drives_length; - uint32_t mi_drives_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ - uint32_t unused_mi_config_table; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ - uint32_t mi_loader_name; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ - uint32_t unused_mi_apm_table; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ - uint32_t unused_mi_vbe_control_info; - uint32_t unused_mi_vbe_mode_info; - uint32_t unused_mi_vbe_interface_seg; - uint32_t unused_mi_vbe_interface_off; - uint32_t unused_mi_vbe_interface_len; -} __attribute((packed)); - -extern struct multiboot_info multiboot_info; - -/* --------------------------------------------------------------------- */ - -/* - * Drive information. This describes an entry in the drives table as - * pointed to by mi_drives_addr. - */ -struct multiboot_drive { - uint32_t md_length; - uint8_t md_number; - uint8_t md_mode; - uint16_t md_cylinders; - uint8_t md_heads; - uint8_t md_sectors; - - /* The variable-sized 'ports' field comes here, so this structure - * can be longer. */ -}; - -/* --------------------------------------------------------------------- */ - -/* - * Memory mapping. This describes an entry in the memory mappings table - * as pointed to by mi_mmap_addr. - * - * Be aware that mm_size specifies the size of all other fields *except* - * for mm_size. In order to jump between two different entries, you - * have to count mm_size + 4 bytes. - */ -struct multiboot_mmap { - uint32_t mm_size; - uint64_t mm_base_addr; - uint64_t mm_length; - uint32_t mm_type; -} __attribute((packed)); - - -struct multiboot_module { - uint32_t start; - uint32_t end; - uint32_t cmdline; - uint32_t reserved; -}; - -#endif +/*- + * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julio M. Merino Vidal. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef MULTIBOOT_H +#define MULTIBOOT_H + +#include + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot header structure. + */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 +#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 +#define MULTIBOOT_HEADER_HAS_VBE 0x00000004 +#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 + +struct multiboot_header { + uint32_t mh_magic; + uint32_t mh_flags; + uint32_t mh_checksum; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ + uint32_t mh_header_addr; + uint32_t mh_load_addr; + uint32_t mh_load_end_addr; + uint32_t mh_bss_end_addr; + uint32_t mh_entry_addr; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ + uint32_t mh_mode_type; + uint32_t mh_width; + uint32_t mh_height; + uint32_t mh_depth; +} __attribute((packed)); + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot information structure. + */ +#define MULTIBOOT_INFO_MAGIC 0x2BADB002 +#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001 +#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002 +#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 +#define MULTIBOOT_INFO_HAS_MODS 0x00000008 +#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010 +#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020 +#define MULTIBOOT_INFO_HAS_MMAP 0x00000040 +#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 +#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100 +#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200 +#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400 +#define MULTIBOOT_INFO_HAS_VBE 0x00000800 + +struct multiboot_info { + uint32_t mi_flags; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ + uint32_t mi_mem_lower; + uint32_t mi_mem_upper; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ + uint8_t mi_boot_device_part3; + uint8_t mi_boot_device_part2; + uint8_t mi_boot_device_part1; + uint8_t mi_boot_device_drive; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ + uint32_t mi_cmdline; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ + uint32_t mi_mods_count; + uint32_t mi_mods_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ + uint32_t mi_elfshdr_num; + uint32_t mi_elfshdr_size; + uint32_t mi_elfshdr_addr; + uint32_t mi_elfshdr_shndx; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ + uint32_t mi_mmap_length; + uint32_t mi_mmap_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ + uint32_t mi_drives_length; + uint32_t mi_drives_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ + uint32_t unused_mi_config_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ + uint32_t mi_loader_name; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ + uint32_t unused_mi_apm_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ + uint32_t unused_mi_vbe_control_info; + uint32_t unused_mi_vbe_mode_info; + uint32_t unused_mi_vbe_interface_seg; + uint32_t unused_mi_vbe_interface_off; + uint32_t unused_mi_vbe_interface_len; +} __attribute((packed)); + +extern struct multiboot_info multiboot_info; + +/* --------------------------------------------------------------------- */ + +/* + * Drive information. This describes an entry in the drives table as + * pointed to by mi_drives_addr. + */ +struct multiboot_drive { + uint32_t md_length; + uint8_t md_number; + uint8_t md_mode; + uint16_t md_cylinders; + uint8_t md_heads; + uint8_t md_sectors; + + /* The variable-sized 'ports' field comes here, so this structure + * can be longer. */ +}; + +/* --------------------------------------------------------------------- */ + +/* + * Memory mapping. This describes an entry in the memory mappings table + * as pointed to by mi_mmap_addr. + * + * Be aware that mm_size specifies the size of all other fields *except* + * for mm_size. In order to jump between two different entries, you + * have to count mm_size + 4 bytes. + */ +struct multiboot_mmap { + uint32_t mm_size; + uint64_t mm_base_addr; + uint64_t mm_length; + uint32_t mm_type; +} __attribute((packed)); + + +struct multiboot_module { + uint32_t start; + uint32_t end; + uint32_t cmdline; + uint32_t reserved; +}; + +#endif diff --git a/src/kernel2/include/smp.h b/src/kernel2/include/smp.h index 40098fa..70a4cb1 100644 --- a/src/kernel2/include/smp.h +++ b/src/kernel2/include/smp.h @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Kevin Wolf. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the tyndur Project - * and its contributors. - * 4. Neither the name of the tyndur Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _GDT_H_ -#define _GDT_H_ -#include - -void smp_init(); - -#endif //ifndef _GDT_H_ - +/* + * Copyright (c) 2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GDT_H_ +#define _GDT_H_ +#include + +void smp_init(); + +#endif //ifndef _GDT_H_ + diff --git a/src/kernel2/src/module.mk b/src/kernel2/src/module.mk index 53124c2..3013524 100644 --- a/src/kernel2/src/module.mk +++ b/src/kernel2/src/module.mk @@ -1,16 +1,16 @@ -### Kernel 2 -kernel2: build/lost2.krn - -KERNEL2_SRC = $(call SOURCE_FILES_WILDCARD,src/kernel2/src/arch/$(ARCH)) $(call SOURCE_FILES_WILDCARD,src/kernel2/src/arch/$(ARCH)/*) $(call SOURCE_FILES,src/kernel2/src) $(call SOURCE_FILES_WILDCARD,src/kernel2/src/*) -KERNEL2_OBJS = $(call OBJECT_FILES,$(KERNEL2_SRC)) -ALL_OBJS += $(KERNEL2_OBJS) -build/lost2.krn: $(KERNEL2_OBJS) src/lib/library.a - ld -o $@ $(LDFLAGS_KERNEL2) $^ -build/lost2.krn: CPPFLAGS += -Isrc/kernel2/include -Isrc/kernel2/include/arch/$(ARCH) - -zkernel2: build/lost2.kgz - -src/kernel2/src/smp/rm_trampoline.o: src/kernel2/src/smp/rm_trampoline.asm - $(NASM) -f bin $< -o $(notdir $@) - $(OBJCOPY) -B i386:i386 -I binary -O elf32-i386 $(notdir $@) $@ - rm $(notdir $@) +### Kernel 2 +kernel2: build/lost2.krn + +KERNEL2_SRC = $(call SOURCE_FILES_WILDCARD,src/kernel2/src/arch/$(ARCH)) $(call SOURCE_FILES_WILDCARD,src/kernel2/src/arch/$(ARCH)/*) $(call SOURCE_FILES,src/kernel2/src) $(call SOURCE_FILES_WILDCARD,src/kernel2/src/*) +KERNEL2_OBJS = $(call OBJECT_FILES,$(KERNEL2_SRC)) +ALL_OBJS += $(KERNEL2_OBJS) +build/lost2.krn: $(KERNEL2_OBJS) src/lib/library.a + ld -o $@ $(LDFLAGS_KERNEL2) $^ +build/lost2.krn: CPPFLAGS += -Isrc/kernel2/include -Isrc/kernel2/include/arch/$(ARCH) + +zkernel2: build/lost2.kgz + +src/kernel2/src/smp/rm_trampoline.o: src/kernel2/src/smp/rm_trampoline.asm + $(NASM) -f bin $< -o $(notdir $@) + $(OBJCOPY) -B i386:i386 -I binary -O elf32-i386 $(notdir $@) $@ + rm $(notdir $@) diff --git a/src/kernel2/src/pv.c b/src/kernel2/src/pv.c index 780c352..aec2963 100644 --- a/src/kernel2/src/pv.c +++ b/src/kernel2/src/pv.c @@ -1,4 +1,4 @@ -// Das hier ist ein gemeiner Hack, damit es in den Locking-Funktionen von -// liballoc keine nicht-aufgelösten Symbole gibt. -void __attribute__((weak)) syscall_p(void) {} -void __attribute__((weak)) syscall_v(void) {} +// Das hier ist ein gemeiner Hack, damit es in den Locking-Funktionen von +// liballoc keine nicht-aufgelösten Symbole gibt. +void __attribute__((weak)) syscall_p(void) {} +void __attribute__((weak)) syscall_v(void) {} diff --git a/src/lib/stdlibc/malloc.c b/src/lib/stdlibc/malloc.c index f20f955..95f343a 100644 --- a/src/lib/stdlibc/malloc.c +++ b/src/lib/stdlibc/malloc.c @@ -197,28 +197,28 @@ void* malloc(size_t size) return (void*) current_memory_node->address; } - -/** - * Reserviert einen Speicherbereich für ein Array mit nelem Elementen der - * Groesse elsize, und initialisiert diesen mit 0 - * @param nelem Anzahl der Elemente - * @param elsize Groesse eines Elements - * @return Pointer auf den Bereich - */ -void* calloc(size_t nelem, size_t elsize) -{ - size_t size; - void * p; - - size = nelem * elsize; - p = malloc(size); - if(p != NULL) - { - memset(p, 0, size); - } - - return p; -} + +/** + * Reserviert einen Speicherbereich für ein Array mit nelem Elementen der + * Groesse elsize, und initialisiert diesen mit 0 + * @param nelem Anzahl der Elemente + * @param elsize Groesse eines Elements + * @return Pointer auf den Bereich + */ +void* calloc(size_t nelem, size_t elsize) +{ + size_t size; + void * p; + + size = nelem * elsize; + p = malloc(size); + if(p != NULL) + { + memset(p, 0, size); + } + + return p; +} /** * Gibt einen reservierten Speicherbereich wieder frei. diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h index 6f1f61c..10c33df 100644 --- a/src/modules/include/wchar.h +++ b/src/modules/include/wchar.h @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _WCHAR_H_ -#define _WCHAR_H_ - -#include -#include - -#define WEOF ((wint_t) -1) - -/** - * Sollte theoretisch alle Werte von wchar_t und zusaetzlich WEOF annehmen - * koennen. - */ +/* + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_H_ +#define _WCHAR_H_ + +#include +#include + +#define WEOF ((wint_t) -1) + +/** + * Sollte theoretisch alle Werte von wchar_t und zusaetzlich WEOF annehmen + * koennen. + */ typedef wchar_t wint_t; /** @@ -49,554 +49,554 @@ typedef int (*wctype_t)(wint_t); * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir mit * UTF-8 nicht. */ -typedef int mbstate_t; - - - -/* WSTRINGS */ - -/** - * Reentrante Variante von mbtowc, bei uns mit UTF-8 aber identisch. - * @see mbtowc - */ -size_t mbrtowc(wchar_t* wc, const char* s, size_t len, mbstate_t* ps); - -/** - * Reentrante Variante von wctomb, bei uns mit UTF-8 aber identisch. - * @see wctomb - */ -size_t wcrtomb(char* buf, wchar_t wc, mbstate_t* ps); - -/** - * Reentrante Variante von wcstombs. Der einzige wesentliche Unterschied fuer - * uns mit UTF8 ist, dass *wcs so aktualisiert wird, dass es bei einem Abbruch, - * sei es weil buf zu klein ist oder weil ein ungueltiges Zeichen angetroffen - * wurde, auf das betreffende Zeichen zeigt. Wird der String erfolgreich - * verarbeitet, wird *wcs auf NULL gesetzt. - * @see wcstombs - */ -size_t wcsrtombs(char* buf, const wchar_t** wcs, size_t len, mbstate_t* ps); - -/** - * Reentrante Variante von mbstowcs. Der einzige wesentliche Unterschied fuer - * uns mit UTF8 ist, dass *str so aktualisiert wird, dass es bei einem Abbruch, - * sei es weil buf zu klein ist oder weil ein ungueltiges Zeichen angetroffen - * wurde, auf das betreffende Zeichen zeigt. Wird der String erfolgreich - * verarbeitet, wird *str auf NULL gesetzt. - * @see mbstowcs - */ -size_t mbsrtowcs(wchar_t* buf, const char** str, size_t len, mbstate_t* ps); - - -/** - * Anzahl der Spalten, die ein Zeichen in Anspruch nimmt, errechnen. Fuer c = 0 - * wird 0 zuruekgegeben. Falls es sich nicht um ein druckbares Zeichen handelt, - * wird -1 zurueckgegeben. - * - * @param wc Das breite Zeichen - * - * @return Anzahl Spalten, oder -1 wenn das Zeichen nicht druckbar ist. - */ -int wcwidth(wchar_t wc); - -/** - * Anzahl der Spalten, die ein String aus breiten Zeichen in Anspruch nimmt, - * errechnen. Wird ein nicht druckbares Zeichen erkannt, wird abgebrochen. - * - * @see wcwidth - * @param wcs Zeiger auf das erste Zeichen - * @param len Anzahl der Zeichen - * - * @return Anzahl der Zeichen oder -1 im Fehlerfall. - */ -int wcswidth(const wchar_t* wcs, size_t len); - - -/** - * Einen String aus breiten Zeichen kopieren, das ist das Pendant zu stpcpy. Die - * beiden Strings duerfen sich nicht ueberlappen. Das abschliessende L'0' wird - * mitkopiert. - * - * @see stpcpy - * @see wcscpy - * @see wcpncpy - * @param dst Zeiger auf die Speicherstelle in die der Kopiertestring abgelegt - * werden soll. Dabei muss vom Aufrufer sichergestellt werden, dass - * dort mindestens speicher fuer wcslen(src) + 1 breite Zeichen ist. - * @param src - * - * @return Zeiger auf das Ende (L'0') des Zielstrings. - */ -wchar_t* wcpcpy(wchar_t* dst, const wchar_t* src); - -/** - * String aus breiten Zeichen kopieren. Dabei werden hoechstens len Zeichen - * kopiert. Sind in src weniger als len Zeichen wird dst mit L'\0' aufgefuellt. - * Ist src laenger als oder gleich lang wie len wird der String in dst nich - * nullterminiert, der Rueckgabewert zeigt also nich auf ein L'\0'. Die beiden - * Speicherbereiche duerfen sich nicht ueberlappen. Diese Funktion ist das - * Pendant zu strncpy. - * - * @see strncpy - * @see wcpncpy - * @param dst Zeiger auf den Speicherbereich der len breite Zeichen aufnehmen - * kann. Es werden genau len Zeichen hineingeschrieben. - * @param src Quellstring - * @param len Anzahl der Zeichen, die in dst geschrieben werden sollen. - * - * @return Zeiger auf das letzte geschriebene Byte, also immer dst + len - 1 - */ -wchar_t* wcpncpy(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Zwei Strings aus breiten Zeichen ohne Unterscheidung von - * Gross-/Kleinschreibung vergleichen inklusive abschliessendes L'\0'. Diese - * Funktion ist das Pendant zu strcasecmp. - * - * @see strcasecmp - * @see wcscmp - * @see towlower - * @param wcs1 Erster String - * @param wcs2 Zweiter String - * - * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste - * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es - * groesser >0. - */ -int wcscasecmp(const wchar_t* wcs1, const wchar_t* wcs2); - -/** - * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei wird der Inhalt von - * src inklusive dem abschliessenden L'\0' ans Ende von dst kopiert. Der - * Aufrufer muss sicherstellen, dass nach dst genug Speicher frei ist. Diese - * Funktion ist das Pendant zu strcat. - * - * @see strcat - * @see wcsncat - * @param dst Zeiger auf den String an dessen Ende src angehaengt werden soll. - * @param src Zeiger auf den String der an dst angehaengt werden soll. - * - * @return dst - */ -wchar_t* wcscat(wchar_t* dst, const wchar_t* src); - -/** - * Erstes Vorkommen eines breiten Zeichens aus einem String aus breiten Zeichen - * heraussuchen. Diese Funktion ist das Pendant zu strchr. - * - * @see strchr - * @param wcs Zeiger auf den String in dem gesucht werden soll. - * @param wc Zeichen das gesucht werden soll. - * - * @return Zeiger auf das erste gefundene Zeichen oder NULL wenn keines gefunden - * wurde. - */ -wchar_t* wcschr(const wchar_t* wcs, wchar_t wc); - -/** - * Zwei Strings aus breiten Zeichen inklusive dem abschliessenden L'\0' - * vergleichen. Diese Funktion ist das Pendant zu strcmp. - * - * @param wcs1 Erster String - * @param wcs2 Zweiter String - * - * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste - * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es - * groesser >0. - */ -int wcscmp(const wchar_t* wcs1, const wchar_t* wcs2); - -/** - * TODO - */ -int wcscoll(const wchar_t* wcs1, const wchar_t* wcs2); - -/** - * String aus Breiten Zeichen inklusive abschliessendem L'\0' kopieren. Der - * Aufrufer hat sicherzustellen, dass dst genug Platz bietet. Die beiden Strings - * duerfen sich nicht uberlappen. Diese Funktion ist das Pendant zu strcpy. - * - * @see strcpy - * @see wcsncpy - * @see wcpcpy - * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden - * soll. - * @param src Zeiger auf den String der kopiert werden soll. - * - * @return dst - */ -wchar_t* wcscpy(wchar_t* dst, const wchar_t* src); - -/** - * String aus breiten Zeichen nach einem Vorkommen eines Zeichens aus set - * durchsuchen. Diese Funktion ist das Pendant zu strcspn. - * - * @see strcspn - * @see wcsspn - * @param wcs Zeiger auf den String, dar durchsucht werden soll - * @param set Zeiger auf den String mit den zu suchenden Zeichen. - * - * @return Offset vom Anfang des Strings oder wcslen(wcs) wenn kein Vorkommen - * gefunden wurde. - */ -size_t wcscspn(const wchar_t* wcs, const wchar_t* set); - -/** - * String aus breiten Zeichen in einen neu allozierten Speicherbereich kopieren. - * Diese Funktion ist das Pendant zu strdup. - * - * @see strdup - * @param wcs Zeiger auf den zu kopierenden String - * - * @return Zeiger auf die Kopie. Muss vom Aufrufer freigegeben werden. Im - * Fehlerfall NULL. - */ -wchar_t* wcsdup(const wchar_t* wcs); - -/** - * Kopiert src an das Ende des Strings dst. Dabei wird der String dst auf - * maximal len - 1 Zeichen und L'\0' verlaengert, ausser wenn len == 0. - * - * @see wcsncat - * @param dst Zeiger auf String an den src angehaengt werden soll - * @param src Zeiger auf String der an dst angehaengt werden soll - * @param len Anzahl Zeichen auf die dst Maximal verlaengert werden darf - * inklusiv L'\0.' - * - * @return wcslen(urspruengliches dst) + wcslen(src); Wenn der Rueckgabewert >= - * len ist, wurde src nich vollstaendig kopiert. - */ -size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Kopiert einen String aus breiten Zeichen. Dabei werden maximal len - 1 - * Zeichen kopiert, und dst wird immer mit L'\0' terminiert, wenn len != 0 ist. - * - * @see wcscpy - * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden - * soll. - * @param src Zeiger auf den Quellstring - * @param len Anzahl der Zeichen inklusiv abschliessendes L'\0', die maximal in - * dst geschrieben werden sollen. - * - * @return wcslen(src); Wenn der Rueckgabewert <= len ist, wurde src nicht - * vollstaendig kopiert. - */ -size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Laenge eines Strings aus breiten Zeichen bestimmen. Dabei werden die Zeichen - * gezaehlt, bis ein abschliessendes L'\0' gefunden wird. Das L'\0' wird nicht - * mitgezaehlt. Diese Funktion ist das Pendant zu strlen. - * - * @see strlen - * @param wcs Zeiger auf den String - * - * @return Laenge des Strings in Zeichen - */ -size_t wcslen(const wchar_t* wcs); - -/** - * Zwei Strings aus breiten Zeichen ohne Unterscheidung von - * Gross-/Kleinschreibung vergleichen. Dabei werden maximal die ersten len - * Zeichen von Beiden Strings verglichen. Diese Funktion ist das Pendant zu - * strncasecmp. - * - * @see strncasecmp - * @see wcscasecmp - * @param wcs1 Erster String - * @param wcs2 Zweiter String - * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn - * vorher kein L'\0' gefunden wird. - * - * @return 0 wenn die beiden Strings gleich sind, < 0 wenn das Zeichen in wcs2 - * groesser ist als das in wcs1 und > 0 wenn das Zeichen in wcs1 - * groesser ist als das in wcs2. - */ -int wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); - -/** - * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei werden maximal len - * Zeichen aus src kopiert. Der Aufrufer muss sicherstellen, dass nach dem - * String, auf den dst zeigt, noch mindestens len + 1 Zeichen platz haben. dst - * wird in jedem Fall mit L'\0' terminiert. Diese Funktion ist das Pendant zu - * strncat. - * - * @see strncat - * @see wcscat - * @param dst String an den src angehaengt werden soll - * @param src String der an dst angehaengt werden soll - * @param len Anzahl der Zeichen, die maximal kopiert werden aus src - * - * @return dst - */ -wchar_t* wcsncat(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Zwei Strings aus breiten Zeichen vergleichen. Dabei werden maximal len - * Zeichen verglichen. Diese Funktion ist das Pendant zu strncmp. - * - * @see strncmp - * @see wcscmp - * @param wcs1 Erster String - * @param wcs2 Zweiter String - * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn - * vorher kein abschliessendes L'\0' angetroffen wurde. - * - * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste - * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es - * groesser >0. - */ -int wcsncmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); - -/** - * String aus breiten Zeichen kopieren. Dabei werden maximal len Zeichen - * kopiert. Die restlichen Zeichen im Puffer werden mit L'\0' gefuellt. Ist src - * gleich lang wie oder laenger als len, wird dst nicht mit L'\0' terminiert. - * Die beiden Strings duerfen sich nicht ueberlappen. Diese Funktion ist das - * Pendant zu strncpy. - * - * @see strncpy - * @see wcscpy - * @param src String der kopiert werden soll - * @param dst Zeiger auf den Speicherbereich in den src kopiert werden soll - * @param len Anzahl der Zeichen, die maximal kopiert werden sollen - * - * @return dst - */ -wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Laenge eines Strings aus breiten Zeichen errechnen. Dabei werden maximal max - * Zeichen gezaehlt. Diese Funktion ist das Pendant zu strnlen. - * - * @see strnlen - * @see wcslen - * @param wcs String - * @param max Anzahl der Zeichen, die maximal gezaehlt werden sollen - * - * @return Anzahl der Zeichen ohne abschliessendes L'\0' - */ -size_t wcsnlen(const wchar_t* wcs, size_t max); - -/** - * Erstes vorkommen eines breiten Zeichens aus set im String aus breiten Zeichen - * wcs suchen. Diese Funktion ist das Pendant zu strpbrk. - * - * @see strpbrk - * @see wcschr - * @param wcs String der durchsucht werden soll - * @param set String aus Zeichen nach denen gesucht werden soll - * - * @return Zeiger auf die Position an der ein Zeichen gefunden wurde oder NULL - * falls keines gefunden wurde. - */ -wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* set); - -/** - * Letztes Vorkommen eines breiten Zeichens in einem String aus breiten Zeichen - * suchen. Diese Funktion ist das Pendant zu strrchr. - * - * @see strrchr - * @see wcschr - * @param wcs String der durchsucht werden soll - * @param wc Zeichen das gesucht werden soll - * - * @return Zeiger auf das letzte gefundene Vorkommen, oder NULL falls das - * Zeichen nicht gefunden wurde. - */ -wchar_t* wcsrchr(const wchar_t* wcs, wchar_t wc); - -/** - * Durchsucht einen String aus breiten Zeichen nach dem ersten Zeichen das nicht - * in set vorkommt. Diese Funktion ist das Pendant zu strspn. - * - * @see strspn - * @see wcschr - * @param wcs String der durchsucht werden soll - * @param set Zeichen die zugelassen sind - * - * @return Offset des ersten Zeichens das nicht in set vorkommt, oder - * wcslen(wcs) falls alle Zeichen in set enthalten sind. - */ -size_t wcsspn(const wchar_t* wcs, const wchar_t* set); - -/** - * Erstes Vorkommen des Breiten Strings find in wcs suchen. Diese Funktion ist - * das Pendant zu strstr. - * - * @see strstr - * @see wcschr - * @param wcs String der durchsucht werden soll - * @param find String der gesucht werden soll - * - * @return Zeiger auf das erste Vorkommen in wcs oder NULL falls keines gefunden - * wurde. - */ -wchar_t* wcsstr(const wchar_t* wcs, const wchar_t* find); - -/** - * String aus breiten Zeichen in Tokens aufspalten, die durch die in delim - * angegebenen Zeichen getrennt werden. wcs wird dabei veraendert. Ist wcs != - * NULL beginnt die suche dort, sonst wird bei *last begonnen. *last wird - * jeweils auf den Anfang des naechsten Token gesetzt, oder auf NULL, wenn das - * Ende erreicht wurde. - * Diese Funktion ist das Pendant zu strtok. - * - * @see strtok - * @param wcs Zeiger auf das Zeichen bei dem die Zerlegung in Tokens begonnen - * werden soll, oder NULL, wenn der Wert von *last genommen werden - * soll. - * @param delim Zeichen die zwei Tokens voneinander trennen koennen - * @param last Zeiger auf die Speicherstelle an der die Funktion die Position - * des naechsten token speichern kann fuer den internen Gebrauch, - * um beim Naechsten Aufruf mit wcs == NULL das naechste Token - * zurueck geben zu koennen. - * - * @return Zeiger auf das aktuelle Token, oder NULL wenn keine Tokens mehr - * vorhanden sind. - */ -wchar_t* wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** last); - -/** - * Speicherbereich aus breiten Zeichen nach einem bestimmten Zeichen - * durchsuchen. Diese Funktion ist das Pendant zu memchr. - * - * @see memchr - * @see wcschr - * @param wcs Zeiger auf den Speicherbereich - * @param wc Zu suchendes Zeichen - * @param len Laenge des Speicherbereichs - * - * @return Zeiger auf das gefundene Zeichen oder NULL falls keines gefunden - * wurde. - */ -wchar_t* wmemchr(const wchar_t* wcs, wchar_t wc, size_t len); - -/** - * Zwei Speicherbereiche aus breiten Zeichen vergleichen. Diese Funktion ist das - * Pendant zu memcmp. - * - * @see memcmp - * @see wcscpm - * @see wcsncmp - * @param wcs1 Zeiger auf den ersten Speicherbereich - * @param wcs2 Zeiger auf den zweiten Speicherbereich - * @param len Laenge der beiden Speicherbereiche - * - * @return 0 wenn die beiden Speicherbereiche gleich sind, < 0 wenn das erste - * unterschiedliche Zeichen in wcs1 kleiner ist als das - * Korrespondierende in wcs2 oder > 0 wenn es groesser ist. - */ -int wmemcmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); - -/** - * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche - * duerfen sich nicht ueberlappen. Diese Funktion ist das Pendant zu memcpy. - * - * @see memcpy - * @see wcsncpy - * @see wcscpy - * @param dst Speicherbereich in den kopiert werden soll - * @param src Speicherbereich der kopiert werden soll - * @param len Laenge der Speicherbereiche - * - * @return dst - */ -wchar_t* wmemcpy(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche - * duerfen sich ueberlappen. Diese Funktion ist das Pendant zu memcpy. - * - * @see memmove - * @see wmemcpy - * @param dst Speicherbereich in den kopiert werden soll - * @param src Speicherbereich der kopiert werden soll - * @param len Laenge der Speicherbereiche - * - * @return dst - */ -wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t len); - -/** - * Speicherbereich aus breiten Zeichen mit einem bestimmten Zeichen ausfuellen. - * Diese Funktion ist das pendant zu memset. - * - * @see memset - * @param wcs Zeiger auf den Speicherbereich - * @param wc Zeichen mit dem der Speicherbereich gefuellt werden soll - * @param len Laenge des Speicherbereichs - * - * @return wcs - */ -wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t len); - - - - -/* WSTDIO */ - -/** - * Breites Zeichen aus einer Datei lesen. - * - * @param stream Die geoeffnete Datei - * - * @return Das gelesene Zeichen oder WEOF im Fehlerfall. - */ -wint_t fgetwc(FILE* stream); - -/** - * Wie fgetwc, mit dem Unterschied, dass getwc als Makro implementiert werden - * darf, das den Parameter mehrmals auswertet - * - * @see fgetwc - */ -#define getwc(stream) fgetwc(stream) - -/** - * Breites Zeichen von der Standardeingabe lesen. - * - * @see fgetwc - */ -wint_t getwchar(void); - - -/** - * Ein breites Zeichen in eine Datei schreiben, dabei wird das Zeichen - * entsprechend codiert. - * - * @param wc Das zu schreibende Zeichen - * @param stream Die geoeffnete Datei - * - * @return Das geschriebene Zeichen oder WEOF im Fehlerfall - */ -wint_t fputwc(wchar_t wc, FILE* stream); - -/** - * Wie fputwc, mit dem Unterschied, dass putwc als Makro implementiert werden - * darf, das seine Parameter mehrmals auswertet. - * - * @see fputwc - */ -#define putwc(wc, stream) fputwc(wc, stream) - -/** - * Breites Zeichen auf die Standardausgabe schreiben - * - * @see fputwc - * @param wc Das zu schreibende Zeichen - * - * @return Das geschriebene Zeichen oder WEOF im Fehlerfall - */ -wint_t putwchar(wchar_t wc); - -/** - * Einen String aus breiten Zeichen in den angegebenen Stream schreiben. - * - * @param wcs Zeiger auf den String aus breiten Zeichen - * @param stream Die geoeffnete Datei - * +typedef int mbstate_t; + + + +/* WSTRINGS */ + +/** + * Reentrante Variante von mbtowc, bei uns mit UTF-8 aber identisch. + * @see mbtowc + */ +size_t mbrtowc(wchar_t* wc, const char* s, size_t len, mbstate_t* ps); + +/** + * Reentrante Variante von wctomb, bei uns mit UTF-8 aber identisch. + * @see wctomb + */ +size_t wcrtomb(char* buf, wchar_t wc, mbstate_t* ps); + +/** + * Reentrante Variante von wcstombs. Der einzige wesentliche Unterschied fuer + * uns mit UTF8 ist, dass *wcs so aktualisiert wird, dass es bei einem Abbruch, + * sei es weil buf zu klein ist oder weil ein ungueltiges Zeichen angetroffen + * wurde, auf das betreffende Zeichen zeigt. Wird der String erfolgreich + * verarbeitet, wird *wcs auf NULL gesetzt. + * @see wcstombs + */ +size_t wcsrtombs(char* buf, const wchar_t** wcs, size_t len, mbstate_t* ps); + +/** + * Reentrante Variante von mbstowcs. Der einzige wesentliche Unterschied fuer + * uns mit UTF8 ist, dass *str so aktualisiert wird, dass es bei einem Abbruch, + * sei es weil buf zu klein ist oder weil ein ungueltiges Zeichen angetroffen + * wurde, auf das betreffende Zeichen zeigt. Wird der String erfolgreich + * verarbeitet, wird *str auf NULL gesetzt. + * @see mbstowcs + */ +size_t mbsrtowcs(wchar_t* buf, const char** str, size_t len, mbstate_t* ps); + + +/** + * Anzahl der Spalten, die ein Zeichen in Anspruch nimmt, errechnen. Fuer c = 0 + * wird 0 zuruekgegeben. Falls es sich nicht um ein druckbares Zeichen handelt, + * wird -1 zurueckgegeben. + * + * @param wc Das breite Zeichen + * + * @return Anzahl Spalten, oder -1 wenn das Zeichen nicht druckbar ist. + */ +int wcwidth(wchar_t wc); + +/** + * Anzahl der Spalten, die ein String aus breiten Zeichen in Anspruch nimmt, + * errechnen. Wird ein nicht druckbares Zeichen erkannt, wird abgebrochen. + * + * @see wcwidth + * @param wcs Zeiger auf das erste Zeichen + * @param len Anzahl der Zeichen + * + * @return Anzahl der Zeichen oder -1 im Fehlerfall. + */ +int wcswidth(const wchar_t* wcs, size_t len); + + +/** + * Einen String aus breiten Zeichen kopieren, das ist das Pendant zu stpcpy. Die + * beiden Strings duerfen sich nicht ueberlappen. Das abschliessende L'0' wird + * mitkopiert. + * + * @see stpcpy + * @see wcscpy + * @see wcpncpy + * @param dst Zeiger auf die Speicherstelle in die der Kopiertestring abgelegt + * werden soll. Dabei muss vom Aufrufer sichergestellt werden, dass + * dort mindestens speicher fuer wcslen(src) + 1 breite Zeichen ist. + * @param src + * + * @return Zeiger auf das Ende (L'0') des Zielstrings. + */ +wchar_t* wcpcpy(wchar_t* dst, const wchar_t* src); + +/** + * String aus breiten Zeichen kopieren. Dabei werden hoechstens len Zeichen + * kopiert. Sind in src weniger als len Zeichen wird dst mit L'\0' aufgefuellt. + * Ist src laenger als oder gleich lang wie len wird der String in dst nich + * nullterminiert, der Rueckgabewert zeigt also nich auf ein L'\0'. Die beiden + * Speicherbereiche duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcpncpy + * @param dst Zeiger auf den Speicherbereich der len breite Zeichen aufnehmen + * kann. Es werden genau len Zeichen hineingeschrieben. + * @param src Quellstring + * @param len Anzahl der Zeichen, die in dst geschrieben werden sollen. + * + * @return Zeiger auf das letzte geschriebene Byte, also immer dst + len - 1 + */ +wchar_t* wcpncpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen inklusive abschliessendes L'\0'. Diese + * Funktion ist das Pendant zu strcasecmp. + * + * @see strcasecmp + * @see wcscmp + * @see towlower + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscasecmp(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei wird der Inhalt von + * src inklusive dem abschliessenden L'\0' ans Ende von dst kopiert. Der + * Aufrufer muss sicherstellen, dass nach dst genug Speicher frei ist. Diese + * Funktion ist das Pendant zu strcat. + * + * @see strcat + * @see wcsncat + * @param dst Zeiger auf den String an dessen Ende src angehaengt werden soll. + * @param src Zeiger auf den String der an dst angehaengt werden soll. + * + * @return dst + */ +wchar_t* wcscat(wchar_t* dst, const wchar_t* src); + +/** + * Erstes Vorkommen eines breiten Zeichens aus einem String aus breiten Zeichen + * heraussuchen. Diese Funktion ist das Pendant zu strchr. + * + * @see strchr + * @param wcs Zeiger auf den String in dem gesucht werden soll. + * @param wc Zeichen das gesucht werden soll. + * + * @return Zeiger auf das erste gefundene Zeichen oder NULL wenn keines gefunden + * wurde. + */ +wchar_t* wcschr(const wchar_t* wcs, wchar_t wc); + +/** + * Zwei Strings aus breiten Zeichen inklusive dem abschliessenden L'\0' + * vergleichen. Diese Funktion ist das Pendant zu strcmp. + * + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscmp(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * TODO + */ +int wcscoll(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * String aus Breiten Zeichen inklusive abschliessendem L'\0' kopieren. Der + * Aufrufer hat sicherzustellen, dass dst genug Platz bietet. Die beiden Strings + * duerfen sich nicht uberlappen. Diese Funktion ist das Pendant zu strcpy. + * + * @see strcpy + * @see wcsncpy + * @see wcpcpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den String der kopiert werden soll. + * + * @return dst + */ +wchar_t* wcscpy(wchar_t* dst, const wchar_t* src); + +/** + * String aus breiten Zeichen nach einem Vorkommen eines Zeichens aus set + * durchsuchen. Diese Funktion ist das Pendant zu strcspn. + * + * @see strcspn + * @see wcsspn + * @param wcs Zeiger auf den String, dar durchsucht werden soll + * @param set Zeiger auf den String mit den zu suchenden Zeichen. + * + * @return Offset vom Anfang des Strings oder wcslen(wcs) wenn kein Vorkommen + * gefunden wurde. + */ +size_t wcscspn(const wchar_t* wcs, const wchar_t* set); + +/** + * String aus breiten Zeichen in einen neu allozierten Speicherbereich kopieren. + * Diese Funktion ist das Pendant zu strdup. + * + * @see strdup + * @param wcs Zeiger auf den zu kopierenden String + * + * @return Zeiger auf die Kopie. Muss vom Aufrufer freigegeben werden. Im + * Fehlerfall NULL. + */ +wchar_t* wcsdup(const wchar_t* wcs); + +/** + * Kopiert src an das Ende des Strings dst. Dabei wird der String dst auf + * maximal len - 1 Zeichen und L'\0' verlaengert, ausser wenn len == 0. + * + * @see wcsncat + * @param dst Zeiger auf String an den src angehaengt werden soll + * @param src Zeiger auf String der an dst angehaengt werden soll + * @param len Anzahl Zeichen auf die dst Maximal verlaengert werden darf + * inklusiv L'\0.' + * + * @return wcslen(urspruengliches dst) + wcslen(src); Wenn der Rueckgabewert >= + * len ist, wurde src nich vollstaendig kopiert. + */ +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Kopiert einen String aus breiten Zeichen. Dabei werden maximal len - 1 + * Zeichen kopiert, und dst wird immer mit L'\0' terminiert, wenn len != 0 ist. + * + * @see wcscpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den Quellstring + * @param len Anzahl der Zeichen inklusiv abschliessendes L'\0', die maximal in + * dst geschrieben werden sollen. + * + * @return wcslen(src); Wenn der Rueckgabewert <= len ist, wurde src nicht + * vollstaendig kopiert. + */ +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Laenge eines Strings aus breiten Zeichen bestimmen. Dabei werden die Zeichen + * gezaehlt, bis ein abschliessendes L'\0' gefunden wird. Das L'\0' wird nicht + * mitgezaehlt. Diese Funktion ist das Pendant zu strlen. + * + * @see strlen + * @param wcs Zeiger auf den String + * + * @return Laenge des Strings in Zeichen + */ +size_t wcslen(const wchar_t* wcs); + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen. Dabei werden maximal die ersten len + * Zeichen von Beiden Strings verglichen. Diese Funktion ist das Pendant zu + * strncasecmp. + * + * @see strncasecmp + * @see wcscasecmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein L'\0' gefunden wird. + * + * @return 0 wenn die beiden Strings gleich sind, < 0 wenn das Zeichen in wcs2 + * groesser ist als das in wcs1 und > 0 wenn das Zeichen in wcs1 + * groesser ist als das in wcs2. + */ +int wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei werden maximal len + * Zeichen aus src kopiert. Der Aufrufer muss sicherstellen, dass nach dem + * String, auf den dst zeigt, noch mindestens len + 1 Zeichen platz haben. dst + * wird in jedem Fall mit L'\0' terminiert. Diese Funktion ist das Pendant zu + * strncat. + * + * @see strncat + * @see wcscat + * @param dst String an den src angehaengt werden soll + * @param src String der an dst angehaengt werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden aus src + * + * @return dst + */ +wchar_t* wcsncat(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Zwei Strings aus breiten Zeichen vergleichen. Dabei werden maximal len + * Zeichen verglichen. Diese Funktion ist das Pendant zu strncmp. + * + * @see strncmp + * @see wcscmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein abschliessendes L'\0' angetroffen wurde. + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcsncmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * String aus breiten Zeichen kopieren. Dabei werden maximal len Zeichen + * kopiert. Die restlichen Zeichen im Puffer werden mit L'\0' gefuellt. Ist src + * gleich lang wie oder laenger als len, wird dst nicht mit L'\0' terminiert. + * Die beiden Strings duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcscpy + * @param src String der kopiert werden soll + * @param dst Zeiger auf den Speicherbereich in den src kopiert werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden sollen + * + * @return dst + */ +wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Laenge eines Strings aus breiten Zeichen errechnen. Dabei werden maximal max + * Zeichen gezaehlt. Diese Funktion ist das Pendant zu strnlen. + * + * @see strnlen + * @see wcslen + * @param wcs String + * @param max Anzahl der Zeichen, die maximal gezaehlt werden sollen + * + * @return Anzahl der Zeichen ohne abschliessendes L'\0' + */ +size_t wcsnlen(const wchar_t* wcs, size_t max); + +/** + * Erstes vorkommen eines breiten Zeichens aus set im String aus breiten Zeichen + * wcs suchen. Diese Funktion ist das Pendant zu strpbrk. + * + * @see strpbrk + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set String aus Zeichen nach denen gesucht werden soll + * + * @return Zeiger auf die Position an der ein Zeichen gefunden wurde oder NULL + * falls keines gefunden wurde. + */ +wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* set); + +/** + * Letztes Vorkommen eines breiten Zeichens in einem String aus breiten Zeichen + * suchen. Diese Funktion ist das Pendant zu strrchr. + * + * @see strrchr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param wc Zeichen das gesucht werden soll + * + * @return Zeiger auf das letzte gefundene Vorkommen, oder NULL falls das + * Zeichen nicht gefunden wurde. + */ +wchar_t* wcsrchr(const wchar_t* wcs, wchar_t wc); + +/** + * Durchsucht einen String aus breiten Zeichen nach dem ersten Zeichen das nicht + * in set vorkommt. Diese Funktion ist das Pendant zu strspn. + * + * @see strspn + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set Zeichen die zugelassen sind + * + * @return Offset des ersten Zeichens das nicht in set vorkommt, oder + * wcslen(wcs) falls alle Zeichen in set enthalten sind. + */ +size_t wcsspn(const wchar_t* wcs, const wchar_t* set); + +/** + * Erstes Vorkommen des Breiten Strings find in wcs suchen. Diese Funktion ist + * das Pendant zu strstr. + * + * @see strstr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param find String der gesucht werden soll + * + * @return Zeiger auf das erste Vorkommen in wcs oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wcsstr(const wchar_t* wcs, const wchar_t* find); + +/** + * String aus breiten Zeichen in Tokens aufspalten, die durch die in delim + * angegebenen Zeichen getrennt werden. wcs wird dabei veraendert. Ist wcs != + * NULL beginnt die suche dort, sonst wird bei *last begonnen. *last wird + * jeweils auf den Anfang des naechsten Token gesetzt, oder auf NULL, wenn das + * Ende erreicht wurde. + * Diese Funktion ist das Pendant zu strtok. + * + * @see strtok + * @param wcs Zeiger auf das Zeichen bei dem die Zerlegung in Tokens begonnen + * werden soll, oder NULL, wenn der Wert von *last genommen werden + * soll. + * @param delim Zeichen die zwei Tokens voneinander trennen koennen + * @param last Zeiger auf die Speicherstelle an der die Funktion die Position + * des naechsten token speichern kann fuer den internen Gebrauch, + * um beim Naechsten Aufruf mit wcs == NULL das naechste Token + * zurueck geben zu koennen. + * + * @return Zeiger auf das aktuelle Token, oder NULL wenn keine Tokens mehr + * vorhanden sind. + */ +wchar_t* wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** last); + +/** + * Speicherbereich aus breiten Zeichen nach einem bestimmten Zeichen + * durchsuchen. Diese Funktion ist das Pendant zu memchr. + * + * @see memchr + * @see wcschr + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zu suchendes Zeichen + * @param len Laenge des Speicherbereichs + * + * @return Zeiger auf das gefundene Zeichen oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wmemchr(const wchar_t* wcs, wchar_t wc, size_t len); + +/** + * Zwei Speicherbereiche aus breiten Zeichen vergleichen. Diese Funktion ist das + * Pendant zu memcmp. + * + * @see memcmp + * @see wcscpm + * @see wcsncmp + * @param wcs1 Zeiger auf den ersten Speicherbereich + * @param wcs2 Zeiger auf den zweiten Speicherbereich + * @param len Laenge der beiden Speicherbereiche + * + * @return 0 wenn die beiden Speicherbereiche gleich sind, < 0 wenn das erste + * unterschiedliche Zeichen in wcs1 kleiner ist als das + * Korrespondierende in wcs2 oder > 0 wenn es groesser ist. + */ +int wmemcmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich nicht ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memcpy + * @see wcsncpy + * @see wcscpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemcpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memmove + * @see wmemcpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Speicherbereich aus breiten Zeichen mit einem bestimmten Zeichen ausfuellen. + * Diese Funktion ist das pendant zu memset. + * + * @see memset + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zeichen mit dem der Speicherbereich gefuellt werden soll + * @param len Laenge des Speicherbereichs + * + * @return wcs + */ +wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t len); + + + + +/* WSTDIO */ + +/** + * Breites Zeichen aus einer Datei lesen. + * + * @param stream Die geoeffnete Datei + * + * @return Das gelesene Zeichen oder WEOF im Fehlerfall. + */ +wint_t fgetwc(FILE* stream); + +/** + * Wie fgetwc, mit dem Unterschied, dass getwc als Makro implementiert werden + * darf, das den Parameter mehrmals auswertet + * + * @see fgetwc + */ +#define getwc(stream) fgetwc(stream) + +/** + * Breites Zeichen von der Standardeingabe lesen. + * + * @see fgetwc + */ +wint_t getwchar(void); + + +/** + * Ein breites Zeichen in eine Datei schreiben, dabei wird das Zeichen + * entsprechend codiert. + * + * @param wc Das zu schreibende Zeichen + * @param stream Die geoeffnete Datei + * + * @return Das geschriebene Zeichen oder WEOF im Fehlerfall + */ +wint_t fputwc(wchar_t wc, FILE* stream); + +/** + * Wie fputwc, mit dem Unterschied, dass putwc als Makro implementiert werden + * darf, das seine Parameter mehrmals auswertet. + * + * @see fputwc + */ +#define putwc(wc, stream) fputwc(wc, stream) + +/** + * Breites Zeichen auf die Standardausgabe schreiben + * + * @see fputwc + * @param wc Das zu schreibende Zeichen + * + * @return Das geschriebene Zeichen oder WEOF im Fehlerfall + */ +wint_t putwchar(wchar_t wc); + +/** + * Einen String aus breiten Zeichen in den angegebenen Stream schreiben. + * + * @param wcs Zeiger auf den String aus breiten Zeichen + * @param stream Die geoeffnete Datei + * * @return Bei Erfolg > 0, im Fehlerfall -1 */ int fputws(const wchar_t* wcs, FILE* stream); diff --git a/src/modules/init/module.mk b/src/modules/init/module.mk index 84fdeba..f5b9fce 100644 --- a/src/modules/init/module.mk +++ b/src/modules/init/module.mk @@ -1,5 +1,5 @@ -# Die Variablennamen sind immer Name des Moduls + _SRC bzw. _OBJS. -# Die .c-Dateien im Unterverzeichnis zlib hinzufügen. -init_SRC += $(call SOURCE_FILES,$(MODULE_PATH)/zlib)) -# Die Liste der Objektdateien aktualisieren. +# Die Variablennamen sind immer Name des Moduls + _SRC bzw. _OBJS. +# Die .c-Dateien im Unterverzeichnis zlib hinzufügen. +init_SRC += $(call SOURCE_FILES,$(MODULE_PATH)/zlib)) +# Die Liste der Objektdateien aktualisieren. init_OBJS := $(call OBJECT_FILES,$(init_SRC)) \ No newline at end of file diff --git a/src/modules/testlib/test_printf.c b/src/modules/testlib/test_printf.c index b7b4815..633f7c8 100644 --- a/src/modules/testlib/test_printf.c +++ b/src/modules/testlib/test_printf.c @@ -1,52 +1,52 @@ -#include "stdio.h" -#include - -// toter code. tests.c entsprechend modifizieren. -void test_printf(void) -{ - printf("TESTE PRINTF \n"); - - printf("printf: "); - printf("a"); - printf("%c", 'b'); - printf("%s", "c1"); - printf("%d", 23); - printf("%o", 045); - printf("%x (erwartet: abc1234567890)\n", 0x67890); - - unsigned long long ull = 12345678901234567890ULL; - printf("llu:\t\t%llu%llu\n (erwartet:\t1234567890123456789012345678901234567890)\n", ull, ull); - printf("lld:\t\t%lld%lld\n (erwartet:\t-6101065172474983726-6101065172474983726)\n", ull, ull); - - printf("[%d], [%8d], [% 8d], [%08d], [%-8d] (erwartet: ->\n[-123], [ -123], [ -123], [-0000123], [-123 ])\n", -123, -123, -123, -123, -123); - - printf("[%s], [%5s], [%-5s] (erwartet [abc], [ abc], [abc ])\n", "abc", "abc", "abc"); - -#define STRINGIFY(x...) #x -#define TOSTRING(x) STRINGIFY(x) - -#define FORMAT "a%c%s%d%o%x" -#define ARGS 'b', "c1", 23, 045, 0x67890 - - char buf[1000]; - int ret, n, i, len[]={0, 8, 13, 14}; - char* expected[]={"OOPS", "abc1234", "abc123456789", "abc1234567890"}; - printf("sprintf: \n"); - ret = sprintf(buf, FORMAT, ARGS); - printf("\tsprintf(buf, \"%s\", %s)=%d\n\tbuf=%s, strlen(buf)=%u\n", FORMAT, TOSTRING(ARGS), ret, buf, strlen(buf)); - - printf("snprintf: snprintf(buf, n, \"%s\", %s)\n", FORMAT, TOSTRING(ARGS)); - for(i = 0; i < 4; i++) - { - n = len[i]; - buf[n] = 'O'; buf[n+1] = 'O'; buf[n+2] = 'P'; buf[n+3] = 'S'; buf[n+4] = 0; - ret = snprintf(buf, n, FORMAT, ARGS); - printf("\tsnprintf(...,n=%d,...)=%d, buf=%s, strlen(buf)=%u (erwartet %s)\n", n, ret, buf, strlen(buf), expected[i]); - } - - printf("asprintf: "); - char * retbuf; - ret = asprintf(&retbuf, FORMAT, ARGS); - printf(" %p %s %u\n (erwartet: irgendwas!=0, abc1234567890, 13)", retbuf, retbuf, strlen(retbuf)); - -} +#include "stdio.h" +#include + +// toter code. tests.c entsprechend modifizieren. +void test_printf(void) +{ + printf("TESTE PRINTF \n"); + + printf("printf: "); + printf("a"); + printf("%c", 'b'); + printf("%s", "c1"); + printf("%d", 23); + printf("%o", 045); + printf("%x (erwartet: abc1234567890)\n", 0x67890); + + unsigned long long ull = 12345678901234567890ULL; + printf("llu:\t\t%llu%llu\n (erwartet:\t1234567890123456789012345678901234567890)\n", ull, ull); + printf("lld:\t\t%lld%lld\n (erwartet:\t-6101065172474983726-6101065172474983726)\n", ull, ull); + + printf("[%d], [%8d], [% 8d], [%08d], [%-8d] (erwartet: ->\n[-123], [ -123], [ -123], [-0000123], [-123 ])\n", -123, -123, -123, -123, -123); + + printf("[%s], [%5s], [%-5s] (erwartet [abc], [ abc], [abc ])\n", "abc", "abc", "abc"); + +#define STRINGIFY(x...) #x +#define TOSTRING(x) STRINGIFY(x) + +#define FORMAT "a%c%s%d%o%x" +#define ARGS 'b', "c1", 23, 045, 0x67890 + + char buf[1000]; + int ret, n, i, len[]={0, 8, 13, 14}; + char* expected[]={"OOPS", "abc1234", "abc123456789", "abc1234567890"}; + printf("sprintf: \n"); + ret = sprintf(buf, FORMAT, ARGS); + printf("\tsprintf(buf, \"%s\", %s)=%d\n\tbuf=%s, strlen(buf)=%u\n", FORMAT, TOSTRING(ARGS), ret, buf, strlen(buf)); + + printf("snprintf: snprintf(buf, n, \"%s\", %s)\n", FORMAT, TOSTRING(ARGS)); + for(i = 0; i < 4; i++) + { + n = len[i]; + buf[n] = 'O'; buf[n+1] = 'O'; buf[n+2] = 'P'; buf[n+3] = 'S'; buf[n+4] = 0; + ret = snprintf(buf, n, FORMAT, ARGS); + printf("\tsnprintf(...,n=%d,...)=%d, buf=%s, strlen(buf)=%u (erwartet %s)\n", n, ret, buf, strlen(buf), expected[i]); + } + + printf("asprintf: "); + char * retbuf; + ret = asprintf(&retbuf, FORMAT, ARGS); + printf(" %p %s %u\n (erwartet: irgendwas!=0, abc1234567890, 13)", retbuf, retbuf, strlen(retbuf)); + +} -- 1.7.1