From 622b4cfe3cbb73302fdfa97c5c4d9d4c9cabddb2 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Thu, 2 May 2013 22:31:00 -0600 Subject: [PATCH] split kernel lib sources into their own directory and handled the section differences with a partial link and a special link script --- armcompile.mk | 2 +- include/comrogue/internals/seg.h | 5 - include/comrogue/internals/trace.h | 4 - kernel/Makefile | 9 +- kernel/{kernel.Lds => kernel.ldi} | 0 kernel/lib/Makefile | 43 +++++++ kernel/{ => lib}/divide.S | 2 - kernel/{ => lib}/intlib.c | 4 +- kernel/lib/kernel-lib.ldi | 182 +++++++++++++++++++++++++++++ kernel/{ => lib}/lib_guids.c | 3 +- kernel/{ => lib}/objhelp.c | 10 +- kernel/{ => lib}/qdivrem.c | 7 +- kernel/{ => lib}/quad.h | 0 kernel/{ => lib}/rbtree.c | 40 +++---- kernel/{ => lib}/str.c | 26 ++--- kernel/{ => lib}/strcomparemem.S | 2 - kernel/{ => lib}/strcopymem.S | 2 - kernel/{ => lib}/strsetmem.S | 2 - 18 files changed, 272 insertions(+), 71 deletions(-) rename kernel/{kernel.Lds => kernel.ldi} (100%) create mode 100644 kernel/lib/Makefile rename kernel/{ => lib}/divide.S (99%) rename kernel/{ => lib}/intlib.c (95%) create mode 100644 kernel/lib/kernel-lib.ldi rename kernel/{ => lib}/lib_guids.c (97%) rename kernel/{ => lib}/objhelp.c (91%) rename kernel/{ => lib}/qdivrem.c (96%) rename kernel/{ => lib}/quad.h (100%) rename kernel/{ => lib}/rbtree.c (92%) rename kernel/{ => lib}/str.c (93%) rename kernel/{ => lib}/strcomparemem.S (99%) rename kernel/{ => lib}/strcopymem.S (99%) rename kernel/{ => lib}/strsetmem.S (99%) diff --git a/armcompile.mk b/armcompile.mk index 3a57732..c3f26a2 100644 --- a/armcompile.mk +++ b/armcompile.mk @@ -50,7 +50,7 @@ AFLAGS := -mcpu=arm1176jzf-s -mfloat-abi=hard ASM_CPP_FLAGS := $(INCLUDES) $(DEFS) -D__ASM__ # Standard rule for pre-processing linker script files. -%.lds: %.Lds +%.lds: %.ldi $(CPP) $(ASM_CPP_FLAGS) -P -o $@ $< # Standard rule for preprocessing and assembling assembler files. diff --git a/include/comrogue/internals/seg.h b/include/comrogue/internals/seg.h index 0c41602..e9d6c73 100644 --- a/include/comrogue/internals/seg.h +++ b/include/comrogue/internals/seg.h @@ -49,8 +49,6 @@ #define SEG_INIT_DATA __attribute__((__section__(".prestart.data"))) #define SEG_INIT_RODATA __attribute__((__section__(".prestart.rodata"))) #define SEG_RODATA SEG_INIT_RODATA -#define SEG_LIB_CODE SEG_INIT_CODE -#define SEG_LIB_RODATA SEG_INIT_RODATA #else @@ -58,8 +56,6 @@ #define SEG_INIT_DATA __attribute__((__section__(".init.data"))) #define SEG_INIT_RODATA __attribute__((__section__(".init.rodata"))) #define SEG_RODATA __attribute__((__section__(".rodata"))) -#define SEG_LIB_CODE __attribute__((__section__(".lib.text"))) -#define SEG_LIB_RODATA __attribute__((__section__(".lib.rodata"))) #endif /* __COMROGUE_PRESTART__ */ @@ -70,7 +66,6 @@ #define DECLARE_STRING8_CONST_STGCLASS(name, value, stgclass) const CHAR stgclass name [] = value #define DECLARE_INIT_STRING8_CONST(name, value) DECLARE_STRING8_CONST_STGCLASS(name, value, SEG_INIT_RODATA) -#define DECLARE_LIB_STRING8_CONST(name, value) DECLARE_STRING8_CONST_STGCLASS(name, value, SEG_LIB_RODATA) #define DECLARE_STRING8_CONST(name, value) DECLARE_STRING8_CONST_STGCLASS(name, value, SEG_RODATA) #endif /* __ASM__ */ diff --git a/include/comrogue/internals/trace.h b/include/comrogue/internals/trace.h index c3a8379..bd16ec3 100644 --- a/include/comrogue/internals/trace.h +++ b/include/comrogue/internals/trace.h @@ -90,12 +90,8 @@ CDECL_END #if defined(__COMROGUE_PRESTART__) || defined(__COMROGUE_INIT__) #define DECLARE_THIS_FILE static DECLARE_INIT_STRING8_CONST(THIS_FILE, __FILE__); #else -#if defined(__COMROGUE_KERNEL_LIB__) -#define DECLARE_THIS_FILE static DECLARE_LIB_STRING8_CONST(THIS_FILE, __FILE__); -#else #define DECLARE_THIS_FILE static DECLARE_STRING8_CONST(THIS_FILE, __FILE__); #endif -#endif #define ASSERT(x) ((x) ? (void)0 : ASSERT_FAIL_FUNC(THIS_FILE, __LINE__)) #define VERIFY(x) ASSERT(x) diff --git a/kernel/Makefile b/kernel/Makefile index fb6e9fc..4c57750 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -33,14 +33,16 @@ CRBASEDIR := $(abspath ..) include $(CRBASEDIR)/armcompile.mk PRESTART_OBJS = prestart.o early_trace.o collect_startup.o early_mm.o -LIB_OBJS = divide.o qdivrem.o intlib.o objhelp.o rbtree.o str.o strcopymem.o strcomparemem.o strsetmem.o lib_guids.o RES_OBJS = lowlevel.o trace.o memmgr.o vmmap.o pagealloc.o kernel_space.o INIT_OBJS = start.o kistart.o init_heap.o all: kernel.img -kernel.elf: $(PRESTART_OBJS) $(LIB_OBJS) $(RES_OBJS) $(INIT_OBJS) kernel.lds - $(LD) -T kernel.lds $(PRESTART_OBJS) $(LIB_OBJS) $(RES_OBJS) $(INIT_OBJS) -o kernel.elf +kernel.elf: $(PRESTART_OBJS) lib/kernel-lib.o $(RES_OBJS) $(INIT_OBJS) kernel.lds + $(LD) -T kernel.lds $(PRESTART_OBJS) lib/kernel-lib.o $(RES_OBJS) $(INIT_OBJS) -o kernel.elf + +lib/kernel-lib.o: + make -C lib kernel.img: kernel.elf $(OBJDUMP) -D kernel.elf > kernel.list @@ -50,3 +52,4 @@ kernel.img: kernel.elf clean: -rm *.o *.s *.lds kernel.img kernel.elf kernel.list kernel.syms* + make -C lib clean \ No newline at end of file diff --git a/kernel/kernel.Lds b/kernel/kernel.ldi similarity index 100% rename from kernel/kernel.Lds rename to kernel/kernel.ldi diff --git a/kernel/lib/Makefile b/kernel/lib/Makefile new file mode 100644 index 0000000..4ccef91 --- /dev/null +++ b/kernel/lib/Makefile @@ -0,0 +1,43 @@ +# +# This file is part of the COMROGUE Operating System for Raspberry Pi +# +# Copyright (c) 2013, Eric J. Bowersox / Erbosoft Enterprises +# All rights reserved. +# +# This program is free for commercial and non-commercial use as long as the following conditions are +# adhered to. +# +# Copyright in this file remains Eric J. Bowersox and/or Erbosoft, and as such any copyright notices +# in the code are not to be removed. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions and +# the following disclaimer. +# * 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 HOLDER 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. +# +# "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. +MAKEFLAGS += -rR +CRBASEDIR := $(abspath ../..) +include $(CRBASEDIR)/armcompile.mk + +LIB_OBJS = divide.o qdivrem.o intlib.o objhelp.o rbtree.o str.o strcopymem.o strcomparemem.o strsetmem.o lib_guids.o + +all: kernel-lib.o + +kernel-lib.o: $(LIB_OBJS) kernel-lib.lds + $(LD) -r -T kernel-lib.lds $(LIB_OBJS) -o kernel-lib.o + +clean: + -rm *.o *.s *.lds diff --git a/kernel/divide.S b/kernel/lib/divide.S similarity index 99% rename from kernel/divide.S rename to kernel/lib/divide.S index 3f2ec37..f11e1a1 100644 --- a/kernel/divide.S +++ b/kernel/lib/divide.S @@ -32,8 +32,6 @@ * SUCH DAMAGE. */ /* Derived from FreeBSD libkern divsi3.S, uldivmod.S, and ldivmod.S, munged by Erbo to COMROGUE standards */ -.section ".lib.text" - .globl __aeabi_uidiv .globl __aeabi_uidivmod __aeabi_uidiv: diff --git a/kernel/intlib.c b/kernel/lib/intlib.c similarity index 95% rename from kernel/intlib.c rename to kernel/lib/intlib.c index b06b303..efc97d8 100644 --- a/kernel/intlib.c +++ b/kernel/lib/intlib.c @@ -29,10 +29,8 @@ * * "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. */ -#define __COMROGUE_KERNEL_LIB__ #include #include -#include #include "quad.h" /*--------------------------- @@ -55,7 +53,7 @@ * Returns: * Standard SUCCEEDED/FAILED HRESULT. */ -SEG_LIB_CODE HRESULT IntLDiv(PLDIV pResult, INT64 num, INT64 denom) +HRESULT IntLDiv(PLDIV pResult, INT64 num, INT64 denom) { UINT32 mode = 0; if (denom == 0) diff --git a/kernel/lib/kernel-lib.ldi b/kernel/lib/kernel-lib.ldi new file mode 100644 index 0000000..c5c6928 --- /dev/null +++ b/kernel/lib/kernel-lib.ldi @@ -0,0 +1,182 @@ +/* + * This file is part of the COMROGUE Operating System for Raspberry Pi + * + * Copyright (c) 2013, Eric J. Bowersox / Erbosoft Enterprises + * All rights reserved. + * + * This program is free for commercial and non-commercial use as long as the following conditions are + * adhered to. + * + * Copyright in this file remains Eric J. Bowersox and/or Erbosoft, and as such any copyright notices + * in the code are not to be removed. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * * 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 HOLDER 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. + * + * "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. + */ +/* Copied from default linker script for relocatable linking under ARM & modified */ +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") +OUTPUT_ARCH(arm) + +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .interp 0 : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash 0 : { *(.hash) } + .gnu.hash 0 : { *(.gnu.hash) } + .dynsym 0 : { *(.dynsym) } + .dynstr 0 : { *(.dynstr) } + .gnu.version 0 : { *(.gnu.version) } + .gnu.version_d 0: { *(.gnu.version_d) } + .gnu.version_r 0: { *(.gnu.version_r) } + .rel.init 0 : { *(.rel.init) } + .rela.init 0 : { *(.rela.init) } + .rel.text 0 : { *(.rel.text) } + .rela.text 0 : { *(.rela.text) } + .rel.fini 0 : { *(.rel.fini) } + .rela.fini 0 : { *(.rela.fini) } + .rel.rodata 0 : { *(.rel.rodata) } + .rela.rodata 0 : { *(.rela.rodata) } + .rel.ctors 0 : { *(.rel.ctors) } + .rela.ctors 0 : { *(.rela.ctors) } + .rel.dtors 0 : { *(.rel.dtors) } + .rela.dtors 0 : { *(.rela.dtors) } + .rel.got 0 : { *(.rel.got) } + .rela.got 0 : { *(.rela.got) } + .rel.bss 0 : { *(.rel.bss) } + .rela.bss 0 : { *(.rela.bss) } + .rel.iplt 0 : + { + *(.rel.iplt) + } + .rela.iplt 0 : + { + *(.rela.iplt) + } + .rel.plt 0 : + { + *(.rel.plt) + } + .rela.plt 0 : + { + *(.rela.plt) + } + .init 0 : + { + KEEP (*(.init)) + } =0 + .plt 0 : { *(.plt) } + .iplt 0 : { *(.iplt) } + .lib.text 0 : + { + *(.text .stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0 + .fini 0 : + { + KEEP (*(.fini)) + } =0 + .lib.rodata 0 : { *(.rodata) } + .lib.rodata1 0 : { *(.rodata1) } + .ARM.extab 0 : { *(.ARM.extab) } + .ARM.exidx 0 : { *(.ARM.exidx) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame 0 : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table 0 : ONLY_IF_RO { *(.gcc_except_table + .gcc_except_table.*) } + /* These sections are generated by the Sun/Oracle C++ compiler. */ + .exception_ranges 0 : ONLY_IF_RO { *(.exception_ranges + .exception_ranges*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + /* Exception handling */ + .eh_frame 0 : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table 0 : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + .exception_ranges 0 : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } + /* Thread Local Storage sections */ + .preinit_array 0 : + { + KEEP (*(.preinit_array)) + } + .jcr 0 : { KEEP (*(.jcr)) } + .dynamic 0 : { *(.dynamic) } + .got 0 : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .stack 0 : + { + *(.stack) + } + .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + + /* we don't allow data in the library section, so discard all data segments */ + /DISCARD/ : { + *(.rel.data.rel.ro) + *(.rela.data.rel.ro) + *(.rel.data) + *(.rela.data) + *(.data) + *(.data1) + *(.dynbss) + *(.bss) + *(COMMON) + *(.rel.tdata) + *(.rela.tdata) + *(.rel.tbss) + *(.rela.tbss) + *(.tdata) + *(.tbss) + } +} diff --git a/kernel/lib_guids.c b/kernel/lib/lib_guids.c similarity index 97% rename from kernel/lib_guids.c rename to kernel/lib/lib_guids.c index af036d4..716c7c3 100644 --- a/kernel/lib_guids.c +++ b/kernel/lib/lib_guids.c @@ -35,9 +35,8 @@ * AND in this order. *------------------------------------------------------------------------------------------------------ */ -#define __COMROGUE_KERNEL_LIB__ #include -#define GUIDATTR SEG_LIB_RODATA +#define GUIDATTR SEG_RODATA #define INITGUID #include diff --git a/kernel/objhelp.c b/kernel/lib/objhelp.c similarity index 91% rename from kernel/objhelp.c rename to kernel/lib/objhelp.c index b3746ea..959856a 100644 --- a/kernel/objhelp.c +++ b/kernel/lib/objhelp.c @@ -29,7 +29,6 @@ * * "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. */ -#define __COMROGUE_KERNEL_LIB__ #include #include #include @@ -38,7 +37,6 @@ #include #include #include -#include /*-------------------------------------------- * Standard object functions (API-type calls) @@ -55,7 +53,7 @@ * Returns: * TRUE if the GUIDs are equal, FALSE otherwise. */ -SEG_LIB_CODE BOOL IsEqualGUID(REFGUID guid1, REFGUID guid2) +BOOL IsEqualGUID(REFGUID guid1, REFGUID guid2) { return MAKEBOOL(StrCompareMem(guid1, guid2, sizeof(GUID)) == 0); } @@ -83,7 +81,7 @@ SEG_LIB_CODE BOOL IsEqualGUID(REFGUID guid1, REFGUID guid2) */ /* This macro makes a ObjHlpStandardQueryInterface_IXXX function for any interface directly derived from IUnknown */ #define MAKE_BASE_QI(iface) \ -SEG_LIB_CODE HRESULT ObjHlpStandardQueryInterface_ ## iface (IUnknown *pThis, REFIID riid, PPVOID ppvObject) \ +HRESULT ObjHlpStandardQueryInterface_ ## iface (IUnknown *pThis, REFIID riid, PPVOID ppvObject) \ { \ if (!ppvObject) return E_POINTER; \ *ppvObject = NULL; \ @@ -105,7 +103,7 @@ MAKE_BASE_QI(IMalloc) * Returns: * 1. */ -SEG_LIB_CODE UINT32 ObjHlpStaticAddRefRelease(IUnknown *pThis) +UINT32 ObjHlpStaticAddRefRelease(IUnknown *pThis) { return 1; } @@ -119,7 +117,7 @@ SEG_LIB_CODE UINT32 ObjHlpStaticAddRefRelease(IUnknown *pThis) * Returns: * Nothing. */ -SEG_LIB_CODE void ObjHlpDoNothingReturnVoid(IUnknown *pThis) +void ObjHlpDoNothingReturnVoid(IUnknown *pThis) { /* do nothing */ } diff --git a/kernel/qdivrem.c b/kernel/lib/qdivrem.c similarity index 96% rename from kernel/qdivrem.c rename to kernel/lib/qdivrem.c index 30b9744..f00c630 100644 --- a/kernel/qdivrem.c +++ b/kernel/lib/qdivrem.c @@ -31,7 +31,6 @@ * SUCH DAMAGE. */ /* Derived from FreeBSD libkern qdivrem.c, munged by Erbo to COMROGUE standards */ -#define __COMROGUE_KERNEL_LIB__ #include #include #include "quad.h" @@ -54,7 +53,7 @@ typedef UINT16 DIGIT; * `fall out' the left (there never will be any such anyway). * We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS. */ -SEG_LIB_CODE static void __shl(register DIGIT *p, register INT32 len, register INT32 sh) +static void __shl(register DIGIT *p, register INT32 len, register INT32 sh) { register INT32 i; @@ -71,7 +70,7 @@ SEG_LIB_CODE static void __shl(register DIGIT *p, register INT32 len, register I * divisor are 4 `digits' in this base (they are shorter if they have * leading zeros). */ -SEG_LIB_CODE UINT64 __qdivrem(UINT64 uq, UINT64 vq, PUINT64 pRem) +UINT64 __qdivrem(UINT64 uq, UINT64 vq, PUINT64 pRem) { UU tmp; DIGIT *u, *v, *q; @@ -85,7 +84,7 @@ SEG_LIB_CODE UINT64 __qdivrem(UINT64 uq, UINT64 vq, PUINT64 pRem) */ if (vq == 0) { /* divide by zero. */ - SEG_LIB_RODATA static volatile const unsigned int zero = 0; + SEG_RODATA static volatile const unsigned int zero = 0; tmp.ul[H] = tmp.ul[L] = 1 / zero; if (pRem) diff --git a/kernel/quad.h b/kernel/lib/quad.h similarity index 100% rename from kernel/quad.h rename to kernel/lib/quad.h diff --git a/kernel/rbtree.c b/kernel/lib/rbtree.c similarity index 92% rename from kernel/rbtree.c rename to kernel/lib/rbtree.c index f75f601..dfea2db 100644 --- a/kernel/rbtree.c +++ b/kernel/lib/rbtree.c @@ -29,10 +29,8 @@ * * "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. */ -#define __COMROGUE_KERNEL_LIB__ #include #include -#include #include #ifdef THIS_FILE @@ -62,7 +60,7 @@ DECLARE_THIS_FILE * 0 if the keys are equal; an integer less than 0 if k1 is less than k2; an integer greater than 0 if * k1 is greater than k2. */ -SEG_LIB_CODE INT32 RbtStdCompareByValue(TREEKEY k1, TREEKEY k2) +INT32 RbtStdCompareByValue(TREEKEY k1, TREEKEY k2) { if (k1 == k2) return 0; @@ -81,7 +79,7 @@ SEG_LIB_CODE INT32 RbtStdCompareByValue(TREEKEY k1, TREEKEY k2) * Returns: * Pointer to the new root node of the subtree after the rotation. */ -SEG_LIB_CODE static PRBTREENODE rotate_left(PRBTREENODE ptn) +static PRBTREENODE rotate_left(PRBTREENODE ptn) { register PRBTREENODE ptnNewRoot = rbtNodeRight(ptn); ASSERT(ptnNewRoot); @@ -102,7 +100,7 @@ SEG_LIB_CODE static PRBTREENODE rotate_left(PRBTREENODE ptn) * Returns: * Pointer to the new root node of the subtree after the rotation. */ -SEG_LIB_CODE static PRBTREENODE rotate_right(PRBTREENODE ptn) +static PRBTREENODE rotate_right(PRBTREENODE ptn) { register PRBTREENODE ptnNewRoot = ptn->ptnLeft; ASSERT(ptnNewRoot); @@ -122,7 +120,7 @@ SEG_LIB_CODE static PRBTREENODE rotate_right(PRBTREENODE ptn) * Returns: * Nothing. */ -SEG_LIB_CODE static void color_flip(PRBTREENODE ptn) +static void color_flip(PRBTREENODE ptn) { rbtToggleColor(ptn); rbtToggleColor(ptn->ptnLeft); @@ -139,7 +137,7 @@ SEG_LIB_CODE static void color_flip(PRBTREENODE ptn) * Returns: * Pointer to the new root node of the subtree after fixup is performed. */ -SEG_LIB_CODE static PRBTREENODE fix_up(PRBTREENODE ptn) +static PRBTREENODE fix_up(PRBTREENODE ptn) { if (rbtIsRed(rbtNodeRight(ptn)) && !rbtIsRed(ptn->ptnLeft)) ptn = rotate_left(ptn); @@ -167,7 +165,7 @@ SEG_LIB_CODE static PRBTREENODE fix_up(PRBTREENODE ptn) * This function is recursive; however, the nature of the tree guarantees that the stack space consumed * by its stack frames will be O(log n). */ -SEG_LIB_CODE static PRBTREENODE insert_under(PRBTREE ptree, PRBTREENODE ptnCurrent, PRBTREENODE ptnNew) +static PRBTREENODE insert_under(PRBTREE ptree, PRBTREENODE ptnCurrent, PRBTREENODE ptnNew) { register int cmp; /* compare result */ @@ -194,7 +192,7 @@ SEG_LIB_CODE static PRBTREENODE insert_under(PRBTREE ptree, PRBTREENODE ptnCurre * Returns: * Nothing. */ -SEG_LIB_CODE void RbtInsert(PRBTREE ptree, PRBTREENODE ptnNew) +void RbtInsert(PRBTREE ptree, PRBTREENODE ptnNew) { ptree->ptnRoot = insert_under(ptree, ptree->ptnRoot, ptnNew); rbtSetNodeColor(ptree->ptnRoot, BLACK); @@ -210,7 +208,7 @@ SEG_LIB_CODE void RbtInsert(PRBTREE ptree, PRBTREENODE ptnNew) * Returns: * Pointer to the node where the key is found, or NULL if not found. */ -SEG_LIB_CODE PRBTREENODE RbtFind(PRBTREE ptree, TREEKEY key) +PRBTREENODE RbtFind(PRBTREE ptree, TREEKEY key) { register PRBTREENODE ptn = ptree->ptnRoot; /* current node */ register int cmp; /* compare result */ @@ -241,7 +239,7 @@ SEG_LIB_CODE PRBTREENODE RbtFind(PRBTREE ptree, TREEKEY key) * Pointer to the node where the key is found, or pointer to the predecessor node, or NULL if the key * is less than every key in the tree and hence has no predecessor. */ -SEG_LIB_CODE PRBTREENODE RbtFindPredecessor(PRBTREE ptree, TREEKEY key) +PRBTREENODE RbtFindPredecessor(PRBTREE ptree, TREEKEY key) { register PRBTREENODE ptn = ptree->ptnRoot; /* current node */ register int cmp; /* compare result */ @@ -276,7 +274,7 @@ SEG_LIB_CODE PRBTREENODE RbtFindPredecessor(PRBTREE ptree, TREEKEY key) * Pointer to the node where the key is found, or pointer to the successor node, or NULL if the key * is greater than every key in the tree and hence has no successor. */ -SEG_LIB_CODE PRBTREENODE RbtFindSuccessor(PRBTREE ptree, TREEKEY key) +PRBTREENODE RbtFindSuccessor(PRBTREE ptree, TREEKEY key) { register PRBTREENODE ptn = ptree->ptnRoot; /* current node */ register int cmp; /* compare result */ @@ -308,7 +306,7 @@ SEG_LIB_CODE PRBTREENODE RbtFindSuccessor(PRBTREE ptree, TREEKEY key) * Returns: * Pointer to the leftmost node in the subtree. */ -SEG_LIB_CODE static PRBTREENODE find_min(PRBTREENODE ptn) +static PRBTREENODE find_min(PRBTREENODE ptn) { while (ptn->ptnLeft) ptn = ptn->ptnLeft; @@ -324,7 +322,7 @@ SEG_LIB_CODE static PRBTREENODE find_min(PRBTREENODE ptn) * Returns: * Pointer to the leftmost node in the tree. If the tree has no nodes, NULL is returned. */ -SEG_LIB_CODE PRBTREENODE RbtFindMin(PRBTREE ptree) +PRBTREENODE RbtFindMin(PRBTREE ptree) { return ptree->ptnRoot ? find_min(ptree->ptnRoot) : NULL; } @@ -340,7 +338,7 @@ SEG_LIB_CODE PRBTREENODE RbtFindMin(PRBTREE ptree) * Returns: * Pointer to root of subtree after fixup. */ -SEG_LIB_CODE static PRBTREENODE move_red_left(PRBTREENODE ptn) +static PRBTREENODE move_red_left(PRBTREENODE ptn) { color_flip(ptn); if (rbtNodeRight(ptn) && rbtIsRed(rbtNodeRight(ptn)->ptnLeft)) @@ -361,7 +359,7 @@ SEG_LIB_CODE static PRBTREENODE move_red_left(PRBTREENODE ptn) * Returns: * Pointer to root of subtree after fixup. */ -SEG_LIB_CODE static PRBTREENODE move_red_right(PRBTREENODE ptn) +static PRBTREENODE move_red_right(PRBTREENODE ptn) { color_flip(ptn); if (ptn->ptnLeft && rbtIsRed(ptn->ptnLeft->ptnLeft)) @@ -386,7 +384,7 @@ SEG_LIB_CODE static PRBTREENODE move_red_right(PRBTREENODE ptn) * This function is recursive; however, the nature of the tree guarantees that the stack space consumed * by its stack frames will be O(log n). */ -SEG_LIB_CODE static PRBTREENODE delete_min(PRBTREENODE ptn) +static PRBTREENODE delete_min(PRBTREENODE ptn) { if (!(ptn->ptnLeft)) return rbtNodeRight(ptn); @@ -412,7 +410,7 @@ SEG_LIB_CODE static PRBTREENODE delete_min(PRBTREENODE ptn) * This function is recursive; however, the nature of the tree guarantees that the stack space consumed * by its stack frames (and those of delete_min, where we call it) will be O(log n). */ -SEG_LIB_CODE static PRBTREENODE delete_from_under(PRBTREE ptree, PRBTREENODE ptnCurrent, TREEKEY key) +static PRBTREENODE delete_from_under(PRBTREE ptree, PRBTREENODE ptnCurrent, TREEKEY key) { register int cmp = (*(ptree->pfnTreeCompare))(key, ptnCurrent->treekey); if (cmp < 0) @@ -467,7 +465,7 @@ SEG_LIB_CODE static PRBTREENODE delete_from_under(PRBTREE ptree, PRBTREENODE ptn * Returns: * Nothing. */ -SEG_LIB_CODE void RbtDelete(PRBTREE ptree, TREEKEY key) +void RbtDelete(PRBTREE ptree, TREEKEY key) { ptree->ptnRoot = delete_from_under(ptree, ptree->ptnRoot, key); if (ptree->ptnRoot) @@ -491,7 +489,7 @@ SEG_LIB_CODE void RbtDelete(PRBTREE ptree, TREEKEY key) * This function is recursive; however, the nature of the tree guarantees that the stack space consumed * by its stack frames will be O(log n). */ -SEG_LIB_CODE static BOOL do_walk(PRBTREE ptree, PRBTREENODE ptn, PFNRBTWALK pfnWalk, PVOID pData) +static BOOL do_walk(PRBTREE ptree, PRBTREENODE ptn, PFNRBTWALK pfnWalk, PVOID pData) { register BOOL rc = TRUE; if (ptn->ptnLeft) @@ -515,7 +513,7 @@ SEG_LIB_CODE static BOOL do_walk(PRBTREE ptree, PRBTREENODE ptn, PFNRBTWALK pfnW * Returns: * TRUE if the tree was entirely traversed, FALSE if the tree walk was interrupted. */ -SEG_LIB_CODE BOOL RbtWalk(PRBTREE ptree, PFNRBTWALK pfnWalk, PVOID pData) +BOOL RbtWalk(PRBTREE ptree, PFNRBTWALK pfnWalk, PVOID pData) { return (ptree->ptnRoot ? do_walk(ptree, ptree->ptnRoot, pfnWalk, pData) : TRUE); } diff --git a/kernel/str.c b/kernel/lib/str.c similarity index 93% rename from kernel/str.c rename to kernel/lib/str.c index b2c3e32..d39362e 100644 --- a/kernel/str.c +++ b/kernel/lib/str.c @@ -29,7 +29,6 @@ * * "Raspberry Pi" is a trademark of the Raspberry Pi Foundation. */ -#define __COMROGUE_KERNEL_LIB__ #include #include #include @@ -50,7 +49,7 @@ * Returns: * TRUE if the character is a digit, FALSE otherwise. */ -SEG_LIB_CODE BOOL StrIsDigit8(CHAR ch) +BOOL StrIsDigit8(CHAR ch) { /* TODO: replace with something nicer later */ return MAKEBOOL((ch >= '0') && (ch <= '9')); @@ -65,7 +64,7 @@ SEG_LIB_CODE BOOL StrIsDigit8(CHAR ch) * Returns: * The length of the string in characters. */ -SEG_LIB_CODE INT32 StrLength8(PCSTR psz) +INT32 StrLength8(PCSTR psz) { register PCSTR p = psz; while (*p) @@ -83,7 +82,7 @@ SEG_LIB_CODE INT32 StrLength8(PCSTR psz) * Returns: * NULL if character was not found, otherwise pointer to character within string. */ -SEG_LIB_CODE PCHAR StrChar8(PCSTR psz, INT32 ch) +PCHAR StrChar8(PCSTR psz, INT32 ch) { const CHAR mych = ch; for (; *psz; psz++) @@ -113,11 +112,10 @@ SEG_LIB_CODE PCHAR StrChar8(PCSTR psz, INT32 ch) * A pointer to the first digit of the converted value, which will be somewhere in the interval * [pchBuf, pchBuf + nBytes). */ -SEG_LIB_CODE static PCHAR convert_number_engine8(UINT64 value, PCHAR pchBuf, INT32 nBytes, INT32 nBase, - BOOL fUppercase) +static PCHAR convert_number_engine8(UINT64 value, PCHAR pchBuf, INT32 nBytes, INT32 nBase, BOOL fUppercase) { - static DECLARE_LIB_STRING8_CONST(szDigitsUppercase, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - static DECLARE_LIB_STRING8_CONST(szDigitsLowercase, "0123456789abcdefghijklmnopqrstuvwxyz"); + static DECLARE_STRING8_CONST(szDigitsUppercase, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + static DECLARE_STRING8_CONST(szDigitsLowercase, "0123456789abcdefghijklmnopqrstuvwxyz"); PCSTR pszDigits = (fUppercase ? szDigitsUppercase : szDigitsLowercase); /* digit set to use */ PCHAR p = pchBuf + nBytes; /* output pointer */ INT64 accumulator; /* accumulator of quotients */ @@ -154,8 +152,8 @@ SEG_LIB_CODE static PCHAR convert_number_engine8(UINT64 value, PCHAR pchBuf, INT else { errorFlag = SEVERITY_ERROR; goto error; } } } while (0) /* Strings used for padding */ -static DECLARE_LIB_STRING8_CONST(szPadSpace, " "); -static DECLARE_LIB_STRING8_CONST(szPadZero, "0000000000000000000000000000000000000000000000000000000000"); +static DECLARE_STRING8_CONST(szPadSpace, " "); +static DECLARE_STRING8_CONST(szPadZero, "0000000000000000000000000000000000000000000000000000000000"); #define PAD_SIZE (sizeof(szPadSpace) - 1) /* number of characters available in pad string */ @@ -183,12 +181,12 @@ static DECLARE_LIB_STRING8_CONST(szPadZero, "0000000000000000000000000000000000 * Notes: * Floating-point conversion formats are not supported at this time. */ -SEG_LIB_CODE HRESULT StrFormatV8(PFNFORMAT8 pfnFormat, PVOID pArg, PCSTR pszFormat, va_list pargs) +HRESULT StrFormatV8(PFNFORMAT8 pfnFormat, PVOID pArg, PCSTR pszFormat, va_list pargs) { - static DECLARE_LIB_STRING8_CONST(szFlagChars, "0+- #"); /* flag characters and values */ - static const UINT32 SEG_LIB_RODATA auiFlagValues[] = + static DECLARE_STRING8_CONST(szFlagChars, "0+- #"); /* flag characters and values */ + static const UINT32 SEG_RODATA auiFlagValues[] = { FLAG_ZEROPAD, FLAG_LEFTJUST, FLAG_PLUSSIGN, FLAG_SPACESIGN, FLAG_ALTMODE, 0 }; - static DECLARE_LIB_STRING8_CONST(szConversionChars, "hl"); /* conversion characters */ + static DECLARE_STRING8_CONST(szConversionChars, "hl"); /* conversion characters */ PCSTR p; /* pointer used to walk the format string */ PCHAR pFlag; /* pointer to flag character/temp buffer pointer */ PCHAR pchOutput; /* pointer to characters actually output */ diff --git a/kernel/strcomparemem.S b/kernel/lib/strcomparemem.S similarity index 99% rename from kernel/strcomparemem.S rename to kernel/lib/strcomparemem.S index 4a66508..6537879 100644 --- a/kernel/strcomparemem.S +++ b/kernel/lib/strcomparemem.S @@ -60,8 +60,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Taken from FreeBSD memcmp.S, munged by Erbo to COMROGUE standards */ -.section ".lib.text" - /* Func: INT32 StrCompareMem(PCVOID pMem1, PCVOID pMem2, SSIZE_T cb); */ /* * Compares two memory blocks as bytes, returning a value for comparison between the two. diff --git a/kernel/strcopymem.S b/kernel/lib/strcopymem.S similarity index 99% rename from kernel/strcopymem.S rename to kernel/lib/strcopymem.S index 69db1db..7de3b88 100644 --- a/kernel/strcopymem.S +++ b/kernel/lib/strcopymem.S @@ -27,8 +27,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ /* Taken from FreeBSD memcpy_arm.S, munged by Erbo to COMROGUE standards */ -.section ".lib.text" - /* * This is one fun bit of code ... * Some easy listening music is suggested while trying to understand this diff --git a/kernel/strsetmem.S b/kernel/lib/strsetmem.S similarity index 99% rename from kernel/strsetmem.S rename to kernel/lib/strsetmem.S index 5f66a08..df6f80a 100644 --- a/kernel/strsetmem.S +++ b/kernel/lib/strsetmem.S @@ -64,8 +64,6 @@ * SUCH DAMAGE. */ /* Taken from FreeBSD memset.S, munged by Erbo to COMROGUE standards */ -.section ".lib.text" - /* FUNC: PVOID StrSetMem(PVOID pMem, INT32 ch, SSIZE_T cb); */ /* * Fills a block of memory with a constant byte value.