From patrick_steinmueller at web.de Tue Aug 4 13:48:05 2009 From: patrick_steinmueller at web.de (=?iso-8859-15?Q?Patrick_Steinm=FCller?=) Date: Tue, 04 Aug 2009 13:48:05 +0200 Subject: [tyndur-devel] =?iso-8859-15?q?AC97_Treiber_-=3E_verbugt=2C_vllt_?= =?iso-8859-15?q?hat_jemand_lust_sich_das_kurz_anzuschauen_und_mir_vorzuwe?= =?iso-8859-15?q?rfen_was_ich_falsch_mache?= Message-ID: <265788785@web.de> @titel -> sagt schon alles + irc logs das zeug kommt in modules/cdi/ in ein verzeichnis ac97 (aber bitte nicht 2 mal schachteln) mfg ________________________________________________________________ Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/ -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : ac97.tar.gz Dateityp : application/octet-stream Dateigröße : 4609 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Wed Aug 5 00:00:16 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 00:00:16 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Fix fuer mmc_automap_user Message-ID: <1249423216-17083-1-git-send-email-kevin@tyndur.org> ! kernel2: In mmc_automap_user werden die Pages einzeln gemappt, also sollte man nicht in jedem Durchlauf alle Seiten mappen. Signed-off-by: Kevin Wolf --- src/kernel2/src/arch/i386/mm/mm_context.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel2/src/arch/i386/mm/mm_context.c index e220857..722d052 100644 --- a/src/kernel2/src/arch/i386/mm/mm_context.c +++ b/src/kernel2/src/arch/i386/mm/mm_context.c @@ -566,7 +566,7 @@ vaddr_t mmc_automap_user(mmc_context_t* target_ctx, mmc_context_t* source_ctx, for (i = 0; i < count; i++) { paddr = mmc_resolve(source_ctx, start + (i * PAGE_SIZE)); vaddr = free_page + (i * PAGE_SIZE); - if (!mmc_map(target_ctx, vaddr, paddr, flags, count)) { + if (!mmc_map(target_ctx, vaddr, paddr, flags, 1)) { mmc_unmap(target_ctx, free_page, i); return NULL; } -- 1.6.0.2 From kevin at tyndur.org Wed Aug 5 00:20:48 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 00:20:48 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Syscall SYSCALL_PM_ENUMERATE_TASKS Message-ID: <1249424448-17788-1-git-send-email-kevin@tyndur.org> + kernel2: Syscall SYSCALL_PM_ENUMERATE_TASKS (Speicherbedarf und aktuelles eip bleiben momentan leer) Signed-off-by: Kevin Wolf --- src/kernel2/include/syscall.h | 4 ++ src/kernel2/src/syscall.c | 3 ++ src/kernel2/src/syscalls/pm.c | 77 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 0 deletions(-) diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h index 6637ffd..b7ebfc9 100644 --- a/src/kernel2/include/syscall.h +++ b/src/kernel2/include/syscall.h @@ -116,6 +116,10 @@ pid_t syscall_pm_create_process(vaddr_t start, uid_t uid, /// Aktuellen Prozess beenden void syscall_pm_exit_process(void); +/// Alle Prozesse auflisten +void* syscall_pm_enumerate_tasks(void); + + /// Speicher an einen anderen Prozess uebergeben void syscall_init_child_page(pid_t pid, vaddr_t src, vaddr_t dest, size_t size); diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c index 58c82de..fcb9f66 100644 --- a/src/kernel2/src/syscall.c +++ b/src/kernel2/src/syscall.c @@ -71,6 +71,9 @@ void syscall_init() syscall_register(SYSCALL_PM_INIT_PAGE, &syscall_init_child_page, 4); syscall_register(SYSCALL_PM_EXIT_PROCESS, &syscall_pm_exit_process, 0); + syscall_register(SYSCALL_PM_ENUMERATE_TASKS, + &syscall_pm_enumerate_tasks, 0); + syscall_register(SYSCALL_SET_RPC_HANDLER, &syscall_set_rpc_handler, 1); #if CONFIG_ARCH == ARCH_I386 syscall_register(SYSCALL_FASTRPC, &syscall_fastrpc, 5); diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c index b4f5cf7..750d3dc 100644 --- a/src/kernel2/src/syscalls/pm.c +++ b/src/kernel2/src/syscalls/pm.c @@ -38,6 +38,7 @@ #include #include "syscall.h" +#include "syscall_structs.h" #include "tasks.h" #include "cpu.h" @@ -234,3 +235,79 @@ void syscall_pm_wait_for_rpc(void) syscall_pm_sleep(); thread->status = PM_STATUS_WAIT_FOR_RPC; } + +/** + * Alle Prozesse auflisten + * + * @return Gibt einen Pointer auf neu allozierte Seiten zurueck, die + * Informationen ueber alle laufenden Tasks enthalten. Der Pointer zeigt dabei + * auf Daten vom Typ task_info_t. + */ +void* syscall_pm_enumerate_tasks(void) +{ + // Erst werden die Tasks gezaehlt, und die Groesse der + // Informationen mit den Kommandozeilen wird errechnet. + size_t task_count = 0; + size_t result_size = sizeof(task_info_t); + pm_process_t* task; + unsigned int i; + + for (i = 0; (task = list_get_element_at(process_list, i)); i++) { + task_count++; + result_size += sizeof(task_info_task_t) + strlen(task->cmdline) + 1; + } + + // Anzahl der Seiten berechnen, die die Informationen benoetigen. + size_t result_page_count = PAGE_ALIGN_ROUND_UP(result_size) / PAGE_SIZE; + + // Jetzt wird eine freie Stelle im Adressraum des Prozesses + // gesucht, wo die Task-Infos hingemappt werden koennen + // FIXME Die Seiten muessen nicht physisch zusammenhaengend sein + task_info_t* task_info = mmc_automap(&mmc_current_context(), + pmm_alloc(result_page_count), result_page_count, MM_USER_START, + MM_USER_END, PTE_P | PTE_W | PTE_U); + + // Der Groessen-Eintrag ist nur da, damit der Task die Pages + // freigeben koennte. + task_info->info_size = result_size; + task_info->task_count = task_count; + + // Dieser Pointer zeigt direkt hinter das Array mit den + // Task-Informationen. Dort werden die Kommandozeilen + // hintereinander gespeichert, und aus den Task-Strukturen wird auf + // sie verwiesen. + char* cmdlines = (char*) task_info->tasks; + cmdlines += task_count * sizeof(task_info_task_t); + + // Jetzt werden die Infos eingefuellt. + for (i = 0; (task = list_get_element_at(process_list, i)); i++) { + task_info->tasks[i].pid = task->pid; + task_info->tasks[i].status = task->status; + + // TODO Ergibt strenggenommen keinen Sinn, evtl. ersten Thread? + task_info->tasks[i].eip = 0; + + // Wenn der Task keinen Eltern-Task hat muessen wir aufpassen, + // damit wir keinen Pagefault produzieren. + if (task->parent == NULL) { + task_info->tasks[i].parent_pid = 0; + } else { + task_info->tasks[i].parent_pid = task->parent->pid; + } + + // Die Kommandozeile inklusive Nullbyte kopieren + size_t cmdline_size = strlen(task->cmdline) + 1; + memcpy(cmdlines, task->cmdline, cmdline_size); + + // Den Pointer fuer die Kommandozeile setzen + task_info->tasks[i].cmdline = cmdlines; + + // Den Zielpointer fuer die naechste Kommandozeile direkt + // hinter die aktuelle setzen. + cmdlines += cmdline_size; + + task_info->tasks[i].memory_used = 0; // TODO + } + + return task_info; +} -- 1.6.0.2 From kevin at tyndur.org Wed Aug 5 11:51:14 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 11:51:14 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Virtuell, aber nicht physisch zusammenhaengender Speicher Message-ID: <1249465874-9112-1-git-send-email-kevin@tyndur.org> + kernel2: mmc_valloc() alloziert virtuell zusammenhaengenden Speicher, der aber physisch nicht zusammenhaengend sein muss ! kernel2: Entsprechende FIXMEs geloest, wo bisher unnoetigerweise physisch zusammenhaengender Speicher reserviert wurde Signed-off-by: Kevin Wolf --- src/kernel2/include/mm.h | 32 ++++++++++++++ src/kernel2/src/arch/i386/mm/mm_context.c | 64 +++++++++++++++++++++++++++++ src/kernel2/src/mm/shm.c | 34 +++++++++++---- src/kernel2/src/syscalls/mem.c | 17 ++++---- src/kernel2/src/syscalls/pm.c | 6 +-- 5 files changed, 131 insertions(+), 22 deletions(-) diff --git a/src/kernel2/include/mm.h b/src/kernel2/include/mm.h index e143fb7..0144aca 100644 --- a/src/kernel2/include/mm.h +++ b/src/kernel2/include/mm.h @@ -74,6 +74,9 @@ void vmm_kernel_unmap(vaddr_t start, size_t size); /* * MM-Kontext + * + * FIXME Den ganzen generischen Funktionen i386-spezifische Flags zu geben, ist + * moeglicherweise keine gute Idee... */ mmc_context_t mmc_create(void); @@ -93,6 +96,35 @@ vaddr_t mmc_automap_user(mmc_context_t* target_ctx, mmc_context_t* source_ctx, vaddr_t start, size_t count, uintptr_t lower_limit, uintptr_t upper_limit, int flags); +/** + * Alloziert einen virtuell (aber nicht zwingend physisch) zusammenhaengenden + * Speicherbereich + * + * @param context Speicherkontext, in den die Seiten gemappt werden sollen + * @param num_pages Anzahl der zu mappenden Seiten + * @param phys_lower_limit Niedrigste zulaessige physische Adresse + * @param phys_upper_limit Hoechste zulaessige physische Adresse. Wenn der Wert + * NULL ist, werden die zulaessigen physischen Adressen nicht eingeschraenkt. + * @param virt_lower_limit Niedrigste zulaessige virtuelle Adresse + * @param virt_upper_limit Hoechste zulaessige virtuelle Adresse + * @param flags Flags fuer die Pagetable + */ +vaddr_t mmc_valloc_limits(mmc_context_t* context, size_t num_pages, + paddr_t phys_lower_limit, paddr_t phys_upper_limit, + uintptr_t virt_lower_limit, uintptr_t virt_upper_limit, int flags); + +/** + * Alloziert einen virtuell (aber nicht zwingend physisch) zusammenhaengenden + * Speicherbereich. Dies ist eine abkuerzende Variante von mmc_valloc_limits, + * die die Standardlimits fuer User- bzw. Kernelspace benutzt, je nachdem ob + * PTE_U in den Flags gesetzt ist oder nicht. + * + * @param context Speicherkontext, in den die Seiten gemappt werden sollen + * @param num_pages Anzahl der zu mappenden Seiten + * @param flags Flags fuer die Pagetable + */ +vaddr_t mmc_valloc(mmc_context_t* context, size_t num_pages, int flags); + void mmc_activate(mmc_context_t* context); #define mmc_current_context() (*cpu_get_current()->mm_context) diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel2/src/arch/i386/mm/mm_context.c index 722d052..34ac946 100644 --- a/src/kernel2/src/arch/i386/mm/mm_context.c +++ b/src/kernel2/src/arch/i386/mm/mm_context.c @@ -574,3 +574,67 @@ vaddr_t mmc_automap_user(mmc_context_t* target_ctx, mmc_context_t* source_ctx, return free_page; } + +/** + * Alloziert einen virtuell (aber nicht zwingend physisch) zusammenhaengenden + * Speicherbereich + * + * @param context Speicherkontext, in den die Seiten gemappt werden sollen + * @param num_pages Anzahl der zu mappenden Seiten + * @param phys_lower_limit Niedrigste zulaessige physische Adresse + * @param phys_upper_limit Hoechste zulaessige physische Adresse. Wenn der Wert + * NULL ist, werden die zulaessigen physischen Adressen nicht eingeschraenkt. + * @param virt_lower_limit Niedrigste zulaessige virtuelle Adresse + * @param virt_upper_limit Hoechste zulaessige virtuelle Adresse + * @param flags Flags fuer die Pagetable + */ +inline vaddr_t mmc_valloc_limits(mmc_context_t* context, size_t num_pages, + paddr_t phys_lower_limit, paddr_t phys_upper_limit, + uintptr_t virt_lower_limit, uintptr_t virt_upper_limit, int flags) +{ + size_t i; + paddr_t paddr; + vaddr_t vaddr; + vaddr_t free_page = find_contiguous_pages(context, num_pages, + virt_lower_limit, virt_upper_limit); + + if (free_page == NULL) { + return NULL; + } + + for (i = 0; i < num_pages; i++) { + if (!phys_upper_limit) { + paddr = pmm_alloc(1); + } else { + paddr = pmm_alloc_limits(phys_lower_limit, phys_upper_limit, 1); + } + vaddr = free_page + (i * PAGE_SIZE); + if (!mmc_map(context, vaddr, paddr, flags, 1)) { + mmc_unmap(context, free_page, i); + return NULL; + } + } + + return free_page; +} + +/** + * Alloziert einen virtuell (aber nicht zwingend physisch) zusammenhaengenden + * Speicherbereich. Dies ist eine abkuerzende Variante von mmc_valloc_limits, + * die die Standardlimits fuer User- bzw. Kernelspace benutzt, je nachdem ob + * PTE_U in den Flags gesetzt ist oder nicht. + * + * @param context Speicherkontext, in den die Seiten gemappt werden sollen + * @param num_pages Anzahl der zu mappenden Seiten + * @param flags Flags fuer die Pagetable + */ +vaddr_t mmc_valloc(mmc_context_t* context, size_t num_pages, int flags) +{ + if (flags & PTE_U) { + return mmc_valloc_limits(context, num_pages, NULL, NULL, + MM_USER_START, MM_USER_END, flags); + } else { + return mmc_valloc_limits(context, num_pages, NULL, NULL, + KERNEL_MEM_START, KERNEL_MEM_END, flags); + } +} diff --git a/src/kernel2/src/mm/shm.c b/src/kernel2/src/mm/shm.c index 72c5eac..67b4831 100644 --- a/src/kernel2/src/mm/shm.c +++ b/src/kernel2/src/mm/shm.c @@ -46,7 +46,6 @@ struct shm_desc { uint64_t id; struct tree_item tree_item; - paddr_t paddr; size_t num_pages; list_t* processes; }; @@ -75,8 +74,6 @@ void shm_init(void) */ uint32_t shm_create(size_t size) { - // FIXME Die Pages muessen nicht physisch zusammenhaengend sein - paddr_t shm_phys = pmm_alloc(NUM_PAGES(size)); uint32_t id = ++shm_last_id; struct shm_desc* shm; @@ -87,7 +84,6 @@ uint32_t shm_create(size_t size) shm = calloc(1, sizeof(*shm)); shm->id = id; shm->num_pages = NUM_PAGES(size); - shm->paddr = shm_phys; shm->processes = list_create(); tree_insert(shms, shm); @@ -112,8 +108,17 @@ void* shm_attach(uint32_t id) return NULL; } - ret = mmc_automap(&mmc_current_context(), shm->paddr, shm->num_pages, - MM_USER_START, MM_USER_END, MM_FLAGS_USER_DATA); + if (list_is_empty(shm->processes)) { + // Erster Prozess, der den SHM oeffnet: Speicher allozieren + ret = mmc_valloc(&mmc_current_context(), shm->num_pages, + MM_FLAGS_USER_DATA); + } else { + // Ansonsten Mapping von einem anderen Prozess uebernehmen + struct shm_process* first = list_get_element_at(shm->processes, 0); + ret = mmc_automap_user(&mmc_current_context(), + &first->process->context, first->vaddr, shm->num_pages, + MM_USER_START, MM_USER_END, MM_FLAGS_USER_DATA); + } if (ret == NULL) { return NULL; @@ -155,13 +160,24 @@ void shm_detach(uint32_t id) found: - mmc_unmap(&mmc_current_context(), shm_proc->vaddr, shm->num_pages); - // Wenn es der letzte Benutzer war, SHM loeschen if (list_is_empty(shm->processes)) { + for (i = 0; i < shm->num_pages; i++) { + pmm_free(mmc_resolve(&mmc_current_context(), + shm_proc->vaddr + (i * PAGE_SIZE)), 1); + } + list_destroy(shm->processes); - pmm_free(shm->paddr, shm->num_pages); + shm->processes = NULL; tree_remove(shms, shm); + } + + // Virtuellen Speicher freigeben + mmc_unmap(&mmc_current_context(), shm_proc->vaddr, shm->num_pages); + + + free(shm_proc); + if (shm->processes == NULL) { free(shm); } diff --git a/src/kernel2/src/syscalls/mem.c b/src/kernel2/src/syscalls/mem.c index 91457da..ff66fa0 100644 --- a/src/kernel2/src/syscalls/mem.c +++ b/src/kernel2/src/syscalls/mem.c @@ -54,20 +54,19 @@ vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* phys) vaddr_t address = NULL; size_t page_count = NUM_PAGES(PAGE_ALIGN_ROUND_UP(bytes)); - // Der Speicher muss nicht physisch zusamenhaengend sein. if (flags & 0x80) { + // ISA-DMA-Speicher + // Physisch zusammenhaengend und nur in den ersten 16 MB + // FIXME Eigentlich muesste man hier auf 64k-Grenzen aufpassen *phys = pmm_alloc_limits((paddr_t) 0, (paddr_t) (16 * 1024 * 1024), page_count); + address = mmc_automap(&mmc_current_context(), *phys, page_count, + USER_MEM_START, USER_MEM_END, MM_FLAGS_USER_DATA); } else { - *phys = pmm_alloc(page_count); - } - - address = mmc_automap(&mmc_current_context(), *phys, page_count, - USER_MEM_START, USER_MEM_END, MM_FLAGS_USER_DATA); - - // Die physische Adresse gibt es nur fuer DMA - if ((flags & 0x80) == 0) { + // Normaler Speicher, muss nicht zusammenhaengend sein *phys = 0; + address = mmc_valloc(&mmc_current_context(), page_count, + MM_FLAGS_USER_DATA); } return address; diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c index 750d3dc..df99961 100644 --- a/src/kernel2/src/syscalls/pm.c +++ b/src/kernel2/src/syscalls/pm.c @@ -262,10 +262,8 @@ void* syscall_pm_enumerate_tasks(void) // Jetzt wird eine freie Stelle im Adressraum des Prozesses // gesucht, wo die Task-Infos hingemappt werden koennen - // FIXME Die Seiten muessen nicht physisch zusammenhaengend sein - task_info_t* task_info = mmc_automap(&mmc_current_context(), - pmm_alloc(result_page_count), result_page_count, MM_USER_START, - MM_USER_END, PTE_P | PTE_W | PTE_U); + task_info_t* task_info = mmc_valloc(&mmc_current_context(), + result_page_count, MM_FLAGS_USER_DATA); // Der Groessen-Eintrag ist nur da, damit der Task die Pages // freigeben koennte. -- 1.6.0.2 From alexanderkluth at gmx.de Wed Aug 5 13:23:52 2009 From: alexanderkluth at gmx.de (alexanderkluth at gmx.de) Date: Wed, 5 Aug 2009 13:23:52 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_Endlich_ist_es_soweit=3A_tyn?= =?utf-8?q?dur_kann_nun_einer_der_wichtigsten_modernen_Sprachen_int?= =?utf-8?q?erpretieren=3A_Malbolge!_Ich_hoffe=2C_somit_k=C3=B6nnen_?= =?utf-8?q?wir_den_Gro=C3=9Fteil_der_weiteren_Treiber_und_Module_un?= =?utf-8?q?d_Anwendungen_in_Malbolge_entwickeln=2E_Somit_entf=C3=A4?= =?utf-8?q?llt_das_Compillieren=2C_denn_wir_interpretieren_von_heut?= =?utf-8?q?e_an_mit_diesem_ultra-performanten_Interpreter=2E?= In-Reply-To: <1> References: <1> Message-ID: <1249471432-8362-1-git-send-email-alexanderkluth@gmx.de> From: Alexander Hartmut Kluth --- src/modules/c/malbolge/Makefile.all | 7 + src/modules/c/malbolge/malbolge.c | 211 +++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/malbolge/Makefile.all create mode 100644 src/modules/c/malbolge/malbolge.c diff --git a/src/modules/c/malbolge/Makefile.all b/src/modules/c/malbolge/Makefile.all new file mode 100644 index 0000000..0ab349e --- /dev/null +++ b/src/modules/c/malbolge/Makefile.all @@ -0,0 +1,7 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/malbolge" +$LOST_TOOLS_LD -omalbolge -Ttext=0x40000000 *.o --start-group $2 --end-group + +mv malbolge $1/apps/ diff --git a/src/modules/c/malbolge/malbolge.c b/src/modules/c/malbolge/malbolge.c new file mode 100644 index 0000000..0e5c4c2 --- /dev/null +++ b/src/modules/c/malbolge/malbolge.c @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander H. Kluth. + * + * 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. + * + * 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. + */ +#include +#include +#include +#include + + +void exec(unsigned short *mem); +unsigned short op(unsigned short x, unsigned short y); + +const char xlat1[] = + "+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA\"lI" + ".v%{gJh4G\\-=O at 5`_3iU!pJS72FhOA1C" + "B6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@"; + +int main(int argc, char **argv) +{ + FILE *f; + unsigned short i = 0; + int x; + unsigned short *mem; + int lines = 1; + + if (argc != 2) { + fprintf(stderr, "Benutzung: malbolge [DATEI]\n"); + return 1; + } + + if ((f = fopen(argv[1], "r")) == NULL) { + fprintf(stderr, "Fehler beim Öffnen von %s", argv[1]); + return 1; + } + + mem = (unsigned short *)malloc(sizeof(unsigned short)*65535); + + if (mem == NULL) { + fclose(f); + fprintf(stderr, "Nicht genug Speicher!\n"); + return 1; + } + + while ((x = getc(f)) != EOF) { + if (isspace(x)) { + continue; + } + + if (x == '\n') { + lines++; + } + + if (x < 127 && x > 32) { + if (strchr( "ji*p 126) { + continue; + } + + switch (xlat1[(mem[c] - 33 + c ) % 94]) { + case 'j': + d = mem[d]; + break; + + case 'i': + c = mem[d]; + break; + + case '*': + a = mem[d] = mem[d] / 3 + mem[d] % 3 * 19683; + break; + + case 'p': + a = mem[d] = op(a, mem[d]); + break; + + case '<': + if (x == '\n') { + printf("\n"); + } + + break; + case '/': + x = getc(stdin); + if (x == '\n') { + a = 10; + } + + if (x == EOF) { + a = 65535; + } else { + a = x; + } + break; + case 'v': + return; + } + + mem[c] = xlat2[mem[c] - 33]; + + if (c == 65535) { + c = 0; + } else { + c++; + } + + if (d == 65535) { + d = 0; + } else { + d++; + } + } +} + + +unsigned short op(unsigned short x, unsigned short y) +{ + unsigned short i = 0, j; + static const unsigned short p9[5] = { + 1, + 9, + 81, + 729, + 6561 + }; + + static const unsigned short o[9][9] = { + { 4, 3, 3, 1, 0, 0, 1, 0, 0 }, + { 4, 3, 5, 1, 0, 2, 1, 0, 2 }, + { 5, 5, 4, 2, 2, 1, 2, 2, 1 }, + { 4, 3, 3, 1, 0, 0, 7, 6, 6 }, + { 4, 3, 5, 1, 0, 2, 7, 6, 8 }, + { 5, 5, 4, 2, 2, 1, 8, 8, 7 }, + { 7, 6, 6, 7, 6, 6, 4, 3, 3 }, + { 7, 6, 8, 7, 6, 8, 4, 3, 5 }, + { 8, 8, 7, 8, 8, 7, 5, 5, 4 }, + }; + + for (j = 0; j < 5; j++) { + i += o[y / p9[j] % 9][x / p9[j] % 9] * p9[j]; + } + + return i; +} + -- 1.6.0.4 From kevin at tyndur.org Wed Aug 5 18:13:20 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 18:13:20 +0200 Subject: [tyndur-devel] [PATCH 0/5] CDI-Portabilitaetspatches: Netzwerk Message-ID: <1249488805-21506-1-git-send-email-kevin@tyndur.org> Diese Patchserie macht die CDI-Netzwerktreiber angenehmer fuer andere Systeme, die die Treiber benutzen wollen. Bisher kommen ohne Vorwarnung tyndur-spezifische Funktionsaufrufe mitten im Code vor. Die folgenden Patches setzen wenigstens ein #ifdef um die Stellen. Manche so notduerftig geflickten Stellen sollten aber irgendwann noch richtig angegangen werden. Kevin Wolf (5): cdi: TYNDUR in cdi.h definieren sis900: tyndur-spezifische Sachen in #ifdef pcnet: tyndur-spezifischer Code e1000: tyndur-spezifischer Code entfernt rtl8139: tyndur-spezifische Sachen src/modules/cdi/e1000/main.c | 3 --- src/modules/cdi/include/cdi.h | 1 + src/modules/cdi/pcnet/main.c | 6 ++++++ src/modules/cdi/pcnet/pcnet.c | 10 ---------- src/modules/cdi/rtl8139/main.c | 8 +++++++- src/modules/cdi/rtl8139/rtl8139.c | 1 - src/modules/cdi/sis900/device.c | 10 +++++++++- src/modules/cdi/sis900/main.c | 14 +++++++++++--- 8 files changed, 34 insertions(+), 19 deletions(-) From kevin at tyndur.org Wed Aug 5 18:13:21 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 18:13:21 +0200 Subject: [tyndur-devel] [PATCH 1/5] cdi: TYNDUR in cdi.h definieren In-Reply-To: <1249488805-21506-1-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> Message-ID: <1249488805-21506-2-git-send-email-kevin@tyndur.org> + cdi: In cdi.h wird TYNDUR definiert, damit Treiber etwas haben, womit sie ihre #ifdefs machen koennen Signed-off-by: Kevin Wolf --- src/modules/cdi/include/cdi.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index c6215a6..8d7c2e8 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -19,6 +19,7 @@ #include "cdi/lists.h" #define CDI_STANDALONE +#define TYNDUR typedef enum { CDI_UNKNOWN = 0, -- 1.6.0.2 From kevin at tyndur.org Wed Aug 5 18:13:22 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 18:13:22 +0200 Subject: [tyndur-devel] [PATCH 2/5] sis900: tyndur-spezifische Sachen in #ifdef In-Reply-To: <1249488805-21506-1-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> Message-ID: <1249488805-21506-3-git-send-email-kevin@tyndur.org> ! sis900: tyndur-spezifische Sachen muessen in #ifdef stehen, damit andere Systeme den Treiber 1:1 benutzern koennen. Signed-off-by: Kevin Wolf --- src/modules/cdi/sis900/device.c | 10 +++++++++- src/modules/cdi/sis900/main.c | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/cdi/sis900/device.c b/src/modules/cdi/sis900/device.c index 40b32fa..fd433f1 100644 --- a/src/modules/cdi/sis900/device.c +++ b/src/modules/cdi/sis900/device.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "cdi.h" #include "cdi/misc.h" @@ -37,6 +36,11 @@ #include "device.h" #include "sis900_io.h" +#ifdef TYNDUR +#include +#endif + + #undef DEBUG #define PHYS(netcard, field) \ @@ -272,9 +276,13 @@ void sis900_send_packet(struct cdi_net_device* device, void* data, size_t size) // Warten, bis das Paket gesendet ist // FIXME: Nicht portabel +#ifdef TYNDUR qword timeout = get_tick_count() + 500000; while ((netcard->tx_desc[cur].status & DESC_STATUS_OWN) && (get_tick_count() < timeout)); +#else + while (netcard->tx_desc[cur].status & DESC_STATUS_OWN); +#endif #ifdef DEBUG if (netcard->tx_desc[cur].status & DESC_STATUS_OWN) { diff --git a/src/modules/cdi/sis900/main.c b/src/modules/cdi/sis900/main.c index 5ebcf04..88bc2f0 100644 --- a/src/modules/cdi/sis900/main.c +++ b/src/modules/cdi/sis900/main.c @@ -41,8 +41,10 @@ struct module_options { uint32_t ip; }; -// FIXME: LOST-spezifisch +#ifdef TYNDUR uint32_t string_to_ip(char* ip); +#endif + static void process_parameter(struct module_options* options, char* param); struct sis900_driver { @@ -68,7 +70,7 @@ int init_sis900(int argc, char* argv[]) #ifdef CDI_STANDALONE cdi_run_drivers(); -#endif +#endif return 0; } @@ -94,12 +96,14 @@ static void sis900_driver_init(int argc, char* argv[]) driver.net.drv.destroy = sis900_driver_destroy; driver.net.drv.init_device = sis900_init_device; driver.net.drv.remove_device = sis900_remove_device; - + // Parameter verarbeiten int i; +#ifdef TYNDUR for (i = 1; i < argc; i++) { process_parameter(&options, argv[i]); } +#endif // Passende PCI-Geraete suchen cdi_list_t pci_devices = cdi_list_create(); @@ -117,7 +121,9 @@ static void sis900_driver_init(int argc, char* argv[]) device->phys = phys_device; device->pci = dev; +#ifdef TYNDUR device->net.ip = options.ip; +#endif cdi_list_push(driver.net.drv.devices, device); } else { cdi_pci_device_destroy(dev); @@ -130,6 +136,7 @@ static void sis900_driver_init(int argc, char* argv[]) cdi_list_destroy(pci_devices); } +#ifdef TYNDUR static void process_parameter(struct module_options* options, char* param) { printf("sis900-Parameter: %s\n", param); @@ -142,6 +149,7 @@ static void process_parameter(struct module_options* options, char* param) printf("Unbekannter Parameter %s\n", param); } } +#endif /** * Deinitialisiert die Datenstrukturen fuer den sis900-Treiber -- 1.6.0.2 From kevin at tyndur.org Wed Aug 5 18:13:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 18:13:23 +0200 Subject: [tyndur-devel] [PATCH 3/5] pcnet: tyndur-spezifischer Code In-Reply-To: <1249488805-21506-1-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> Message-ID: <1249488805-21506-4-git-send-email-kevin@tyndur.org> ! pcnet: tyndur-spezifischen Code in #ifdef ! pcnet: Unnoetiger tyndur-spezifischer Code entfernt Signed-off-by: Kevin Wolf --- src/modules/cdi/pcnet/main.c | 6 ++++++ src/modules/cdi/pcnet/pcnet.c | 10 ---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/modules/cdi/pcnet/main.c b/src/modules/cdi/pcnet/main.c index c3b75a8..d8a77f6 100644 --- a/src/modules/cdi/pcnet/main.c +++ b/src/modules/cdi/pcnet/main.c @@ -52,8 +52,10 @@ static struct { static const char* driver_name = "pcnet"; +#ifdef TYNDUR // FIXME: LOST-spezifisch uint32_t string_to_ip(char* ip); +#endif static void process_parameter(struct module_options* options, char* param); static int pcnet_driver_init(int argc, char* argv[]); @@ -118,7 +120,9 @@ static int pcnet_driver_init(int argc, char* argv[]) memset(device, 0, sizeof(struct pcnet_device)); device->pci = dev; +#ifdef TYNDUR device->net.ip = options.ip; +#endif cdi_list_push(driver.net.drv.devices, device); } else { cdi_pci_device_destroy(dev); @@ -133,6 +137,7 @@ static int pcnet_driver_init(int argc, char* argv[]) static void process_parameter(struct module_options* options, char* param) { +#ifdef TYNDUR printf("pcnet-Parameter: %s\n", param); if (strncmp(param, "ip=", 3) == 0) { @@ -142,6 +147,7 @@ static void process_parameter(struct module_options* options, char* param) } else { printf("Unbekannter Parameter %s\n", param); } +#endif } /** diff --git a/src/modules/cdi/pcnet/pcnet.c b/src/modules/cdi/pcnet/pcnet.c index 6e0ce51..8bccbf4 100644 --- a/src/modules/cdi/pcnet/pcnet.c +++ b/src/modules/cdi/pcnet/pcnet.c @@ -37,7 +37,6 @@ #include "cdi/io.h" #include -#include static void pcnet_handle_interrupt(struct cdi_device* device); static void pcnet_reset(struct pcnet_device *netcard); @@ -118,8 +117,6 @@ void pcnet_remove_device(struct cdi_device* device) void pcnet_send_packet (struct cdi_net_device* device, void* data, size_t size) { -// p(); - struct pcnet_device *netcard = (struct pcnet_device*) device; if (netcard->last_transmit_descriptor > 7)netcard->last_transmit_descriptor = 0; @@ -140,14 +137,10 @@ void pcnet_send_packet ++netcard->last_transmit_descriptor; if (netcard->last_transmit_descriptor == 8)netcard->last_transmit_descriptor = 0; - -// v(); } static void pcnet_handle_interrupt(struct cdi_device* device) { -// p(); - struct pcnet_device* netcard = (struct pcnet_device*) device; if (netcard->init_wait_for_irq == 1) @@ -156,7 +149,6 @@ static void pcnet_handle_interrupt(struct cdi_device* device) pcnet_write_csr(netcard, CSR_STATUS, csr0); DEBUG_MSG("Interrupt (wait for irq)"); netcard->init_wait_for_irq = 0; -// v(); return; } @@ -216,8 +208,6 @@ static void pcnet_handle_interrupt(struct cdi_device* device) // Clear the interrupt request pcnet_write_csr(netcard, CSR_STATUS, STATUS_INTERRUPT_ENABLE | STATUS_RECEIVE_INTERRUPT); } - -// v(); } static void pcnet_reset(struct pcnet_device *netcard) -- 1.6.0.2 From kevin at tyndur.org Wed Aug 5 18:13:24 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 18:13:24 +0200 Subject: [tyndur-devel] [PATCH 4/5] e1000: tyndur-spezifischer Code entfernt In-Reply-To: <1249488805-21506-1-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> Message-ID: <1249488805-21506-5-git-send-email-kevin@tyndur.org> ! e1000: Es gibt keinen Grund mehr, Ausgaben auf VT2 zu machen, und portabel ist es sowieso nicht Signed-off-by: Kevin Wolf --- src/modules/cdi/e1000/main.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/src/modules/cdi/e1000/main.c b/src/modules/cdi/e1000/main.c index f043548..584d610 100644 --- a/src/modules/cdi/e1000/main.c +++ b/src/modules/cdi/e1000/main.c @@ -69,9 +69,6 @@ int init_e1000(void) */ static void e1000_driver_init() { - // Debugausgaben auf VT2 - stdout = fopen("vterm:/vterm1/out", "w"); - // Konstruktor der Vaterklasse cdi_net_driver_init((struct cdi_net_driver*) &driver); -- 1.6.0.2 From kevin at tyndur.org Wed Aug 5 18:13:25 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 5 Aug 2009 18:13:25 +0200 Subject: [tyndur-devel] [PATCH 5/5] rtl8139: tyndur-spezifische Sachen In-Reply-To: <1249488805-21506-1-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> Message-ID: <1249488805-21506-6-git-send-email-kevin@tyndur.org> ! rtl8139: tyndur-spezifisches in #ifdef * rtl8139: Unbenoetigtes #include entfernt Signed-off-by: Kevin Wolf --- src/modules/cdi/rtl8139/main.c | 8 +++++++- src/modules/cdi/rtl8139/rtl8139.c | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/cdi/rtl8139/main.c b/src/modules/cdi/rtl8139/main.c index 8e340c8..4411a1f 100644 --- a/src/modules/cdi/rtl8139/main.c +++ b/src/modules/cdi/rtl8139/main.c @@ -44,8 +44,10 @@ static struct { static const char* driver_name = "rtl8139"; -// FIXME: LOST-spezifisch +#ifdef TYNDUR +// FIXME: tyndur-spezifisch uint32_t string_to_ip(char* ip); +#endif static void process_parameter(struct module_options* options, char* param); static int rtl8139_driver_init(int argc, char* argv[]); @@ -113,7 +115,9 @@ static int rtl8139_driver_init(int argc, char* argv[]) device->phys = phys_device; device->pci = dev; +#ifdef TYNDUR device->net.ip = options.ip; +#endif cdi_list_push(driver.net.drv.devices, device); } else { cdi_pci_device_destroy(dev); @@ -128,6 +132,7 @@ static int rtl8139_driver_init(int argc, char* argv[]) static void process_parameter(struct module_options* options, char* param) { +#ifdef TYNDUR printf("rtl8139-Parameter: %s\n", param); if (strncmp(param, "ip=", 3) == 0) { @@ -137,6 +142,7 @@ static void process_parameter(struct module_options* options, char* param) } else { printf("Unbekannter Parameter %s\n", param); } +#endif } /** diff --git a/src/modules/cdi/rtl8139/rtl8139.c b/src/modules/cdi/rtl8139/rtl8139.c index 7b43154..ab38d93 100644 --- a/src/modules/cdi/rtl8139/rtl8139.c +++ b/src/modules/cdi/rtl8139/rtl8139.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "cdi/net.h" #include "cdi/pci.h" -- 1.6.0.2 From toni at tyndur.org Wed Aug 5 19:38:13 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Wed, 5 Aug 2009 19:38:13 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Fix fuer mmc_automap_user In-Reply-To: <1249423216-17083-1-git-send-email-kevin@tyndur.org> References: <1249423216-17083-1-git-send-email-kevin@tyndur.org> Message-ID: <20090805173813.GA17444@einstein.kaufmann.lan> On Wed, Aug 05 00:00, Kevin Wolf wrote: > ! kernel2: In mmc_automap_user werden die Pages einzeln gemappt, also > sollte man nicht in jedem Durchlauf alle Seiten mappen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From janosch.graef at gmx.net Wed Aug 5 20:25:52 2009 From: janosch.graef at gmx.net (=?ISO-8859-1?Q?Janosch_Gr=E4f?=) Date: Wed, 05 Aug 2009 20:25:52 +0200 Subject: [tyndur-devel] [PATCH 1/5] cdi: TYNDUR in cdi.h definieren In-Reply-To: <1249488805-21506-2-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> <1249488805-21506-2-git-send-email-kevin@tyndur.org> Message-ID: <4A79CEB0.7070502@gmx.net> Kevin Wolf schrieb: > + cdi: In cdi.h wird TYNDUR definiert, damit Treiber etwas haben, womit > sie ihre #ifdefs machen koennen > > Signed-off-by: Kevin Wolf > --- > src/modules/cdi/include/cdi.h | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h > index c6215a6..8d7c2e8 100644 > --- a/src/modules/cdi/include/cdi.h > +++ b/src/modules/cdi/include/cdi.h > @@ -19,6 +19,7 @@ > #include "cdi/lists.h" > > #define CDI_STANDALONE > +#define TYNDUR > > typedef enum { > CDI_UNKNOWN = 0, > Ich finde, dass das gar keine gute Idee ist. Wenn jetzt jedes OS sein #define da reinhaut fördert das nicht gerade die OS-Unabhängigkeit der Treiber. Mfg, Janosch Gräf From toni at tyndur.org Thu Aug 6 15:35:48 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 15:35:48 +0200 Subject: [tyndur-devel] [PATCH 1/5] cdi: TYNDUR in cdi.h definieren In-Reply-To: <1249488805-21506-2-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> <1249488805-21506-2-git-send-email-kevin@tyndur.org> Message-ID: <20090806133548.GA6738@einstein.kaufmann.lan> On Wed, Aug 05 18:13, Kevin Wolf wrote: > + cdi: In cdi.h wird TYNDUR definiert, damit Treiber etwas haben, womit > sie ihre #ifdefs machen koennen > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Aug 6 15:41:29 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 15:41:29 +0200 Subject: [tyndur-devel] [PATCH 3/5] pcnet: tyndur-spezifischer Code In-Reply-To: <1249488805-21506-4-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> <1249488805-21506-4-git-send-email-kevin@tyndur.org> Message-ID: <20090806134128.GB6738@einstein.kaufmann.lan> On Wed, Aug 05 18:13, Kevin Wolf wrote: > ! pcnet: tyndur-spezifischen Code in #ifdef > ! pcnet: Unnoetiger tyndur-spezifischer Code entfernt > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Aug 6 15:41:46 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 15:41:46 +0200 Subject: [tyndur-devel] [PATCH 2/5] sis900: tyndur-spezifische Sachen in #ifdef In-Reply-To: <1249488805-21506-3-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> <1249488805-21506-3-git-send-email-kevin@tyndur.org> Message-ID: <20090806134146.GC6738@einstein.kaufmann.lan> On Wed, Aug 05 18:13, Kevin Wolf wrote: > ! sis900: tyndur-spezifische Sachen muessen in #ifdef stehen, damit > andere Systeme den Treiber 1:1 benutzern koennen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Aug 6 15:42:45 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 15:42:45 +0200 Subject: [tyndur-devel] [PATCH 4/5] e1000: tyndur-spezifischer Code entfernt In-Reply-To: <1249488805-21506-5-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> <1249488805-21506-5-git-send-email-kevin@tyndur.org> Message-ID: <20090806134245.GD6738@einstein.kaufmann.lan> On Wed, Aug 05 18:13, Kevin Wolf wrote: > ! e1000: Es gibt keinen Grund mehr, Ausgaben auf VT2 zu machen, und > portabel ist es sowieso nicht > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Aug 6 15:43:03 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 15:43:03 +0200 Subject: [tyndur-devel] [PATCH 5/5] rtl8139: tyndur-spezifische Sachen In-Reply-To: <1249488805-21506-6-git-send-email-kevin@tyndur.org> References: <1249488805-21506-1-git-send-email-kevin@tyndur.org> <1249488805-21506-6-git-send-email-kevin@tyndur.org> Message-ID: <20090806134302.GE6738@einstein.kaufmann.lan> On Wed, Aug 05 18:13, Kevin Wolf wrote: > ! rtl8139: tyndur-spezifisches in #ifdef > * rtl8139: Unbenoetigtes #include entfernt > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Aug 6 16:26:25 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 16:26:25 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Virtuell, aber nicht physisch zusammenhaengender Speicher In-Reply-To: <1249465874-9112-1-git-send-email-kevin@tyndur.org> References: <1249465874-9112-1-git-send-email-kevin@tyndur.org> Message-ID: <20090806142625.GF6738@einstein.kaufmann.lan> On Wed, Aug 05 11:51, Kevin Wolf wrote: > + kernel2: mmc_valloc() alloziert virtuell zusammenhaengenden Speicher, > der aber physisch nicht zusammenhaengend sein muss > ! kernel2: Entsprechende FIXMEs geloest, wo bisher unnoetigerweise > physisch zusammenhaengender Speicher reserviert wurde > > Signed-off-by: Kevin Wolf Hm irgendwie macht es mir ja Angst, dass ich da nichts finde... Aber ich muss das wohl oder übel so akzeptieren. ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Aug 6 16:35:40 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 16:35:40 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Syscall SYSCALL_PM_ENUMERATE_TASKS In-Reply-To: <1249424448-17788-1-git-send-email-kevin@tyndur.org> References: <1249424448-17788-1-git-send-email-kevin@tyndur.org> Message-ID: <20090806143540.GG6738@einstein.kaufmann.lan> On Wed, Aug 05 00:20, Kevin Wolf wrote: > + kernel2: Syscall SYSCALL_PM_ENUMERATE_TASKS (Speicherbedarf und > aktuelles eip bleiben momentan leer) > > Signed-off-by: Kevin Wolf > --- > src/kernel2/include/syscall.h | 4 ++ > src/kernel2/src/syscall.c | 3 ++ > src/kernel2/src/syscalls/pm.c | 77 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 84 insertions(+), 0 deletions(-) > > diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h > index 6637ffd..b7ebfc9 100644 > --- a/src/kernel2/include/syscall.h > +++ b/src/kernel2/include/syscall.h > @@ -116,6 +116,10 @@ pid_t syscall_pm_create_process(vaddr_t start, uid_t uid, > /// Aktuellen Prozess beenden > void syscall_pm_exit_process(void); > > +/// Alle Prozesse auflisten > +void* syscall_pm_enumerate_tasks(void); > + > + > /// Speicher an einen anderen Prozess uebergeben > void syscall_init_child_page(pid_t pid, vaddr_t src, vaddr_t dest, > size_t size); > diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c > index 58c82de..fcb9f66 100644 > --- a/src/kernel2/src/syscall.c > +++ b/src/kernel2/src/syscall.c > @@ -71,6 +71,9 @@ void syscall_init() > syscall_register(SYSCALL_PM_INIT_PAGE, &syscall_init_child_page, 4); > syscall_register(SYSCALL_PM_EXIT_PROCESS, &syscall_pm_exit_process, 0); > > + syscall_register(SYSCALL_PM_ENUMERATE_TASKS, > + &syscall_pm_enumerate_tasks, 0); > + > syscall_register(SYSCALL_SET_RPC_HANDLER, &syscall_set_rpc_handler, 1); > #if CONFIG_ARCH == ARCH_I386 > syscall_register(SYSCALL_FASTRPC, &syscall_fastrpc, 5); > diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c > index b4f5cf7..750d3dc 100644 > --- a/src/kernel2/src/syscalls/pm.c > +++ b/src/kernel2/src/syscalls/pm.c > @@ -38,6 +38,7 @@ > #include > > #include "syscall.h" > +#include "syscall_structs.h" > #include "tasks.h" > #include "cpu.h" > > @@ -234,3 +235,79 @@ void syscall_pm_wait_for_rpc(void) > syscall_pm_sleep(); > thread->status = PM_STATUS_WAIT_FOR_RPC; > } > + > +/** > + * Alle Prozesse auflisten > + * > + * @return Gibt einen Pointer auf neu allozierte Seiten zurueck, die > + * Informationen ueber alle laufenden Tasks enthalten. Der Pointer zeigt dabei > + * auf Daten vom Typ task_info_t. > + */ > +void* syscall_pm_enumerate_tasks(void) > +{ > + // Erst werden die Tasks gezaehlt, und die Groesse der > + // Informationen mit den Kommandozeilen wird errechnet. > + size_t task_count = 0; > + size_t result_size = sizeof(task_info_t); > + pm_process_t* task; > + unsigned int i; > + > + for (i = 0; (task = list_get_element_at(process_list, i)); i++) { > + task_count++; > + result_size += sizeof(task_info_task_t) + strlen(task->cmdline) + 1; > + } > + > + // Anzahl der Seiten berechnen, die die Informationen benoetigen. > + size_t result_page_count = PAGE_ALIGN_ROUND_UP(result_size) / PAGE_SIZE; > + > + // Jetzt wird eine freie Stelle im Adressraum des Prozesses > + // gesucht, wo die Task-Infos hingemappt werden koennen > + // FIXME Die Seiten muessen nicht physisch zusammenhaengend sein > + task_info_t* task_info = mmc_automap(&mmc_current_context(), > + pmm_alloc(result_page_count), result_page_count, MM_USER_START, > + MM_USER_END, PTE_P | PTE_W | PTE_U); > + > + // Der Groessen-Eintrag ist nur da, damit der Task die Pages > + // freigeben koennte. > + task_info->info_size = result_size; > + task_info->task_count = task_count; > + > + // Dieser Pointer zeigt direkt hinter das Array mit den > + // Task-Informationen. Dort werden die Kommandozeilen > + // hintereinander gespeichert, und aus den Task-Strukturen wird auf > + // sie verwiesen. > + char* cmdlines = (char*) task_info->tasks; > + cmdlines += task_count * sizeof(task_info_task_t); > + > + // Jetzt werden die Infos eingefuellt. > + for (i = 0; (task = list_get_element_at(process_list, i)); i++) { > + task_info->tasks[i].pid = task->pid; > + task_info->tasks[i].status = task->status; > + > + // TODO Ergibt strenggenommen keinen Sinn, evtl. ersten Thread? > + task_info->tasks[i].eip = 0; > + > + // Wenn der Task keinen Eltern-Task hat muessen wir aufpassen, > + // damit wir keinen Pagefault produzieren. > + if (task->parent == NULL) { > + task_info->tasks[i].parent_pid = 0; > + } else { > + task_info->tasks[i].parent_pid = task->parent->pid; > + } > + > + // Die Kommandozeile inklusive Nullbyte kopieren > + size_t cmdline_size = strlen(task->cmdline) + 1; > + memcpy(cmdlines, task->cmdline, cmdline_size); So ein strcpy ist schon was feines... ;-) > + > + // Den Pointer fuer die Kommandozeile setzen > + task_info->tasks[i].cmdline = cmdlines; > + > + // Den Zielpointer fuer die naechste Kommandozeile direkt > + // hinter die aktuelle setzen. > + cmdlines += cmdline_size; > + > + task_info->tasks[i].memory_used = 0; // TODO > + } > + > + return task_info; > +} Aber jo, sonst sieht das gut aus. Also wenn du das noch änderst: Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Thu Aug 6 16:47:17 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 6 Aug 2009 16:47:17 +0200 Subject: [tyndur-devel] [PATCH] Pascal: Compilerfehler mit neuerer FPC-Version Message-ID: <1249570037-1978-1-git-send-email-kevin@tyndur.org> ! Pascal: Attribute von Klassen duerfen nicht mehr nach Methoden deklariert werden, ausser es wird durch erneute Angabe der Sichtbarkeit ein neuer Block angefangen. Signed-off-by: Kevin Wolf --- src/modules/pas/lib/tar/tar.pas | 1 + src/modules/pas/lib/tcpip/tcpip.pas | 1 + src/modules/pas/lpt/packages.pas | 4 ++++ 3 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/modules/pas/lib/tar/tar.pas b/src/modules/pas/lib/tar/tar.pas index f80ab9e..dd49a05 100644 --- a/src/modules/pas/lib/tar/tar.pas +++ b/src/modules/pas/lib/tar/tar.pas @@ -32,6 +32,7 @@ type procedure ReadNextBlock(buffer_offset: dword); function BufferIsZero: boolean; + private f: file; in_buffer: PByte; in_size: dword; diff --git a/src/modules/pas/lib/tcpip/tcpip.pas b/src/modules/pas/lib/tcpip/tcpip.pas index 4f06527..d0eaab5 100644 --- a/src/modules/pas/lib/tcpip/tcpip.pas +++ b/src/modules/pas/lib/tcpip/tcpip.pas @@ -29,6 +29,7 @@ type private procedure GetInput; + private conn: longint; buffer: String; fIgnoreCR: boolean; diff --git a/src/modules/pas/lpt/packages.pas b/src/modules/pas/lpt/packages.pas index c1f4130..9e2b44c 100644 --- a/src/modules/pas/lpt/packages.pas +++ b/src/modules/pas/lpt/packages.pas @@ -30,6 +30,7 @@ type function GetCurrentVersion (pkgname, sectname: String): TPackageVersion; + public packages: TCollection; end; @@ -43,6 +44,7 @@ type function add(name: String): TPackageSection; + public name: String; desc: String; sections: TCollection; @@ -58,6 +60,7 @@ type function add(number: String): TPackageVersion; + public section: String; versions: TCollection; end; @@ -76,6 +79,7 @@ type property preinstDependencies: TCollection read instDep; property runDependencies: TCollection read runDep; + public repository: String; version: String; size: dword; -- 1.5.6.5 From toni at tyndur.org Thu Aug 6 17:08:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 6 Aug 2009 17:08:44 +0200 Subject: [tyndur-devel] [PATCH] Pascal: Compilerfehler mit neuerer FPC-Version In-Reply-To: <1249570037-1978-1-git-send-email-kevin@tyndur.org> References: <1249570037-1978-1-git-send-email-kevin@tyndur.org> Message-ID: <20090806150844.GA14838@thales.kaufmann.lan> On Thu, Aug 06 16:47, Kevin Wolf wrote: > ! Pascal: Attribute von Klassen duerfen nicht mehr nach Methoden deklariert > werden, ausser es wird durch erneute Angabe der Sichtbarkeit ein neuer Block > angefangen. > > Signed-off-by: Kevin Wolf Wenns kompiliert.... Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Thu Aug 6 23:41:26 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 6 Aug 2009 23:41:26 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Syscall SYSCALL_MEM_INFO Message-ID: <1249594886-374-1-git-send-email-kevin@tyndur.org> + kernel2: Syscall SYSCALL_MEM_INFO ! kernel2: pmm_count_pages() macht jetzt was sinnvolles anstatt eine uninitialisierte Variable zurueckzugeben. Signed-off-by: Kevin Wolf --- src/kernel2/include/syscall.h | 4 ++++ src/kernel2/src/arch/i386/syscall.c | 4 ++++ src/kernel2/src/mm/phys.c | 9 +-------- src/kernel2/src/syscall.c | 1 + src/kernel2/src/syscalls/mem.c | 10 ++++++++++ 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h index b7ebfc9..ea182c4 100644 --- a/src/kernel2/include/syscall.h +++ b/src/kernel2/include/syscall.h @@ -84,6 +84,10 @@ vaddr_t syscall_mem_allocate_physical( /// Einen Speicherblock freigeben void syscall_mem_free(vaddr_t start, size_t bytes); +/// Freie Pages und Gesamtspeicher zurueckgeben +void syscall_mem_info(uint32_t* sum_pages, uint32_t* free_pages); + + // Prozessverwaltung /// PID des aktuellen Prozesses abfragen pid_t syscall_pm_get_pid(void); diff --git a/src/kernel2/src/arch/i386/syscall.c b/src/kernel2/src/arch/i386/syscall.c index 268d4e4..e8d71dc 100644 --- a/src/kernel2/src/arch/i386/syscall.c +++ b/src/kernel2/src/arch/i386/syscall.c @@ -91,6 +91,10 @@ void syscall_arch(machine_state_t* isf) syscall_fastrpc_ret(); + } else if (handler == syscall_mem_info) { + + syscall_mem_info(&isf->eax, &isf->edx); + } else { uint32_t eax, edx; dword stack_backup; diff --git a/src/kernel2/src/mm/phys.c b/src/kernel2/src/mm/phys.c index 1d11478..e77bb3c 100644 --- a/src/kernel2/src/mm/phys.c +++ b/src/kernel2/src/mm/phys.c @@ -65,13 +65,6 @@ static lock_t pmm_lock = 0; static size_t pmm_bitmap_length; /** - * Anzahl der nutzbaren Seiten. Entspricht pmm_bitmap_size * 32 abzüglich - * der von der BIOS-Memory-Map als reserviert gekennzeichneten Bereiche. - */ -static size_t pmm_bitmap_usable_pages; - - -/** * Gibt die Startadresse der Bitmap zurück */ void* pmm_get_bitmap_start() @@ -123,7 +116,7 @@ size_t pmm_count_free() */ size_t pmm_count_pages() { - return pmm_bitmap_usable_pages; + return 8 * pmm_get_bitmap_size(); } /** diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c index fcb9f66..4292724 100644 --- a/src/kernel2/src/syscall.c +++ b/src/kernel2/src/syscall.c @@ -52,6 +52,7 @@ void syscall_init() syscall_register(SYSCALL_MEM_ALLOCATE_PHYSICAL, &syscall_mem_allocate_physical, 3); syscall_register(SYSCALL_MEM_FREE, &syscall_mem_free, 2); + syscall_register(SYSCALL_MEM_INFO, &syscall_mem_info, 0); syscall_register(SYSCALL_PM_GET_PID, (void*) &syscall_pm_get_pid, 0); syscall_register(SYSCALL_PM_GET_PARENT_PID, (void*) diff --git a/src/kernel2/src/syscalls/mem.c b/src/kernel2/src/syscalls/mem.c index ff66fa0..20f9e73 100644 --- a/src/kernel2/src/syscalls/mem.c +++ b/src/kernel2/src/syscalls/mem.c @@ -130,3 +130,13 @@ void syscall_mem_free(vaddr_t start, size_t bytes) start = (vaddr_t) ((uintptr_t) start + PAGE_SIZE); } } + +/** + * Gibt zurueck, wie viele Byte Speicher dem System insgesamt zur Verfuegung + * stehen und wie viele davon frei sind. + */ +void syscall_mem_info(uint32_t* sum_pages, uint32_t* free_pages) +{ + *sum_pages = pmm_count_pages() * PAGE_SIZE; + *free_pages = pmm_count_free() * PAGE_SIZE; +} -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 10:47:20 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 10:47:20 +0200 Subject: [tyndur-devel] [PATCH 0/3] ip-Parameter nach tcpip verschieben Message-ID: <1249634843-11618-1-git-send-email-kevin@tyndur.org> Bisher wurden IP-Adressen in der Kommandozeile des Netzwerkkartentreibers initialisiert, was einerseits unlogisch und andererseits fuer tyndur-spezifischen Code in Treibern verantwortlich ist. Also verschieben wir den Parameter einfach mal nach tcpip. Kevin Wolf (3): tcpip: Kommandozeilenparameter fuer Default-IP libc: IP-Adresse bei der Treiberregistrierung entfernt cdi: ip-Kommandozeilenparameter in Netzwerktreibern entfernt src/modules/cdi/include/cdi/net.h | 3 -- src/modules/cdi/lib/net/net.c | 7 +----- src/modules/cdi/pcnet/main.c | 38 +------------------------------- src/modules/cdi/rtl8139/main.c | 38 +------------------------------- src/modules/cdi/sis900/main.c | 44 +------------------------------------ src/modules/include/network.h | 5 +-- src/modules/lib/network.c | 4 +-- src/modules/tcpip/arp.c | 6 ++-- src/modules/tcpip/include/main.h | 9 +++++-- src/modules/tcpip/ip.c | 2 +- src/modules/tcpip/lostio_if.c | 4 +- src/modules/tcpip/main.c | 8 ++++++- src/modules/tcpip/tcp.c | 2 +- src/modules/tcpip/tcp_server.c | 2 +- 14 files changed, 28 insertions(+), 144 deletions(-) From kevin at tyndur.org Fri Aug 7 10:47:21 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 10:47:21 +0200 Subject: [tyndur-devel] [PATCH 1/3] tcpip: Kommandozeilenparameter fuer Default-IP In-Reply-To: <1249634843-11618-1-git-send-email-kevin@tyndur.org> References: <1249634843-11618-1-git-send-email-kevin@tyndur.org> Message-ID: <1249634843-11618-2-git-send-email-kevin@tyndur.org> + tcpip: Kommandozeilenparameter ip=a.b.c.d fuer Default-IP. Die vom Treiber uebergebene IP wird ab sofort ignoriert. Signed-off-by: Kevin Wolf --- src/modules/tcpip/arp.c | 6 +++--- src/modules/tcpip/include/main.h | 9 ++++++--- src/modules/tcpip/ip.c | 2 +- src/modules/tcpip/lostio_if.c | 4 ++-- src/modules/tcpip/main.c | 8 +++++++- src/modules/tcpip/tcp.c | 2 +- src/modules/tcpip/tcp_server.c | 2 +- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/modules/tcpip/arp.c b/src/modules/tcpip/arp.c index e2b7609..b2b6236 100644 --- a/src/modules/tcpip/arp.c +++ b/src/modules/tcpip/arp.c @@ -76,7 +76,7 @@ static void arp_send_request(struct device *device, arp->source_mac = device->dev.mac; arp->dest_mac = eth->dest; - arp->source_ip = device->dev.ip; + arp->source_ip = device->ip; arp->dest_ip = ip; ethernet_send_packet(device, @@ -107,7 +107,7 @@ void arp_send_response(struct device* device, struct arp* request) arp->source_mac = eth->src; arp->dest_mac = eth->dest; - arp->source_ip = device->dev.ip; + arp->source_ip = device->ip; arp->dest_ip = request->source_ip; ethernet_send_packet(device, @@ -173,7 +173,7 @@ void arp_receive(struct device *device, void* packet, size_t size) } else if (arp->command == ARP_CMD_REQUEST) { - if (arp->dest_ip == device->dev.ip) { + if (arp->dest_ip == device->ip) { arp_send_response(device, arp); } } diff --git a/src/modules/tcpip/include/main.h b/src/modules/tcpip/include/main.h index caebd31..9340469 100644 --- a/src/modules/tcpip/include/main.h +++ b/src/modules/tcpip/include/main.h @@ -37,11 +37,13 @@ #define _MAIN_H_ #include -#include "network.h" +#include +#include struct module_options { - dword gateway; - dword nameserver; + uint32_t gateway; + uint32_t nameserver; + uint32_t ip; }; struct driver @@ -55,6 +57,7 @@ struct device { struct net_device dev; struct driver *driver; + uint32_t ip; }; extern struct module_options options; diff --git a/src/modules/tcpip/ip.c b/src/modules/tcpip/ip.c index 67c60b1..8a1b975 100644 --- a/src/modules/tcpip/ip.c +++ b/src/modules/tcpip/ip.c @@ -120,7 +120,7 @@ static bool ip_send_packet_direct(struct device* device, uint32_t dest_ip, struct eth_packet_header* eth; // Source-IP im Header eintagen und Pruefsumme berechnen - header->source_ip = device->dev.ip; + header->source_ip = device->ip; ip_update_checksum(header); diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c index a3b0f1c..b79ebf8 100644 --- a/src/modules/tcpip/lostio_if.c +++ b/src/modules/tcpip/lostio_if.c @@ -357,7 +357,7 @@ size_t lostio_netconfig_read(lostio_filehandle_t *handle, void *buf, size_t bloc char *data = NULL; // //ip if (handle->node->size == 1) - data = ip_to_string(device->dev.ip); + data = ip_to_string(device->ip); // //mac else if (handle->node->size == 2) data = mac_to_string(device->dev.mac); @@ -385,7 +385,7 @@ size_t lostio_netconfig_write(lostio_filehandle_t *handle, size_t blocksize, siz struct device *device = (struct device *) handle->node->data; if (handle->node->size == 1) { - device->dev.ip = string_to_ip(data); + device->ip = string_to_ip(data); return blocksize * count; } else if (handle->node->size == 2) diff --git a/src/modules/tcpip/main.c b/src/modules/tcpip/main.c index 5618482..1a99014 100644 --- a/src/modules/tcpip/main.c +++ b/src/modules/tcpip/main.c @@ -55,7 +55,8 @@ static list_t *net_drivers; struct module_options options = { .gateway = 0x0202000a, - .nameserver = 0xdede43d0 + .nameserver = 0xdede43d0, + .ip = 0x0e02000a, }; void init_routing(struct device *device); @@ -157,6 +158,7 @@ void rpc_register_driver(pid_t pid, dword cid, size_t data_size, void* data) struct device *device = malloc(sizeof(struct device)); memcpy(device, data, sizeof(struct net_device)); device->driver = driver; + device->ip = options.ip; list_push(driver->devices, device); // VFS Ordner und Dateien für das Device erstellen @@ -218,6 +220,10 @@ void process_parameter(struct module_options* options, char* param) dword nameserver = string_to_ip(¶m[3]); printf("Nameserver: %08x\n", nameserver); options->nameserver = nameserver; + } else if (strncmp(param, "ip=", 3) == 0) { + uint32_t ip = string_to_ip(¶m[3]); + printf("IP-Adresse: %08x\n", ip); + options->ip = ip; } else { printf("Unbekannter Parameter %s\n", param); } diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index 30d39ae..79febba 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -196,7 +196,7 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) conn->dest_ip = ip; conn->dest_port = port; - conn->source_ip = route->device->dev.ip; + conn->source_ip = route->device->ip; conn->source_port = tcp_get_free_port(); conn->window = 0; conn->ack = 0; diff --git a/src/modules/tcpip/tcp_server.c b/src/modules/tcpip/tcp_server.c index 16b0a72..28ce98d 100644 --- a/src/modules/tcpip/tcp_server.c +++ b/src/modules/tcpip/tcp_server.c @@ -242,7 +242,7 @@ int tcp_incoming_connection(uint32_t remote_ip, conn->dest_ip = remote_ip; conn->dest_port = remote_port; - conn->source_ip = route->device->dev.ip; + conn->source_ip = route->device->ip; conn->source_port = local_port; conn->window = 0x1000; conn->ack = big_endian_dword(header->seq) + 1; -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 10:47:22 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 10:47:22 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: IP-Adresse bei der Treiberregistrierung entfernt In-Reply-To: <1249634843-11618-1-git-send-email-kevin@tyndur.org> References: <1249634843-11618-1-git-send-email-kevin@tyndur.org> Message-ID: <1249634843-11618-3-git-send-email-kevin@tyndur.org> - libc: Bei der Registrierung eines Netzwerktreibers wird die IP-Adresse des Geraets nicht mehr uebertragen. Signed-off-by: Kevin Wolf --- src/modules/cdi/lib/net/net.c | 7 +------ src/modules/include/network.h | 5 ++--- src/modules/lib/network.c | 4 +--- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/modules/cdi/lib/net/net.c b/src/modules/cdi/lib/net/net.c index beb812c..88a5bb1 100644 --- a/src/modules/cdi/lib/net/net.c +++ b/src/modules/cdi/lib/net/net.c @@ -58,18 +58,13 @@ void cdi_net_driver_destroy(struct cdi_net_driver* driver) void cdi_net_device_init(struct cdi_net_device* device) { device->number = netcard_highest_id; - if (device->ip == 0) { - // FIXME - device->ip = 0x4201a8c0; - } // Zur Liste der Netzwerkkarten hinzufügen cdi_list_push(netcard_list, device); // Beim tcpip Modul registrieren register_netcard(device->number, - device->mac, - device->ip); + device->mac); ++netcard_highest_id; } diff --git a/src/modules/include/network.h b/src/modules/include/network.h index ef0bb99..ca36a97 100644 --- a/src/modules/include/network.h +++ b/src/modules/include/network.h @@ -43,14 +43,13 @@ (big_endian_word((x) >> 16))) struct net_device { - dword number; + uint32_t number; uint64_t mac; - dword ip; }; dword string_to_ip(const char* ip); char* ip_to_string(dword ip); char* mac_to_string(uint64_t mac); -void register_netcard(dword device_numer, uint64_t mac, dword ip); +void register_netcard(dword device_numer, uint64_t mac); #endif diff --git a/src/modules/lib/network.c b/src/modules/lib/network.c index d0343d3..ac32ef4 100644 --- a/src/modules/lib/network.c +++ b/src/modules/lib/network.c @@ -110,13 +110,11 @@ char* mac_to_string(uint64_t mac) * * @param ip IP-Adresse, die der Netzwerkkarte zugeordnet ist. */ -//FIXME: ip braucht keine Sau hier -void register_netcard(dword device_number, uint64_t mac, dword ip) +void register_netcard(dword device_number, uint64_t mac) { struct net_device driver = { .number = device_number, .mac = mac, - .ip = ip }; char buffer[8 + sizeof(struct net_device)]; -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 10:47:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 10:47:23 +0200 Subject: [tyndur-devel] [PATCH 3/3] cdi: ip-Kommandozeilenparameter in Netzwerktreibern entfernt In-Reply-To: <1249634843-11618-1-git-send-email-kevin@tyndur.org> References: <1249634843-11618-1-git-send-email-kevin@tyndur.org> Message-ID: <1249634843-11618-4-git-send-email-kevin@tyndur.org> - cdi: ip-Kommandozeilenparameter in Netzwerktreibern entfernt Signed-off-by: Kevin Wolf --- src/modules/cdi/include/cdi/net.h | 3 -- src/modules/cdi/pcnet/main.c | 38 +------------------------------- src/modules/cdi/rtl8139/main.c | 38 +------------------------------- src/modules/cdi/sis900/main.c | 44 +------------------------------------ 4 files changed, 3 insertions(+), 120 deletions(-) diff --git a/src/modules/cdi/include/cdi/net.h b/src/modules/cdi/include/cdi/net.h index f8ff6d2..89628bd 100644 --- a/src/modules/cdi/include/cdi/net.h +++ b/src/modules/cdi/include/cdi/net.h @@ -29,9 +29,6 @@ struct cdi_net_device { void (*send_packet) (struct cdi_net_device* device, void* data, size_t size); - - // LOST-spezifisch - uint32_t ip; }; struct cdi_net_driver { diff --git a/src/modules/cdi/pcnet/main.c b/src/modules/cdi/pcnet/main.c index d8a77f6..04711ae 100644 --- a/src/modules/cdi/pcnet/main.c +++ b/src/modules/cdi/pcnet/main.c @@ -52,12 +52,6 @@ static struct { static const char* driver_name = "pcnet"; -#ifdef TYNDUR -// FIXME: LOST-spezifisch -uint32_t string_to_ip(char* ip); -#endif - -static void process_parameter(struct module_options* options, char* param); static int pcnet_driver_init(int argc, char* argv[]); static void pcnet_driver_destroy(struct cdi_driver* driver); @@ -81,12 +75,6 @@ int init_pcnet(int argc, char* argv[]) static int pcnet_driver_init(int argc, char* argv[]) { - struct module_options options = { - // TODO Auf 0 setzen und am Ende pr�fen und ggf. einfach was - // freies suchen - .ip = 0x0b01a8c0 - }; - // TODO Auf pci-Service warten // TODO Auf tcpip-Service warten @@ -101,17 +89,12 @@ static int pcnet_driver_init(int argc, char* argv[]) driver.net.drv.init_device = pcnet_init_device; driver.net.drv.remove_device = pcnet_remove_device; - // Parameter verarbeiten - int i; - for (i = 1; i < argc; i++) { - process_parameter(&options, argv[i]); - } - // Passende PCI-Geraete suchen cdi_list_t pci_devices = cdi_list_create(); cdi_pci_get_all_devices(pci_devices); struct cdi_pci_device* dev; + int i; for (i = 0; (dev = cdi_list_get(pci_devices, i)); i++) { if ((dev->vendor_id == VENDOR_ID) && (dev->device_id == DEVICE_ID)) { struct pcnet_device* device; @@ -120,9 +103,6 @@ static int pcnet_driver_init(int argc, char* argv[]) memset(device, 0, sizeof(struct pcnet_device)); device->pci = dev; -#ifdef TYNDUR - device->net.ip = options.ip; -#endif cdi_list_push(driver.net.drv.devices, device); } else { cdi_pci_device_destroy(dev); @@ -134,22 +114,6 @@ static int pcnet_driver_init(int argc, char* argv[]) return 0; } - -static void process_parameter(struct module_options* options, char* param) -{ -#ifdef TYNDUR - printf("pcnet-Parameter: %s\n", param); - - if (strncmp(param, "ip=", 3) == 0) { - uint32_t ip = string_to_ip(¶m[3]); - printf("IP-Adresse: %08x\n", ip); - options->ip = ip; - } else { - printf("Unbekannter Parameter %s\n", param); - } -#endif -} - /** * Deinitialisiert die Datenstrukturen fuer den pcnet-Treiber */ diff --git a/src/modules/cdi/rtl8139/main.c b/src/modules/cdi/rtl8139/main.c index 4411a1f..46cd918 100644 --- a/src/modules/cdi/rtl8139/main.c +++ b/src/modules/cdi/rtl8139/main.c @@ -44,12 +44,6 @@ static struct { static const char* driver_name = "rtl8139"; -#ifdef TYNDUR -// FIXME: tyndur-spezifisch -uint32_t string_to_ip(char* ip); -#endif - -static void process_parameter(struct module_options* options, char* param); static int rtl8139_driver_init(int argc, char* argv[]); static void rtl8139_driver_destroy(struct cdi_driver* driver); @@ -73,12 +67,6 @@ int init_rtl8139(int argc, char* argv[]) static int rtl8139_driver_init(int argc, char* argv[]) { - struct module_options options = { - // TODO Auf 0 setzen und am Ende prüfen und ggf. einfach was - // freies suchen - .ip = 0x0b01a8c0 - }; - // TODO Auf pci-Service warten // TODO Auf tcpip-Service warten @@ -93,17 +81,12 @@ static int rtl8139_driver_init(int argc, char* argv[]) driver.net.drv.init_device = rtl8139_init_device; driver.net.drv.remove_device = rtl8139_remove_device; - // Parameter verarbeiten - int i; - for (i = 1; i < argc; i++) { - process_parameter(&options, argv[i]); - } - // Passende PCI-Geraete suchen cdi_list_t pci_devices = cdi_list_create(); cdi_pci_get_all_devices(pci_devices); struct cdi_pci_device* dev; + int i; for (i = 0; (dev = cdi_list_get(pci_devices, i)); i++) { if ((dev->vendor_id == 0x10ec) && (dev->device_id == 0x8139)) { void* phys_device; @@ -115,9 +98,6 @@ static int rtl8139_driver_init(int argc, char* argv[]) device->phys = phys_device; device->pci = dev; -#ifdef TYNDUR - device->net.ip = options.ip; -#endif cdi_list_push(driver.net.drv.devices, device); } else { cdi_pci_device_destroy(dev); @@ -129,22 +109,6 @@ static int rtl8139_driver_init(int argc, char* argv[]) return 0; } - -static void process_parameter(struct module_options* options, char* param) -{ -#ifdef TYNDUR - printf("rtl8139-Parameter: %s\n", param); - - if (strncmp(param, "ip=", 3) == 0) { - uint32_t ip = string_to_ip(¶m[3]); - printf("IP-Adresse: %08x\n", ip); - options->ip = ip; - } else { - printf("Unbekannter Parameter %s\n", param); - } -#endif -} - /** * Deinitialisiert die Datenstrukturen fuer den rtl8139-Treiber */ diff --git a/src/modules/cdi/sis900/main.c b/src/modules/cdi/sis900/main.c index 88bc2f0..aaaf996 100644 --- a/src/modules/cdi/sis900/main.c +++ b/src/modules/cdi/sis900/main.c @@ -36,17 +36,6 @@ #include "device.h" - -struct module_options { - uint32_t ip; -}; - -#ifdef TYNDUR -uint32_t string_to_ip(char* ip); -#endif - -static void process_parameter(struct module_options* options, char* param); - struct sis900_driver { struct cdi_net_driver net; }; @@ -80,12 +69,6 @@ int init_sis900(int argc, char* argv[]) */ static void sis900_driver_init(int argc, char* argv[]) { - struct module_options options = { - // TODO Auf 0 setzen und am Ende prüfen und ggf. einfach was - // freies suchen - .ip = 0x0b01a8c0 - }; - // Konstruktor der Vaterklasse cdi_net_driver_init((struct cdi_net_driver*) &driver); @@ -97,19 +80,12 @@ static void sis900_driver_init(int argc, char* argv[]) driver.net.drv.init_device = sis900_init_device; driver.net.drv.remove_device = sis900_remove_device; - // Parameter verarbeiten - int i; -#ifdef TYNDUR - for (i = 1; i < argc; i++) { - process_parameter(&options, argv[i]); - } -#endif - // Passende PCI-Geraete suchen cdi_list_t pci_devices = cdi_list_create(); cdi_pci_get_all_devices(pci_devices); struct cdi_pci_device* dev; + int i; for (i = 0; (dev = cdi_list_get(pci_devices, i)); i++) { if ((dev->vendor_id == 0x1039) && (dev->device_id == 0x0900)) { void* phys_device; @@ -121,9 +97,6 @@ static void sis900_driver_init(int argc, char* argv[]) device->phys = phys_device; device->pci = dev; -#ifdef TYNDUR - device->net.ip = options.ip; -#endif cdi_list_push(driver.net.drv.devices, device); } else { cdi_pci_device_destroy(dev); @@ -136,21 +109,6 @@ static void sis900_driver_init(int argc, char* argv[]) cdi_list_destroy(pci_devices); } -#ifdef TYNDUR -static void process_parameter(struct module_options* options, char* param) -{ - printf("sis900-Parameter: %s\n", param); - - if (strncmp(param, "ip=", 3) == 0) { - uint32_t ip = string_to_ip(¶m[3]); - printf("IP-Adresse: %08x\n", ip); - options->ip = ip; - } else { - printf("Unbekannter Parameter %s\n", param); - } -} -#endif - /** * Deinitialisiert die Datenstrukturen fuer den sis900-Treiber */ -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 11:24:49 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 11:24:49 +0200 Subject: [tyndur-devel] [PATCH] kernel2: IRQs beim Registrieren eines Handlers demaskieren Message-ID: <1249637089-19722-1-git-send-email-kevin@tyndur.org> ! kernel2: IRQs werden maskiert, wenn sie auftreten und kein Handler registriert ist. Wenn der Treiber dann schliesslich kommt, brauchen wir den IRQ aber wieder. Fixt den haengenden Tastaturtreiber, wenn zu frueh auf den Tasten rumgehaemmert wird. Signed-off-by: Kevin Wolf --- src/kernel2/src/interrupts/im.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/kernel2/src/interrupts/im.c b/src/kernel2/src/interrupts/im.c index 5057303..d7130bd 100644 --- a/src/kernel2/src/interrupts/im.c +++ b/src/kernel2/src/interrupts/im.c @@ -216,6 +216,12 @@ bool im_add_handler(uint32_t intr, pm_process_t* handler) intr_handling_task[intr] = handler; pm_register_on_destroy(handler, on_process_destroy, (void*) intr); + // Moeglicherweise ist der IRQ frueher maskiert worden, weil es keinen + // Treiber dafuer gab. Spaetestens jetzt brauchen wir ihn aber wieder. + if ((intr >= IM_IRQ_BASE) && (intr< (IM_IRQ_BASE + 16))) { + im_enable_irq(intr - IM_IRQ_BASE); + } + return TRUE; } -- 1.5.6.5 From toni at tyndur.org Fri Aug 7 11:30:19 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 11:30:19 +0200 Subject: [tyndur-devel] [PATCH] kernel2: IRQs beim Registrieren eines Handlers demaskieren In-Reply-To: <1249637089-19722-1-git-send-email-kevin@tyndur.org> References: <1249637089-19722-1-git-send-email-kevin@tyndur.org> Message-ID: <20090807093019.GA6168@einstein.kaufmann.lan> On Fri, Aug 07 11:24, Kevin Wolf wrote: > ! kernel2: IRQs werden maskiert, wenn sie auftreten und kein Handler > registriert ist. Wenn der Treiber dann schliesslich kommt, brauchen wir den > IRQ aber wieder. Fixt den haengenden Tastaturtreiber, wenn zu frueh auf den > Tasten rumgehaemmert wird. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Fri Aug 7 12:19:26 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 12:19:26 +0200 Subject: [tyndur-devel] [PATCH] cdi: cdi_run_drivers unbedingt ausfuehren Message-ID: <1249640366-22461-1-git-send-email-kevin@tyndur.org> * cdi: Auch modulare Monolithen koennen mit cdi_run_drivers etwas anfangen, also nicht von CDI_STANDALONE abhaengig machen. Signed-off-by: Kevin Wolf --- src/modules/cdi/ata/main.c | 2 -- src/modules/cdi/e1000/main.c | 2 -- src/modules/cdi/ext2/main.c | 2 -- src/modules/cdi/floppy/main.c | 2 -- src/modules/cdi/include/cdi.h | 12 +++++++++--- src/modules/cdi/iso9660/main.c | 2 -- src/modules/cdi/lib/cdi.c | 12 +++++++++--- src/modules/cdi/pcnet/main.c | 2 -- src/modules/cdi/ramdisk/main.c | 2 -- src/modules/cdi/rtl8139/main.c | 2 -- src/modules/cdi/serial/main.c | 2 -- src/modules/cdi/sis900/main.c | 2 -- 12 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/modules/cdi/ata/main.c b/src/modules/cdi/ata/main.c index 7008b95..144a6f8 100644 --- a/src/modules/cdi/ata/main.c +++ b/src/modules/cdi/ata/main.c @@ -57,9 +57,7 @@ int init_ata(int argc, char* argv[]) cdi_storage_driver_register((struct cdi_storage_driver*) &driver_storage); cdi_scsi_driver_register((struct cdi_scsi_driver*) &driver_scsi); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/e1000/main.c b/src/modules/cdi/e1000/main.c index 584d610..39da9f6 100644 --- a/src/modules/cdi/e1000/main.c +++ b/src/modules/cdi/e1000/main.c @@ -57,9 +57,7 @@ int init_e1000(void) e1000_driver_init(); cdi_driver_register((struct cdi_driver*) &driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/ext2/main.c b/src/modules/cdi/ext2/main.c index 05ae2ba..acbe6db 100644 --- a/src/modules/cdi/ext2/main.c +++ b/src/modules/cdi/ext2/main.c @@ -64,9 +64,7 @@ int init_ext2(void) } cdi_fs_driver_register((struct cdi_fs_driver*) &ext2_driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/floppy/main.c b/src/modules/cdi/floppy/main.c index 16e28c7..8ecd8cd 100644 --- a/src/modules/cdi/floppy/main.c +++ b/src/modules/cdi/floppy/main.c @@ -63,9 +63,7 @@ int init_floppy(void) } cdi_storage_driver_register((struct cdi_storage_driver*) &floppy_driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 8d7c2e8..7bcf9e4 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -59,9 +59,15 @@ struct cdi_driver { void cdi_init(void); /** - * Fuehrt alle registrierten Treiber aus. Nach dem Aufruf dieser Funktion - * duerfen keine weiteren Befehle ausgefuehrt werden, da nicht definiert ist, - * ob und wann die Funktion zurueckkehrt. + * Diese Funktion wird von Treibern aufgerufen, nachdem ein neuer Treiber + * hinzugefuegt worden ist. + * + * Sie registriert typischerweise die neu hinzugefuegten Treiber und/oder + * Geraete beim Betriebssystem und startet damit ihre Ausfuehrung. + * + * Nach dem Aufruf dieser Funktion duerfen vom Treiber keine weiteren Befehle + * ausgefuehrt werden, da nicht definiert ist, ob und wann die Funktion + * zurueckkehrt. */ void cdi_run_drivers(void); diff --git a/src/modules/cdi/iso9660/main.c b/src/modules/cdi/iso9660/main.c index 9a2af55..3d21a96 100644 --- a/src/modules/cdi/iso9660/main.c +++ b/src/modules/cdi/iso9660/main.c @@ -45,9 +45,7 @@ int init_iso9660(void) if (iso9660_driver_init(&iso9660_driver)!=0) return -1; cdi_fs_driver_register((struct cdi_fs_driver*)&iso9660_driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/lib/cdi.c b/src/modules/cdi/lib/cdi.c index d8c7819..b650a79 100644 --- a/src/modules/cdi/lib/cdi.c +++ b/src/modules/cdi/lib/cdi.c @@ -68,9 +68,15 @@ static void cdi_destroy(void) } /** - * Fuehrt alle registrierten Treiber aus. Nach dem Aufruf dieser Funktion - * duerfen keine weiteren Befehle ausgefuehrt werden, da nicht definiert ist, - * ob und wann die Funktion zurueckkehrt. + * Diese Funktion wird von Treibern aufgerufen, nachdem ein neuer Treiber + * hinzugefuegt worden ist. + * + * Sie registriert typischerweise die neu hinzugefuegten Treiber und/oder + * Geraete beim Betriebssystem und startet damit ihre Ausfuehrung. + * + * Nach dem Aufruf dieser Funktion duerfen vom Treiber keine weiteren Befehle + * ausgefuehrt werden, da nicht definiert ist, ob und wann die Funktion + * zurueckkehrt. */ void cdi_run_drivers(void) { diff --git a/src/modules/cdi/pcnet/main.c b/src/modules/cdi/pcnet/main.c index 04711ae..dd94159 100644 --- a/src/modules/cdi/pcnet/main.c +++ b/src/modules/cdi/pcnet/main.c @@ -66,9 +66,7 @@ int init_pcnet(int argc, char* argv[]) pcnet_driver_init(argc, argv); cdi_driver_register((struct cdi_driver*) &driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/ramdisk/main.c b/src/modules/cdi/ramdisk/main.c index d15fd84..73a7e0c 100644 --- a/src/modules/cdi/ramdisk/main.c +++ b/src/modules/cdi/ramdisk/main.c @@ -58,9 +58,7 @@ int init_ramdisk(void) } cdi_fs_driver_register((struct cdi_fs_driver*) &ramdisk_driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/rtl8139/main.c b/src/modules/cdi/rtl8139/main.c index 46cd918..b864724 100644 --- a/src/modules/cdi/rtl8139/main.c +++ b/src/modules/cdi/rtl8139/main.c @@ -58,9 +58,7 @@ int init_rtl8139(int argc, char* argv[]) rtl8139_driver_init(argc, argv); cdi_driver_register((struct cdi_driver*) &driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/serial/main.c b/src/modules/cdi/serial/main.c index 113c4cf..2ebc62a 100644 --- a/src/modules/cdi/serial/main.c +++ b/src/modules/cdi/serial/main.c @@ -58,9 +58,7 @@ int init_serial(void) } cdi_fs_driver_register((struct cdi_fs_driver*) &serial_driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } diff --git a/src/modules/cdi/sis900/main.c b/src/modules/cdi/sis900/main.c index aaaf996..1904c6e 100644 --- a/src/modules/cdi/sis900/main.c +++ b/src/modules/cdi/sis900/main.c @@ -57,9 +57,7 @@ int init_sis900(int argc, char* argv[]) sis900_driver_init(argc, argv); cdi_driver_register((struct cdi_driver*) &driver); -#ifdef CDI_STANDALONE cdi_run_drivers(); -#endif return 0; } -- 1.5.6.5 From toni at tyndur.org Fri Aug 7 13:45:34 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 13:45:34 +0200 Subject: [tyndur-devel] [PATCH] cdi: cdi_run_drivers unbedingt ausfuehren In-Reply-To: <1249640366-22461-1-git-send-email-kevin@tyndur.org> References: <1249640366-22461-1-git-send-email-kevin@tyndur.org> Message-ID: <20090807114534.GB6168@einstein.kaufmann.lan> On Fri, Aug 07 12:19, Kevin Wolf wrote: > * cdi: Auch modulare Monolithen koennen mit cdi_run_drivers etwas anfangen, > also nicht von CDI_STANDALONE abhaengig machen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Fri Aug 7 14:04:29 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 14:04:29 +0200 Subject: [tyndur-devel] [PATCH] e1000: Debugmeldungen ausschalten Message-ID: <1249646669-15421-1-git-send-email-kevin@tyndur.org> * e1000: Eigentlich brauchen wir die Debugmeldungen im Moment nicht mehr Signed-off-by: Kevin Wolf --- src/modules/cdi/e1000/device.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/modules/cdi/e1000/device.c b/src/modules/cdi/e1000/device.c index 7026958..5534b3b 100644 --- a/src/modules/cdi/e1000/device.c +++ b/src/modules/cdi/e1000/device.c @@ -36,7 +36,7 @@ #include "device.h" #include "e1000_io.h" -#define DEBUG +#undef DEBUG #define PHYS(netcard, field) \ ((uintptr_t) netcard->phys + offsetof(struct e1000_device, field)) @@ -293,6 +293,8 @@ static void e1000_handle_interrupt(struct cdi_device* device) } else if (icr & ICR_TRANSMIT) { // Nichts zu tun } else { +#ifdef DEBUG printf("e1000: Unerwarteter Interrupt.\n"); +#endif } } -- 1.5.6.5 From toni at tyndur.org Fri Aug 7 18:34:49 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 18:34:49 +0200 Subject: [tyndur-devel] [PATCH] e1000: Debugmeldungen ausschalten In-Reply-To: <1249646669-15421-1-git-send-email-kevin@tyndur.org> References: <1249646669-15421-1-git-send-email-kevin@tyndur.org> Message-ID: <20090807163449.GA19030@einstein.kaufmann.lan> On Fri, Aug 07 14:04, Kevin Wolf wrote: > * e1000: Eigentlich brauchen wir die Debugmeldungen im Moment nicht mehr > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Fri Aug 7 19:29:18 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 19:29:18 +0200 Subject: [tyndur-devel] [PATCH 0/2] Fixes fuer yasm Message-ID: <1249666160-20794-1-git-send-email-kevin@tyndur.org> Die folgenden beiden Patches sind noetig, um yasm unter tyndur zum Laufen zu bringen. Kevin Wolf (2): bsdtypes.h: LONG_BITS == 64 ist fuer i386 falsch libc: fgets-Rueckgabe enthaelt Zeilenumbruch src/include/bsdtypes.h | 6 ++++++ src/modules/c/shell/shell.c | 7 +++++++ src/modules/init/init.c | 6 ++++++ src/modules/lib/posix/socket.c | 6 ++++++ src/modules/lib/stdlibc/file.c | 7 +++++-- src/modules/servmgr/config.c | 10 ++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) From kevin at tyndur.org Fri Aug 7 19:29:19 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 19:29:19 +0200 Subject: [tyndur-devel] [PATCH 1/2] bsdtypes.h: LONG_BITS == 64 ist fuer i386 falsch In-Reply-To: <1249666160-20794-1-git-send-email-kevin@tyndur.org> References: <1249666160-20794-1-git-send-email-kevin@tyndur.org> Message-ID: <1249666160-20794-2-git-send-email-kevin@tyndur.org> ! bsdtypes.h: LONG_BITS je nach Architektur unterschiedlich setzen. Damit tut dann sogar strcspn wie erwartet. Signed-off-by: Kevin Wolf --- src/include/bsdtypes.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/include/bsdtypes.h b/src/include/bsdtypes.h index 7d7dc5a..fcfc141 100644 --- a/src/include/bsdtypes.h +++ b/src/include/bsdtypes.h @@ -30,6 +30,7 @@ #define _BSDTYPES_H_ #include +#include typedef unsigned char u_char; typedef unsigned int u_short; @@ -38,7 +39,12 @@ typedef unsigned long u_long; typedef void* caddr_t; +#if CONFIG_ARCH == ARCH_AMD64 #define LONG_BIT 64 +#else +#define LONG_BIT 32 +#endif + #define NBBY 8 #endif -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 19:29:20 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 19:29:20 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: fgets-Rueckgabe enthaelt Zeilenumbruch In-Reply-To: <1249666160-20794-1-git-send-email-kevin@tyndur.org> References: <1249666160-20794-1-git-send-email-kevin@tyndur.org> Message-ID: <1249666160-20794-3-git-send-email-kevin@tyndur.org> ! libc: Im von fgets() zurueckgegebenen String ist auch das abschliessende Leerzeichen enthalten. Signed-off-by: Kevin Wolf --- src/modules/c/shell/shell.c | 7 +++++++ src/modules/init/init.c | 6 ++++++ src/modules/lib/posix/socket.c | 6 ++++++ src/modules/lib/stdlibc/file.c | 7 +++++-- src/modules/servmgr/config.c | 10 ++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index cb5de50..66f91c6 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -307,6 +307,7 @@ int shell_do_cmd(void) bool shell_script(const char* path) { FILE* script = fopen(path, "r"); + size_t i; if (!script) { return FALSE; @@ -314,6 +315,12 @@ bool shell_script(const char* path) while (feof(script) == 0) { fgets(shell_command_buffer, COMMAND_BUFFER_SIZE, script); + + i = strlen(shell_command_buffer); + if ((i > 0) && (shell_command_buffer[i - 1] == '\n')) { + shell_command_buffer[i - 1] = '\0'; + } + shell_do_cmd(); } diff --git a/src/modules/init/init.c b/src/modules/init/init.c index 80e7af0..03d6b98 100644 --- a/src/modules/init/init.c +++ b/src/modules/init/init.c @@ -531,10 +531,16 @@ pid_t start_program(char* path, char* args, pid_t parent_pid) char* new_path; char* new_args; int ret; + size_t i; fgets(interpreter, 256, f); fclose(f); + i = strlen(interpreter); + if ((i > 0) && (interpreter[i - 1] == '\n')) { + interpreter[i - 1] = '\0'; + } + if (strlen(interpreter) < 2) { return FALSE; } diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c index f0b97e1..0616c2b 100644 --- a/src/modules/lib/posix/socket.c +++ b/src/modules/lib/posix/socket.c @@ -261,6 +261,7 @@ int accept(int sock, struct sockaddr* address, socklen_t* address_len) struct lostio_internal_file* conn; struct socket* socket = get_socket(sock); + size_t i; if (socket == NULL) { errno = EBADF; @@ -277,6 +278,11 @@ int accept(int sock, struct sockaddr* address, socklen_t* address_len) return -1; } + i = strlen(buf); + if ((i > 0) && (buf[i - 1] == '\n')) { + buf[i - 1] = '\0'; + } + clientsocket = calloc(1, sizeof(*clientsocket)); clientsocket->sa_family = AF_INET; clientsock = create_socket(socket); diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c index 7d5e1a8..3157247 100644 --- a/src/modules/lib/stdlibc/file.c +++ b/src/modules/lib/stdlibc/file.c @@ -362,12 +362,15 @@ char* fgets(char* dest, int length, FILE *io_res) break; } else if (c == EOF) { continue; - } else if (c == '\n') { - break; } *dest = (char) c; dest++; + + if (c == '\n') { + i++; + break; + } } *dest = '\0'; diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c index c722e41..b28ae8a 100644 --- a/src/modules/servmgr/config.c +++ b/src/modules/servmgr/config.c @@ -151,6 +151,11 @@ static void config_parse_deps(const char* path, // FIXME: Das koennte man noch etwas eleganter loesen ;-) while (fgets(buffer, sizeof(buffer), f)) { + size_t i = strlen(buffer); + if ((i > 0) && (buffer[i - 1] == '\n')) { + buffer[i - 1] = '\0'; + } + dep = config_service_get(buffer); if (dep == NULL) { printf("servmgr: Service %s haengt ab von %s; Dieser ist aber " @@ -184,6 +189,11 @@ static void config_parse_conf(const char* path, // FIXME: Das koennte man noch etwas eleganter loesen ;-) while (fgets(buffer, sizeof(buffer), f)) { + size_t i = strlen(buffer); + if ((i > 0) && (buffer[i - 1] == '\n')) { + buffer[i - 1] = '\0'; + } + if (!strcmp(buffer, "nowait")) { conf_serv->conf.wait = NOWAIT; } else if (!strcmp(buffer, "waitterminate")) { -- 1.5.6.5 From toni at tyndur.org Fri Aug 7 19:42:58 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 19:42:58 +0200 Subject: [tyndur-devel] [PATCH 1/2] bsdtypes.h: LONG_BITS == 64 ist fuer i386 falsch In-Reply-To: <1249666160-20794-2-git-send-email-kevin@tyndur.org> References: <1249666160-20794-1-git-send-email-kevin@tyndur.org> <1249666160-20794-2-git-send-email-kevin@tyndur.org> Message-ID: <20090807174258.GA23863@einstein.kaufmann.lan> On Fri, Aug 07 19:29, Kevin Wolf wrote: > ! bsdtypes.h: LONG_BITS je nach Architektur unterschiedlich setzen. Damit tut > dann sogar strcspn wie erwartet. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 7 19:45:14 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 19:45:14 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: fgets-Rueckgabe enthaelt Zeilenumbruch In-Reply-To: <1249666160-20794-3-git-send-email-kevin@tyndur.org> References: <1249666160-20794-1-git-send-email-kevin@tyndur.org> <1249666160-20794-3-git-send-email-kevin@tyndur.org> Message-ID: <20090807174513.GB23863@einstein.kaufmann.lan> On Fri, Aug 07 19:29, Kevin Wolf wrote: > ! libc: Im von fgets() zurueckgegebenen String ist auch das abschliessende > Leerzeichen enthalten. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 7 19:46:59 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 19:46:59 +0200 Subject: [tyndur-devel] [PATCH 1/3] tcpip: Kommandozeilenparameter fuer Default-IP In-Reply-To: <1249634843-11618-2-git-send-email-kevin@tyndur.org> References: <1249634843-11618-1-git-send-email-kevin@tyndur.org> <1249634843-11618-2-git-send-email-kevin@tyndur.org> Message-ID: <20090807174659.GC23863@einstein.kaufmann.lan> On Fri, Aug 07 10:47, Kevin Wolf wrote: > + tcpip: Kommandozeilenparameter ip=a.b.c.d fuer Default-IP. Die vom Treiber > uebergebene IP wird ab sofort ignoriert. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 7 19:48:20 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 19:48:20 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: IP-Adresse bei der Treiberregistrierung entfernt In-Reply-To: <1249634843-11618-3-git-send-email-kevin@tyndur.org> References: <1249634843-11618-1-git-send-email-kevin@tyndur.org> <1249634843-11618-3-git-send-email-kevin@tyndur.org> Message-ID: <20090807174819.GD23863@einstein.kaufmann.lan> On Fri, Aug 07 10:47, Kevin Wolf wrote: > - libc: Bei der Registrierung eines Netzwerktreibers wird die IP-Adresse des > Geraets nicht mehr uebertragen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 7 19:51:12 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 19:51:12 +0200 Subject: [tyndur-devel] [PATCH 3/3] cdi: ip-Kommandozeilenparameter in Netzwerktreibern entfernt In-Reply-To: <1249634843-11618-4-git-send-email-kevin@tyndur.org> References: <1249634843-11618-1-git-send-email-kevin@tyndur.org> <1249634843-11618-4-git-send-email-kevin@tyndur.org> Message-ID: <20090807175112.GE23863@einstein.kaufmann.lan> On Fri, Aug 07 10:47, Kevin Wolf wrote: > - cdi: ip-Kommandozeilenparameter in Netzwerktreibern entfernt > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 7 20:06:39 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 7 Aug 2009 20:06:39 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Syscall SYSCALL_MEM_INFO In-Reply-To: <1249594886-374-1-git-send-email-kevin@tyndur.org> References: <1249594886-374-1-git-send-email-kevin@tyndur.org> Message-ID: <20090807180639.GF23863@einstein.kaufmann.lan> On Thu, Aug 06 23:41, Kevin Wolf wrote: > + kernel2: Syscall SYSCALL_MEM_INFO > ! kernel2: pmm_count_pages() macht jetzt was sinnvolles anstatt eine > uninitialisierte Variable zurueckzugeben. > > Signed-off-by: Kevin Wolf > --- > src/kernel2/include/syscall.h | 4 ++++ > src/kernel2/src/arch/i386/syscall.c | 4 ++++ > src/kernel2/src/mm/phys.c | 9 +-------- > src/kernel2/src/syscall.c | 1 + > src/kernel2/src/syscalls/mem.c | 10 ++++++++++ > 5 files changed, 20 insertions(+), 8 deletions(-) > > diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h > index b7ebfc9..ea182c4 100644 > --- a/src/kernel2/include/syscall.h > +++ b/src/kernel2/include/syscall.h > @@ -84,6 +84,10 @@ vaddr_t syscall_mem_allocate_physical( > /// Einen Speicherblock freigeben > void syscall_mem_free(vaddr_t start, size_t bytes); > > +/// Freie Pages und Gesamtspeicher zurueckgeben > +void syscall_mem_info(uint32_t* sum_pages, uint32_t* free_pages); > + > + > // Prozessverwaltung > /// PID des aktuellen Prozesses abfragen > pid_t syscall_pm_get_pid(void); > diff --git a/src/kernel2/src/arch/i386/syscall.c b/src/kernel2/src/arch/i386/syscall.c > index 268d4e4..e8d71dc 100644 > --- a/src/kernel2/src/arch/i386/syscall.c > +++ b/src/kernel2/src/arch/i386/syscall.c > @@ -91,6 +91,10 @@ void syscall_arch(machine_state_t* isf) > > syscall_fastrpc_ret(); > > + } else if (handler == syscall_mem_info) { > + > + syscall_mem_info(&isf->eax, &isf->edx); > + > } else { > uint32_t eax, edx; > dword stack_backup; > diff --git a/src/kernel2/src/mm/phys.c b/src/kernel2/src/mm/phys.c > index 1d11478..e77bb3c 100644 > --- a/src/kernel2/src/mm/phys.c > +++ b/src/kernel2/src/mm/phys.c > @@ -65,13 +65,6 @@ static lock_t pmm_lock = 0; > static size_t pmm_bitmap_length; > > /** > - * Anzahl der nutzbaren Seiten. Entspricht pmm_bitmap_size * 32 abz?glich > - * der von der BIOS-Memory-Map als reserviert gekennzeichneten Bereiche. > - */ > -static size_t pmm_bitmap_usable_pages; > - > - > -/** > * Gibt die Startadresse der Bitmap zur?ck > */ > void* pmm_get_bitmap_start() > @@ -123,7 +116,7 @@ size_t pmm_count_free() > */ > size_t pmm_count_pages() > { > - return pmm_bitmap_usable_pages; > + return 8 * pmm_get_bitmap_size(); > } > > /** > diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c > index fcb9f66..4292724 100644 > --- a/src/kernel2/src/syscall.c > +++ b/src/kernel2/src/syscall.c > @@ -52,6 +52,7 @@ void syscall_init() > syscall_register(SYSCALL_MEM_ALLOCATE_PHYSICAL, > &syscall_mem_allocate_physical, 3); > syscall_register(SYSCALL_MEM_FREE, &syscall_mem_free, 2); > + syscall_register(SYSCALL_MEM_INFO, &syscall_mem_info, 0); Hm diese 0 da ist irgendwie etwas irreführend, auch wenn sie nichts kapuutmachen dürfte... Ich hätte da eher eine 2 vorgeschlagen. > > syscall_register(SYSCALL_PM_GET_PID, (void*) &syscall_pm_get_pid, 0); > syscall_register(SYSCALL_PM_GET_PARENT_PID, (void*) > diff --git a/src/kernel2/src/syscalls/mem.c b/src/kernel2/src/syscalls/mem.c > index ff66fa0..20f9e73 100644 > --- a/src/kernel2/src/syscalls/mem.c > +++ b/src/kernel2/src/syscalls/mem.c > @@ -130,3 +130,13 @@ void syscall_mem_free(vaddr_t start, size_t bytes) > start = (vaddr_t) ((uintptr_t) start + PAGE_SIZE); > } > } > + > +/** > + * Gibt zurueck, wie viele Byte Speicher dem System insgesamt zur Verfuegung > + * stehen und wie viele davon frei sind. > + */ > +void syscall_mem_info(uint32_t* sum_pages, uint32_t* free_pages) > +{ > + *sum_pages = pmm_count_pages() * PAGE_SIZE; > + *free_pages = pmm_count_free() * PAGE_SIZE; > +} Sonst sieht das gut aus. Acked-By: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From xanclic at googlemail.com Fri Aug 7 21:27:18 2009 From: xanclic at googlemail.com (Max Reitz) Date: Fri, 7 Aug 2009 21:27:18 +0200 Subject: [tyndur-devel] [PATCH] SSIZE32 bei PCnet Message-ID: <1249673238-25381-1-git-send-email-xanclic@googlemail.com> + SSIZE32-Bit setzen wäre sinnvoll --- src/modules/cdi/pcnet/pcnet.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/modules/cdi/pcnet/pcnet.c b/src/modules/cdi/pcnet/pcnet.c index 6e0ce51..a2fabbf 100644 --- a/src/modules/cdi/pcnet/pcnet.c +++ b/src/modules/cdi/pcnet/pcnet.c @@ -227,7 +227,7 @@ static void pcnet_reset(struct pcnet_device *netcard) cdi_sleep_ms(10); // Set software style to PCnet-PCI 32bit - pcnet_write_bcr(netcard, BCR_SOFTWARE_STYLE, 0x02); + pcnet_write_bcr(netcard, BCR_SOFTWARE_STYLE, 0x0102); DEBUG_MSG("Reset"); } -- 1.6.0.2 From kevin at tyndur.org Fri Aug 7 22:33:07 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 22:33:07 +0200 Subject: [tyndur-devel] [PATCH 0/4] build: Kernel bauen! Message-ID: <1249677191-13594-1-git-send-email-kevin@tyndur.org> Die folgenden Patches sind noetig, um unter tyndur einen neuen tyndur-Kernel bauen zu koennen. Ausserdem werden noch gefixte binutils benutzt, weil ar die benoetigte Bibliothek nicht zusammengepackt bekommt, aber wenn man das unter Linux macht, bootet der so kompilierte Kernel tatsaechlich. Kevin Wolf (4): build: Kernel ohne libc bauen build: yasm unterstuetzen build: -nc zum Ueberspringen der Kompilierung build: Unterstuetzung fuer Linkerskripts src/modules/c/build/build.c | 47 +++++++++++++++++++++++++--------- src/modules/c/build/dir.c | 7 +++++ src/modules/c/build/include/build.h | 4 +++ src/modules/c/build/main.c | 11 +++++++- 4 files changed, 55 insertions(+), 14 deletions(-) From kevin at tyndur.org Fri Aug 7 22:33:08 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 22:33:08 +0200 Subject: [tyndur-devel] [PATCH 1/4] build: Kernel ohne libc bauen In-Reply-To: <1249677191-13594-1-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> Message-ID: <1249677191-13594-2-git-send-email-kevin@tyndur.org> + build: Mit -k kann man -nostdinc und -nostdlib aktivieren Signed-off-by: Kevin Wolf --- src/modules/c/build/build.c | 16 ++++++++++++++-- src/modules/c/build/include/build.h | 2 ++ src/modules/c/build/main.c | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/modules/c/build/build.c b/src/modules/c/build/build.c index ace3260..3319508 100644 --- a/src/modules/c/build/build.c +++ b/src/modules/c/build/build.c @@ -54,6 +54,9 @@ static const char* fpcflags = "-n -Cn -CX -Tlost"; static const char* nasmflags = "-felf -O99"; static const char* gasflags = "-m32 -c"; +static const char* c_compiler = "gcc"; +static const char* linker = "gcc"; + static char* root_path; /** @@ -227,7 +230,7 @@ static void do_build(struct build_dir* dir, const char* parent_include, // TODO Pruefen, ob sich Abhaengigkeiten veraendert haben printf("%s: Kompilieren (C)...", dir->path); fflush(stdout); - compile(dir->path, dir->src_files[LANG_C], "gcc", cflags, include); + compile(dir->path, dir->src_files[LANG_C], c_compiler, cflags, include); printf("\r%s: Kompilieren (Pascal)...\033[K", dir->path); fflush(stdout); @@ -247,7 +250,11 @@ static void do_build(struct build_dir* dir, const char* parent_include, fflush(stdout); objs = get_obj_files(dir->path); - do_command(".", "gcc", "-o %s/run %s %s", dir->path, lib, objs); + if (!standalone) { + do_command(".", linker, "-o %s/run %s %s", dir->path, lib, objs); + } else { + do_command(".", linker, "-o %s/run --start-group %s %s --end-group", dir->path, lib, objs); + } free(objs); } @@ -262,9 +269,14 @@ static void do_build(struct build_dir* dir, const char* parent_include, * Bauen! * * @param root Wurzelverzeichnis des Projekts + * @param standalone Wenn != 0, wird die Standardbibliothek nicht benutzt */ void build(struct build_dir* root) { + if (standalone) { + c_compiler = "gcc -nostdinc"; + linker = "ld"; + } root_path = getcwd(NULL, 0); do_build(root, "", "", 0); printf("Fertig gebaut.\n"); diff --git a/src/modules/c/build/include/build.h b/src/modules/c/build/include/build.h index c7ee608..b1d7659 100644 --- a/src/modules/c/build/include/build.h +++ b/src/modules/c/build/include/build.h @@ -76,5 +76,7 @@ void build(struct build_dir* root); extern int dry_run; extern int verbose; +extern int dont_compile; +extern int standalone; #endif diff --git a/src/modules/c/build/main.c b/src/modules/c/build/main.c index d531db7..46f196f 100644 --- a/src/modules/c/build/main.c +++ b/src/modules/c/build/main.c @@ -72,9 +72,12 @@ int verbose = 0; int dry_run= 0; +/// Keine Standardbibliotheken einbinden +int standalone = 0; + static void usage(char* binary) { - fprintf(stderr, "Aufruf: %s [-v] [--dry-run] []\n", + fprintf(stderr, "Aufruf: %s [-k] [-v] [--dry-run] []\n", binary); exit(1); } @@ -96,6 +99,8 @@ int main(int argc, char** argv) verbose = 1; } else if (!strcmp(argv[i], "--dry-run")) { dry_run = 1; + } else if (!strcmp(argv[i], "-k")) { + standalone = 1; } else if (argv[i][0] == '-') { usage(argv[0]); } else if (rootdir_path) { -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 22:33:09 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 22:33:09 +0200 Subject: [tyndur-devel] [PATCH 2/4] build: yasm unterstuetzen In-Reply-To: <1249677191-13594-1-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> Message-ID: <1249677191-13594-3-git-send-email-kevin@tyndur.org> * build: yasm funktioniert jetzt, nasm nicht. Also den benutzten Assembler aendern. Signed-off-by: Kevin Wolf --- src/modules/c/build/build.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/c/build/build.c b/src/modules/c/build/build.c index 3319508..ecf8fc4 100644 --- a/src/modules/c/build/build.c +++ b/src/modules/c/build/build.c @@ -51,7 +51,7 @@ static const char* cflags = "-c"; #endif static const char* fpcflags = "-n -Cn -CX -Tlost"; -static const char* nasmflags = "-felf -O99"; +static const char* nasmflags = "-felf"; static const char* gasflags = "-m32 -c"; static const char* c_compiler = "gcc"; @@ -240,8 +240,10 @@ static void do_build(struct build_dir* dir, const char* parent_include, fflush(stdout); compile(dir->path, dir->src_files[LANG_ASM_GAS], "gcc", gasflags, include); + printf("\r%s: Assemblieren (yasm)...\033[K", dir->path); + fflush(stdout); for (i = 0; (file = list_get_element_at(dir->src_files[LANG_ASM_NASM], i)); i++) { - do_command(dir->path, "nasm", "%s %s", nasmflags, file->name); + do_command(dir->path, "yasm", "%s %s", nasmflags, file->name); } // Im Wurzelverzeichnis wird gelinkt (TODO einstellbar machen) -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 22:33:10 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 22:33:10 +0200 Subject: [tyndur-devel] [PATCH 3/4] build: -nc zum Ueberspringen der Kompilierung In-Reply-To: <1249677191-13594-1-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> Message-ID: <1249677191-13594-4-git-send-email-kevin@tyndur.org> + build: Mit -nc kann die Kompilierung uebersprungen werden, wenn die Objektdateien schon vorhanden sind und nur noch Bibliotheken erstellt bzw. Objektdateien gelinkt werden muessen. Signed-off-by: Kevin Wolf --- src/modules/c/build/build.c | 28 +++++++++++++++------------- src/modules/c/build/main.c | 6 +++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/modules/c/build/build.c b/src/modules/c/build/build.c index ecf8fc4..683428b 100644 --- a/src/modules/c/build/build.c +++ b/src/modules/c/build/build.c @@ -228,22 +228,24 @@ static void do_build(struct build_dir* dir, const char* parent_include, // Und schliesslich noch die einzelnen Dateien // TODO Pruefen, ob sich Abhaengigkeiten veraendert haben - printf("%s: Kompilieren (C)...", dir->path); - fflush(stdout); - compile(dir->path, dir->src_files[LANG_C], c_compiler, cflags, include); + if (!dont_compile) { + printf("%s: Kompilieren (C)...", dir->path); + fflush(stdout); + compile(dir->path, dir->src_files[LANG_C], c_compiler, cflags, include); - printf("\r%s: Kompilieren (Pascal)...\033[K", dir->path); - fflush(stdout); - compile(dir->path, dir->src_files[LANG_PAS], "fpc", fpcflags, include); + printf("\r%s: Kompilieren (Pascal)...\033[K", dir->path); + fflush(stdout); + compile(dir->path, dir->src_files[LANG_PAS], "fpc", fpcflags, include); - printf("\r%s: Assemblieren (gas)...\033[K", dir->path); - fflush(stdout); - compile(dir->path, dir->src_files[LANG_ASM_GAS], "gcc", gasflags, include); + printf("\r%s: Assemblieren (gas)...\033[K", dir->path); + fflush(stdout); + compile(dir->path, dir->src_files[LANG_ASM_GAS], "gcc", gasflags, include); - printf("\r%s: Assemblieren (yasm)...\033[K", dir->path); - fflush(stdout); - for (i = 0; (file = list_get_element_at(dir->src_files[LANG_ASM_NASM], i)); i++) { - do_command(dir->path, "yasm", "%s %s", nasmflags, file->name); + printf("\r%s: Assemblieren (yasm)...\033[K", dir->path); + fflush(stdout); + for (i = 0; (file = list_get_element_at(dir->src_files[LANG_ASM_NASM], i)); i++) { + do_command(dir->path, "yasm", "%s %s", nasmflags, file->name); + } } // Im Wurzelverzeichnis wird gelinkt (TODO einstellbar machen) diff --git a/src/modules/c/build/main.c b/src/modules/c/build/main.c index 46f196f..8997abe 100644 --- a/src/modules/c/build/main.c +++ b/src/modules/c/build/main.c @@ -71,13 +71,15 @@ int verbose = 0; /// Nur Meldungen ausgeben, aber nichts wirklich aufrufen int dry_run= 0; +/// Nur Bibliotheken sammeln und linken +int dont_compile= 0; /// Keine Standardbibliotheken einbinden int standalone = 0; static void usage(char* binary) { - fprintf(stderr, "Aufruf: %s [-k] [-v] [--dry-run] []\n", + fprintf(stderr, "Aufruf: %s [-k] [-nc] [-v] [--dry-run] []\n", binary); exit(1); } @@ -101,6 +103,8 @@ int main(int argc, char** argv) dry_run = 1; } else if (!strcmp(argv[i], "-k")) { standalone = 1; + } else if (!strcmp(argv[i], "-nc")) { + dont_compile = 1; } else if (argv[i][0] == '-') { usage(argv[0]); } else if (rootdir_path) { -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 22:33:11 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 22:33:11 +0200 Subject: [tyndur-devel] [PATCH 4/4] build: Unterstuetzung fuer Linkerskripts In-Reply-To: <1249677191-13594-1-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> Message-ID: <1249677191-13594-5-git-send-email-kevin@tyndur.org> + build: Wenn im Verzeichnis, in dem die Binary gebaut werden soll, eine *.ld-Datei vorhanden ist, wird sie als Linkerskript benutzt. Signed-off-by: Kevin Wolf --- src/modules/c/build/build.c | 7 ++++++- src/modules/c/build/dir.c | 7 +++++++ src/modules/c/build/include/build.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletions(-) diff --git a/src/modules/c/build/build.c b/src/modules/c/build/build.c index 683428b..4c899c8 100644 --- a/src/modules/c/build/build.c +++ b/src/modules/c/build/build.c @@ -257,7 +257,12 @@ static void do_build(struct build_dir* dir, const char* parent_include, if (!standalone) { do_command(".", linker, "-o %s/run %s %s", dir->path, lib, objs); } else { - do_command(".", linker, "-o %s/run --start-group %s %s --end-group", dir->path, lib, objs); + do_command(".", linker, "-o %s/run %s%s " + "--start-group %s %s --end-group", + dir->path, + dir->ldscript ? "-T" : "", + dir->ldscript ? dir->ldscript : "", + lib, objs); } free(objs); } diff --git a/src/modules/c/build/dir.c b/src/modules/c/build/dir.c index 39b3ac6..b77c467 100644 --- a/src/modules/c/build/dir.c +++ b/src/modules/c/build/dir.c @@ -109,6 +109,8 @@ struct build_dir* scan_directory(struct build_dir* parent, const char* path) filetype = OTHER_FILE; } else if (!strcmp(suffix, ".o")) { filetype = OBJ; + } else if (!strcmp(suffix, ".ld")) { + filetype = LD_SCRIPT; } else if (!strcmp(suffix, ".c")) { filetype = LANG_C; } else if (!strcmp(suffix, ".pas")) { @@ -174,6 +176,11 @@ struct build_dir* scan_directory(struct build_dir* parent, const char* path) } } break; + case LD_SCRIPT: + // Ein Linkerskript pro Verzeichnis + build_dir->ldscript = file->name; + free(file); + break; case OBJ: // Objektdateien haben ihre eigene Liste list_push(build_dir->obj_files, file); diff --git a/src/modules/c/build/include/build.h b/src/modules/c/build/include/build.h index b1d7659..3efced2 100644 --- a/src/modules/c/build/include/build.h +++ b/src/modules/c/build/include/build.h @@ -46,6 +46,7 @@ enum filetype { #define MAX_LANG OTHER_FILE OTHER_FILE, + LD_SCRIPT, SUBDIR, OBJ, }; @@ -58,6 +59,7 @@ struct build_dir { int has_include; int has_arch_include; char* path; + char* ldscript; struct build_dir* parent; struct build_dir* lib; list_t* src_files[MAX_LANG]; -- 1.5.6.5 From kevin at tyndur.org Fri Aug 7 23:54:35 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 7 Aug 2009 23:54:35 +0200 Subject: [tyndur-devel] [PATCH] kernel: Multibootheader per Linkerskript platzieren Message-ID: <1249682075-30816-1-git-send-email-kevin@tyndur.org> * kernel: Wenn man den Multibootheader per Link platziert anstatt zufällig über die Reihenfolge der ld-Parameter, kommt auch build damit zurecht Signed-off-by: Kevin Wolf --- src/kernel/src/Makefile.all | 2 +- src/kernel/src/header.asm | 1 + src/kernel/src/kernel.ld | 1 + 3 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/kernel/src/Makefile.all b/src/kernel/src/Makefile.all index 3cab74e..bf92739 100644 --- a/src/kernel/src/Makefile.all +++ b/src/kernel/src/Makefile.all @@ -2,5 +2,5 @@ shopt -s extglob source $LOST_BUILDMK_ROOT/config.sh echo "LD $1/kernel/tyndur" -$LOST_TOOLS_LD -otyndur.krn -Tkernel.ld header.o !(header).o $2 +$LOST_TOOLS_LD -otyndur.krn -Tkernel.ld *.o $2 mv tyndur.krn $1/kernel/tyndur diff --git a/src/kernel/src/header.asm b/src/kernel/src/header.asm index 760e0c1..a3a8d2d 100644 --- a/src/kernel/src/header.asm +++ b/src/kernel/src/header.asm @@ -74,6 +74,7 @@ _start: cli hlt +section multiboot multiboot_header: align 4 MULTIBOOT_MAGIC equ 0x1BADB002 diff --git a/src/kernel/src/kernel.ld b/src/kernel/src/kernel.ld index 0cb7936..9efbcb0 100644 --- a/src/kernel/src/kernel.ld +++ b/src/kernel/src/kernel.ld @@ -12,6 +12,7 @@ SECTIONS .text : AT(ADDR(.text) - VIRT_TO_PHYS) { + *(multiboot) *(.text) } .rodata ALIGN(4096) : AT(ADDR(.rodata) - VIRT_TO_PHYS) -- 1.5.6.5 From toni at tyndur.org Sat Aug 8 00:29:48 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 00:29:48 +0200 Subject: [tyndur-devel] [PATCH] kernel: Multibootheader per Linkerskript platzieren In-Reply-To: <1249682075-30816-1-git-send-email-kevin@tyndur.org> References: <1249682075-30816-1-git-send-email-kevin@tyndur.org> Message-ID: <20090807222948.GA2976@einstein.kaufmann.lan> On Fri, Aug 07 23:54, Kevin Wolf wrote: > * kernel: Wenn man den Multibootheader per Link platziert anstatt zufällig über > die Reihenfolge der ld-Parameter, kommt auch build damit zurecht > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 00:34:00 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 00:34:00 +0200 Subject: [tyndur-devel] [PATCH 1/4] build: Kernel ohne libc bauen In-Reply-To: <1249677191-13594-2-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> <1249677191-13594-2-git-send-email-kevin@tyndur.org> Message-ID: <20090807223400.GB2976@einstein.kaufmann.lan> On Fri, Aug 07 22:33, Kevin Wolf wrote: > + build: Mit -k kann man -nostdinc und -nostdlib aktivieren > > Signed-off-by: Kevin Wolf > --- > src/modules/c/build/build.c | 16 ++++++++++++++-- > src/modules/c/build/include/build.h | 2 ++ > src/modules/c/build/main.c | 7 ++++++- > 3 files changed, 22 insertions(+), 3 deletions(-) > > diff --git a/src/modules/c/build/build.c b/src/modules/c/build/build.c > index ace3260..3319508 100644 > --- a/src/modules/c/build/build.c > +++ b/src/modules/c/build/build.c > @@ -54,6 +54,9 @@ static const char* fpcflags = "-n -Cn -CX -Tlost"; > static const char* nasmflags = "-felf -O99"; > static const char* gasflags = "-m32 -c"; > > +static const char* c_compiler = "gcc"; > +static const char* linker = "gcc"; > + > static char* root_path; > > /** > @@ -227,7 +230,7 @@ static void do_build(struct build_dir* dir, const char* parent_include, > // TODO Pruefen, ob sich Abhaengigkeiten veraendert haben > printf("%s: Kompilieren (C)...", dir->path); > fflush(stdout); > - compile(dir->path, dir->src_files[LANG_C], "gcc", cflags, include); > + compile(dir->path, dir->src_files[LANG_C], c_compiler, cflags, include); > > printf("\r%s: Kompilieren (Pascal)...\033[K", dir->path); > fflush(stdout); > @@ -247,7 +250,11 @@ static void do_build(struct build_dir* dir, const char* parent_include, > fflush(stdout); > > objs = get_obj_files(dir->path); > - do_command(".", "gcc", "-o %s/run %s %s", dir->path, lib, objs); > + if (!standalone) { > + do_command(".", linker, "-o %s/run %s %s", dir->path, lib, objs); > + } else { > + do_command(".", linker, "-o %s/run --start-group %s %s --end-group", dir->path, lib, objs); > + } > free(objs); > } > > @@ -262,9 +269,14 @@ static void do_build(struct build_dir* dir, const char* parent_include, > * Bauen! > * > * @param root Wurzelverzeichnis des Projekts > + * @param standalone Wenn != 0, wird die Standardbibliothek nicht benutzt > */ > void build(struct build_dir* root) > { > + if (standalone) { > + c_compiler = "gcc -nostdinc"; > + linker = "ld"; > + } > root_path = getcwd(NULL, 0); > do_build(root, "", "", 0); > printf("Fertig gebaut.\n"); > diff --git a/src/modules/c/build/include/build.h b/src/modules/c/build/include/build.h > index c7ee608..b1d7659 100644 > --- a/src/modules/c/build/include/build.h > +++ b/src/modules/c/build/include/build.h > @@ -76,5 +76,7 @@ void build(struct build_dir* root); > > extern int dry_run; > extern int verbose; > +extern int dont_compile; Weg damit. > +extern int standalone; > > #endif > diff --git a/src/modules/c/build/main.c b/src/modules/c/build/main.c > index d531db7..46f196f 100644 > --- a/src/modules/c/build/main.c > +++ b/src/modules/c/build/main.c > @@ -72,9 +72,12 @@ int verbose = 0; > int dry_run= 0; > > > +/// Keine Standardbibliotheken einbinden > +int standalone = 0; > + > static void usage(char* binary) > { > - fprintf(stderr, "Aufruf: %s [-v] [--dry-run] []\n", > + fprintf(stderr, "Aufruf: %s [-k] [-v] [--dry-run] []\n", > binary); > exit(1); > } > @@ -96,6 +99,8 @@ int main(int argc, char** argv) > verbose = 1; > } else if (!strcmp(argv[i], "--dry-run")) { > dry_run = 1; > + } else if (!strcmp(argv[i], "-k")) { > + standalone = 1; > } else if (argv[i][0] == '-') { > usage(argv[0]); > } else if (rootdir_path) { Wenn du das noch fixt, dann: Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 00:35:24 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 00:35:24 +0200 Subject: [tyndur-devel] [PATCH 2/4] build: yasm unterstuetzen In-Reply-To: <1249677191-13594-3-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> <1249677191-13594-3-git-send-email-kevin@tyndur.org> Message-ID: <20090807223524.GC2976@einstein.kaufmann.lan> On Fri, Aug 07 22:33, Kevin Wolf wrote: > * build: yasm funktioniert jetzt, nasm nicht. Also den benutzten Assembler > aendern. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 00:38:25 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 00:38:25 +0200 Subject: [tyndur-devel] [PATCH 4/4] build: Unterstuetzung fuer Linkerskripts In-Reply-To: <1249677191-13594-5-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> <1249677191-13594-5-git-send-email-kevin@tyndur.org> Message-ID: <20090807223825.GD2976@einstein.kaufmann.lan> On Fri, Aug 07 22:33, Kevin Wolf wrote: > + build: Wenn im Verzeichnis, in dem die Binary gebaut werden soll, eine > *.ld-Datei vorhanden ist, wird sie als Linkerskript benutzt. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 00:44:06 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 00:44:06 +0200 Subject: [tyndur-devel] [PATCH 3/4] build: -nc zum Ueberspringen der Kompilierung In-Reply-To: <1249677191-13594-4-git-send-email-kevin@tyndur.org> References: <1249677191-13594-1-git-send-email-kevin@tyndur.org> <1249677191-13594-4-git-send-email-kevin@tyndur.org> Message-ID: <20090807224406.GE2976@einstein.kaufmann.lan> On Fri, Aug 07 22:33, Kevin Wolf wrote: > + build: Mit -nc kann die Kompilierung uebersprungen werden, wenn die > Objektdateien schon vorhanden sind und nur noch Bibliotheken erstellt bzw. > Objektdateien gelinkt werden muessen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Aug 8 10:11:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 10:11:23 +0200 Subject: [tyndur-devel] [PATCH] SSIZE32 bei PCnet In-Reply-To: <1249673238-25381-1-git-send-email-xanclic@googlemail.com> References: <1249673238-25381-1-git-send-email-xanclic@googlemail.com> Message-ID: <20090808080703.GA4812@debws.produktiv.lan> On Fri, Aug 07, 2009 at 09:27:18PM +0200, Max Reitz wrote: > + SSIZE32-Bit setzen wäre sinnvoll Das braucht noch ein Signed-off-by (einfach die eine Zeile als Antwort auf diese Mail reicht). Scheint ansonsten in qemu so zu laufen wie bisher, dürfte also nicht falsch sein. Keine Ahnung, mit realer Hardware müßte man noch testen. > > --- > src/modules/cdi/pcnet/pcnet.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/src/modules/cdi/pcnet/pcnet.c b/src/modules/cdi/pcnet/pcnet.c > index 6e0ce51..a2fabbf 100644 > --- a/src/modules/cdi/pcnet/pcnet.c > +++ b/src/modules/cdi/pcnet/pcnet.c > @@ -227,7 +227,7 @@ static void pcnet_reset(struct pcnet_device *netcard) > cdi_sleep_ms(10); > > // Set software style to PCnet-PCI 32bit > - pcnet_write_bcr(netcard, BCR_SOFTWARE_STYLE, 0x02); > + pcnet_write_bcr(netcard, BCR_SOFTWARE_STYLE, 0x0102); > > DEBUG_MSG("Reset"); > } > -- > 1.6.0.2 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From xanclic at googlemail.com Sat Aug 8 10:34:34 2009 From: xanclic at googlemail.com (Max Reitz) Date: Sat, 08 Aug 2009 10:34:34 +0200 Subject: [tyndur-devel] [PATCH] SSIZE32 bei PCnet In-Reply-To: <20090808080703.GA4812@debws.produktiv.lan> References: <1249673238-25381-1-git-send-email-xanclic@googlemail.com> <20090808080703.GA4812@debws.produktiv.lan> Message-ID: <4A7D389A.4090805@googlemail.com> Signed-off-by: Max Reitz From patrick at tyndur.org Sat Aug 8 14:38:00 2009 From: patrick at tyndur.org (Patrick Kaufmann) Date: Sat, 8 Aug 2009 14:38:00 +0200 Subject: [tyndur-devel] [PATCH] Libc: Erstes Stueck richtige libm Message-ID: <1249735080-6870-1-git-send-email-patrick@tyndur.org> From: patrick + Libc: Erstes Stueck richtige libm Signed-off-by: Patrick Kaufmann --- src/modules/include/math.h | 74 ++++++++++++---- src/modules/lib/stdlibc/math.c | 45 ---------- src/modules/lib/stdlibc/math/fabs.c | 64 ++++++++++++++ src/modules/lib/stdlibc/math/fcos.c | 85 ++++++++++++++++++ src/modules/lib/stdlibc/math/fexp.c | 58 ++++++++++++ src/modules/lib/stdlibc/math/fldexp.c | 112 ++++++++++++++++++++++++ src/modules/lib/stdlibc/math/flog.c | 154 +++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/math/fsin.c | 83 ++++++++++++++++++ src/modules/lib/stdlibc/math/fsqrt.c | 64 ++++++++++++++ src/modules/lib/stdlibc/math/ftan.c | 143 ++++++++++++++++++++++++++++++ 10 files changed, 820 insertions(+), 62 deletions(-) delete mode 100644 src/modules/lib/stdlibc/math.c create mode 100644 src/modules/lib/stdlibc/math/fabs.c create mode 100644 src/modules/lib/stdlibc/math/fcos.c create mode 100644 src/modules/lib/stdlibc/math/fexp.c create mode 100644 src/modules/lib/stdlibc/math/fldexp.c create mode 100644 src/modules/lib/stdlibc/math/flog.c create mode 100644 src/modules/lib/stdlibc/math/fsin.c create mode 100644 src/modules/lib/stdlibc/math/fsqrt.c create mode 100644 src/modules/lib/stdlibc/math/ftan.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 8be2d9c..a5d39b4 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -1,8 +1,8 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Patrick Kaufmann. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,26 +13,66 @@ * 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 + * 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 + * 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 _MATH_H_ #define _MATH_H_ -#include -// Betrag einer reelen Zahl errechen -#ifndef CONFIG_LIBC_NO_STUBS -double fabs(double x); -#endif +# define NAN (__builtin_nanf ("")) + +double tan(double); +float tanf(float); +long double tanl(long double); +double sqrt(double); +float sqrtf(float); +long double sqrtl(long double); +double sin(double); +float sinf(float); +long double sinl(long double); +double log2(double); +float log2f(float); +long double log2l(long double); +double log10(double); +float log10f(float); +long double log10l(long double); +double log(double); +float logf(float); +long double logl(long double); +double ldexp(double, int); +float ldexpf(float, int); +long double ldexpl(long double, int); +double fabs(double); +float fabsf(float); +long double fabsl(long double); +double exp(double); +float expf(float); +long double expl(long double); +double cos(double); +float cosf(float); +long double cosl(long double); +double atan(double); +float atanf(float); +long double atanl(long double); +double atan2(double, double); +float atan2f(float, float); +long double atan2l(long double, long double); +double asin(double); +float asinf(float); +long double asinl(long double); +double acos(double); +float acosf(float); +long double acosl(long double); #endif + diff --git a/src/modules/lib/stdlibc/math.c b/src/modules/lib/stdlibc/math.c deleted file mode 100644 index 76d437f..0000000 --- a/src/modules/lib/stdlibc/math.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2007 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. - */ - -#include -#include -#include - -// FIXME: Nur bis der Float-Kram vom Kernel unterstuetzt wird -#ifndef CONFIG_LIBC_NO_STUBS - -/** - * Betrag einer reellen Zahl errechnen - */ -double fabs(double x) -{ - return ((x < 0) ? -x : x); -} - -#endif - diff --git a/src/modules/lib/stdlibc/math/fabs.c b/src/modules/lib/stdlibc/math/fabs.c new file mode 100644 index 0000000..06a9098 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fabs.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double fabs(double x) +{ + double res; + if (x < 0.0) { + return -x; + } + else { + return res; + } +} + +float fabsf(float x) +{ + float res; + if (x < 0.0) { + return -x; + } + else { + return res; + } +} + +long double fabsl(long double x) +{ + long double res; + if (x < 0.0) { + return -x; + } + else { + return res; + } +} + diff --git a/src/modules/lib/stdlibc/math/fcos.c b/src/modules/lib/stdlibc/math/fcos.c new file mode 100644 index 0000000..06d2d7d --- /dev/null +++ b/src/modules/lib/stdlibc/math/fcos.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pio2 1.570796326794896619 + +double cos(double x) +{ + double res; + asm("fcos;" : "=t" (res) : "0" (x)); + return res; +} + +float cosf(float x) +{ + float res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +long double cosl(long double x) +{ + long double res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +double acos(double x) { + double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +float acosf(float x) { + float res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +long double acosl(long double x) { + long double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fexp.c b/src/modules/lib/stdlibc/math/fexp.c new file mode 100644 index 0000000..fbc48f5 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fexp.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double exp(double x) +{ + double one = 1; + double res; + asm("fyl2x;" + "f2xm1": "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float expf(float x) +{ + float one = 1; + float res; + asm("fyl2x;" + "f2xm1": "=t" (res) : "0" (x), "u" (one)); + return res; +} + +long double expl(long double x) +{ + long double one = 1; + long double res; + asm("fyl2x;" + "f2xm1" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fldexp.c b/src/modules/lib/stdlibc/math/fldexp.c new file mode 100644 index 0000000..83dd8da --- /dev/null +++ b/src/modules/lib/stdlibc/math/fldexp.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double ldexp(double x, int exp) +{ + double res = x; + int exponent; + int i; + if (!exp) { + if (!x) { + errno = EDOM; + return NAN; + } + return 1; + } + exponent = exp; + if (exp < 0) { + exponent = -exp; + } + for (i = 1; i < exponent; i++) { + res *= x; + } + + if (exp < 0) { + return 1 / res; + } + + return res; +} + +float ldexpf(float x, int exp) +{ + float res = x; + int exponent; + int i; + if (!exp) { + if (!x) { + errno = EDOM; + return NAN; + } + return 1; + } + exponent = exp; + if (exp < 0) { + exponent = -exp; + } + for (i = 1; i < exponent; i++) { + res *= x; + } + + if (exp < 0) { + return 1 / res; + } + + return res; +} + +long double ldexpl(long double x, int exp) +{ + long double res = x; + int exponent; + int i; + if (!exp) { + if (!x) { + errno = EDOM; + return NAN; + } + return 1; + } + exponent = exp; + if (exp < 0) { + exponent = -exp; + } + for (i = 1; i < exponent; i++) { + res *= x; + } + + if (exp < 0) { + return 1 / res; + } + + return res; +} + diff --git a/src/modules/lib/stdlibc/math/flog.c b/src/modules/lib/stdlibc/math/flog.c new file mode 100644 index 0000000..ca5c457 --- /dev/null +++ b/src/modules/lib/stdlibc/math/flog.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double log2(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); +} + +float log2f(float x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); +} + + +long double log2l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); +} + +double log(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float logf(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +long double logl(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + + +double log10(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +float log10f(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +long double log10l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + diff --git a/src/modules/lib/stdlibc/math/fsin.c b/src/modules/lib/stdlibc/math/fsin.c new file mode 100644 index 0000000..9748def --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsin.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double sin(double x) +{ + double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +float sinf(float x) +{ + float res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +long double sinl(long double x) +{ + long double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +double asin(double x) { + double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + +float asinf(float x) { + float res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + +long double asinl(long double x) { + long double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fsqrt.c b/src/modules/lib/stdlibc/math/fsqrt.c new file mode 100644 index 0000000..1d9ac72 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsqrt.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +long double sqrtl(long double x) +{ + long double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + +double sqrt(double x) +{ + double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=l" (res) : "0" (x)); + return res; +} + +float sqrtf(float x) +{ + float res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c new file mode 100644 index 0000000..de2f2ba --- /dev/null +++ b/src/modules/lib/stdlibc/math/ftan.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pi 3.1415926535897932384 +#define pio2 1.570796326794896619 + +static short sgn(double x) { + short res; + if (x < 0) { + res = -1; + } else if (x == 0) { + res = 0; + } else { + res = 1; + } + return res; +} + + +double tan(double x) +{ + double res; + asm("fptan" : "=t" (res) : "0" (x)); + return res; +} + +float tanf(float x) +{ + float res; + asm("fptan" : "=t" (res) : "0" (x)); + return res; +} + +long double tanl(long double x) +{ + long double res; + asm("fptan" : "=t" (res) : "0" (x)); + return res; +} + +double atan(double x) +{ + + double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +float atanf(float x) +{ + float res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + + +long double atanl(long double x) +{ + long double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +double atan2(double x, double y) { + double res; + if (x < 0) { + res = (pi - atan(y / x)) * sgn(y); + return res; + } else if (x == 0) { + if (y == 0) { + errno = EDOM; + return NAN; + } + res = pio2 * sgn(y); + return res; + } + res = atan(y / x) * sgn(y); + return res; +} + + +float atan2f(float x, float y) { + float res; + if (x < 0) { + res = (pi - atan(y / x)) * (float)sgn((double)y); + return res; + } else if (x == 0) { + if (y == 0) { + errno = EDOM; + return NAN; + } + res = pio2 * (float)sgn((double)y); + return res; + } + res = atan(y / x) * (float)sgn((double)y); + return res; +} + +long double atan2l(long double x, long double y) { + long double res; + if (x < 0) { + res = (pi - atan(y / x)) * (long double)sgn((double)y); + return res; + } else if (x == 0) { + if (y == 0) { + errno = EDOM; + return NAN; + } + res = pio2 * (long double)sgn((double)y); + return res; + } + res = atan(y / x) * (long double)sgn((double)y); + return res; +} + -- 1.6.3.3 From patrick at tyndur.org Sat Aug 8 15:00:47 2009 From: patrick at tyndur.org (Patrick Kaufmann) Date: Sat, 8 Aug 2009 15:00:47 +0200 Subject: [tyndur-devel] [PATCH] Libc: Erstes Stueck richtige libm In-Reply-To: <1249735080-6870-1-git-send-email-patrick@tyndur.org> References: <1249735080-6870-1-git-send-email-patrick@tyndur.org> Message-ID: <1249736447-2109-1-git-send-email-patrick@tyndur.org> From: patrick + Libc: Erstes Stueck richtige libm Signed-off-by: Patrick Kaufmann --- src/modules/include/math.h | 74 ++++++++++++---- src/modules/lib/stdlibc/math.c | 45 ---------- src/modules/lib/stdlibc/math/fabs.c | 67 ++++++++++++++ src/modules/lib/stdlibc/math/fcos.c | 85 ++++++++++++++++++ src/modules/lib/stdlibc/math/fexp.c | 58 ++++++++++++ src/modules/lib/stdlibc/math/fldexp.c | 112 +++++++++++++++++++++++ src/modules/lib/stdlibc/math/flog.c | 157 +++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/math/fsin.c | 83 +++++++++++++++++ src/modules/lib/stdlibc/math/fsqrt.c | 64 +++++++++++++ src/modules/lib/stdlibc/math/ftan.c | 143 ++++++++++++++++++++++++++++++ 10 files changed, 826 insertions(+), 62 deletions(-) delete mode 100644 src/modules/lib/stdlibc/math.c create mode 100644 src/modules/lib/stdlibc/math/fabs.c create mode 100644 src/modules/lib/stdlibc/math/fcos.c create mode 100644 src/modules/lib/stdlibc/math/fexp.c create mode 100644 src/modules/lib/stdlibc/math/fldexp.c create mode 100644 src/modules/lib/stdlibc/math/flog.c create mode 100644 src/modules/lib/stdlibc/math/fsin.c create mode 100644 src/modules/lib/stdlibc/math/fsqrt.c create mode 100644 src/modules/lib/stdlibc/math/ftan.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 8be2d9c..a5d39b4 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -1,8 +1,8 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Patrick Kaufmann. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,26 +13,66 @@ * 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 + * 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 + * 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 _MATH_H_ #define _MATH_H_ -#include -// Betrag einer reelen Zahl errechen -#ifndef CONFIG_LIBC_NO_STUBS -double fabs(double x); -#endif +# define NAN (__builtin_nanf ("")) + +double tan(double); +float tanf(float); +long double tanl(long double); +double sqrt(double); +float sqrtf(float); +long double sqrtl(long double); +double sin(double); +float sinf(float); +long double sinl(long double); +double log2(double); +float log2f(float); +long double log2l(long double); +double log10(double); +float log10f(float); +long double log10l(long double); +double log(double); +float logf(float); +long double logl(long double); +double ldexp(double, int); +float ldexpf(float, int); +long double ldexpl(long double, int); +double fabs(double); +float fabsf(float); +long double fabsl(long double); +double exp(double); +float expf(float); +long double expl(long double); +double cos(double); +float cosf(float); +long double cosl(long double); +double atan(double); +float atanf(float); +long double atanl(long double); +double atan2(double, double); +float atan2f(float, float); +long double atan2l(long double, long double); +double asin(double); +float asinf(float); +long double asinl(long double); +double acos(double); +float acosf(float); +long double acosl(long double); #endif + diff --git a/src/modules/lib/stdlibc/math.c b/src/modules/lib/stdlibc/math.c deleted file mode 100644 index 76d437f..0000000 --- a/src/modules/lib/stdlibc/math.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2007 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. - */ - -#include -#include -#include - -// FIXME: Nur bis der Float-Kram vom Kernel unterstuetzt wird -#ifndef CONFIG_LIBC_NO_STUBS - -/** - * Betrag einer reellen Zahl errechnen - */ -double fabs(double x) -{ - return ((x < 0) ? -x : x); -} - -#endif - diff --git a/src/modules/lib/stdlibc/math/fabs.c b/src/modules/lib/stdlibc/math/fabs.c new file mode 100644 index 0000000..59633da --- /dev/null +++ b/src/modules/lib/stdlibc/math/fabs.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double fabs(double x) +{ + double res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + +float fabsf(float x) +{ + float res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + +long double fabsl(long double x) +{ + long double res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fcos.c b/src/modules/lib/stdlibc/math/fcos.c new file mode 100644 index 0000000..06d2d7d --- /dev/null +++ b/src/modules/lib/stdlibc/math/fcos.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pio2 1.570796326794896619 + +double cos(double x) +{ + double res; + asm("fcos;" : "=t" (res) : "0" (x)); + return res; +} + +float cosf(float x) +{ + float res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +long double cosl(long double x) +{ + long double res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +double acos(double x) { + double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +float acosf(float x) { + float res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +long double acosl(long double x) { + long double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fexp.c b/src/modules/lib/stdlibc/math/fexp.c new file mode 100644 index 0000000..fbc48f5 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fexp.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double exp(double x) +{ + double one = 1; + double res; + asm("fyl2x;" + "f2xm1": "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float expf(float x) +{ + float one = 1; + float res; + asm("fyl2x;" + "f2xm1": "=t" (res) : "0" (x), "u" (one)); + return res; +} + +long double expl(long double x) +{ + long double one = 1; + long double res; + asm("fyl2x;" + "f2xm1" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fldexp.c b/src/modules/lib/stdlibc/math/fldexp.c new file mode 100644 index 0000000..83dd8da --- /dev/null +++ b/src/modules/lib/stdlibc/math/fldexp.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double ldexp(double x, int exp) +{ + double res = x; + int exponent; + int i; + if (!exp) { + if (!x) { + errno = EDOM; + return NAN; + } + return 1; + } + exponent = exp; + if (exp < 0) { + exponent = -exp; + } + for (i = 1; i < exponent; i++) { + res *= x; + } + + if (exp < 0) { + return 1 / res; + } + + return res; +} + +float ldexpf(float x, int exp) +{ + float res = x; + int exponent; + int i; + if (!exp) { + if (!x) { + errno = EDOM; + return NAN; + } + return 1; + } + exponent = exp; + if (exp < 0) { + exponent = -exp; + } + for (i = 1; i < exponent; i++) { + res *= x; + } + + if (exp < 0) { + return 1 / res; + } + + return res; +} + +long double ldexpl(long double x, int exp) +{ + long double res = x; + int exponent; + int i; + if (!exp) { + if (!x) { + errno = EDOM; + return NAN; + } + return 1; + } + exponent = exp; + if (exp < 0) { + exponent = -exp; + } + for (i = 1; i < exponent; i++) { + res *= x; + } + + if (exp < 0) { + return 1 / res; + } + + return res; +} + diff --git a/src/modules/lib/stdlibc/math/flog.c b/src/modules/lib/stdlibc/math/flog.c new file mode 100644 index 0000000..14e906d --- /dev/null +++ b/src/modules/lib/stdlibc/math/flog.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double log2(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float log2f(float x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + + +long double log2l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +double log(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float logf(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +long double logl(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + + +double log10(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +float log10f(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +long double log10l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + diff --git a/src/modules/lib/stdlibc/math/fsin.c b/src/modules/lib/stdlibc/math/fsin.c new file mode 100644 index 0000000..9748def --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsin.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double sin(double x) +{ + double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +float sinf(float x) +{ + float res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +long double sinl(long double x) +{ + long double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +double asin(double x) { + double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + +float asinf(float x) { + float res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + +long double asinl(long double x) { + long double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fsqrt.c b/src/modules/lib/stdlibc/math/fsqrt.c new file mode 100644 index 0000000..1d9ac72 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsqrt.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +long double sqrtl(long double x) +{ + long double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + +double sqrt(double x) +{ + double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=l" (res) : "0" (x)); + return res; +} + +float sqrtf(float x) +{ + float res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c new file mode 100644 index 0000000..de2f2ba --- /dev/null +++ b/src/modules/lib/stdlibc/math/ftan.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pi 3.1415926535897932384 +#define pio2 1.570796326794896619 + +static short sgn(double x) { + short res; + if (x < 0) { + res = -1; + } else if (x == 0) { + res = 0; + } else { + res = 1; + } + return res; +} + + +double tan(double x) +{ + double res; + asm("fptan" : "=t" (res) : "0" (x)); + return res; +} + +float tanf(float x) +{ + float res; + asm("fptan" : "=t" (res) : "0" (x)); + return res; +} + +long double tanl(long double x) +{ + long double res; + asm("fptan" : "=t" (res) : "0" (x)); + return res; +} + +double atan(double x) +{ + + double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +float atanf(float x) +{ + float res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + + +long double atanl(long double x) +{ + long double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +double atan2(double x, double y) { + double res; + if (x < 0) { + res = (pi - atan(y / x)) * sgn(y); + return res; + } else if (x == 0) { + if (y == 0) { + errno = EDOM; + return NAN; + } + res = pio2 * sgn(y); + return res; + } + res = atan(y / x) * sgn(y); + return res; +} + + +float atan2f(float x, float y) { + float res; + if (x < 0) { + res = (pi - atan(y / x)) * (float)sgn((double)y); + return res; + } else if (x == 0) { + if (y == 0) { + errno = EDOM; + return NAN; + } + res = pio2 * (float)sgn((double)y); + return res; + } + res = atan(y / x) * (float)sgn((double)y); + return res; +} + +long double atan2l(long double x, long double y) { + long double res; + if (x < 0) { + res = (pi - atan(y / x)) * (long double)sgn((double)y); + return res; + } else if (x == 0) { + if (y == 0) { + errno = EDOM; + return NAN; + } + res = pio2 * (long double)sgn((double)y); + return res; + } + res = atan(y / x) * (long double)sgn((double)y); + return res; +} + -- 1.6.3.3 From kevin at tyndur.org Sat Aug 8 16:06:46 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 16:06:46 +0200 Subject: [tyndur-devel] [PATCH 0/4] Patches fuer Subversion Message-ID: <1249740410-9421-1-git-send-email-kevin@tyndur.org> Die folgenden Patches erlauben es, svn commit so zu benutzen, wie man sich das vorstellt. (Abgesehen davon, dass er keine Umlaute in der Commitmessage mag, und von allen anderen noch unentdeckten Features) Kevin Wolf (4): libc: POSIX: rmdir implementieren Pascal-RTL: exit() aus der libc benutzen libc: strerror gibt die Fehlernummer aus LostIOv1: Korrekter Fehlercode beim Loeschen nichtexistenter Dateien src/lib/string/strerror.c | 45 --------------------------------- src/modules/lib/lostio/handler.c | 9 +++++- src/modules/lib/posix/rmdir.c | 14 +++++++--- src/modules/lib/posix/strerror.c | 48 ++++++++++++++++++++++++++++++++++++ src/modules/pas/lib/rtl/system.pas | 7 ++--- 5 files changed, 68 insertions(+), 55 deletions(-) delete mode 100644 src/lib/string/strerror.c create mode 100644 src/modules/lib/posix/strerror.c From kevin at tyndur.org Sat Aug 8 16:06:47 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 16:06:47 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: rmdir implementieren In-Reply-To: <1249740410-9421-1-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> Message-ID: <1249740410-9421-2-git-send-email-kevin@tyndur.org> ! libc: POSIX: Ein implementiertes rmdir macht svn cleanup etwas gluecklicher Signed-off-by: Kevin Wolf --- src/modules/lib/posix/rmdir.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/lib/posix/rmdir.c b/src/modules/lib/posix/rmdir.c index 60d7f22..702c544 100644 --- a/src/modules/lib/posix/rmdir.c +++ b/src/modules/lib/posix/rmdir.c @@ -27,6 +27,8 @@ */ #include +#include +#include #include /** @@ -36,9 +38,13 @@ * * @return 0 bei Erfolg, -1 im Fehlerfall */ -int rmdir(const char* filename) { - // TODO - errno = EPERM; - return -1; +int rmdir(const char* filename) +{ + if (!is_directory(filename)) { + errno = ENOTDIR; + return -1; + } + + return io_remove_link(filename); } -- 1.5.6.5 From kevin at tyndur.org Sat Aug 8 16:06:48 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 16:06:48 +0200 Subject: [tyndur-devel] [PATCH 2/4] Pascal-RTL: exit() aus der libc benutzen In-Reply-To: <1249740410-9421-1-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> Message-ID: <1249740410-9421-3-git-send-email-kevin@tyndur.org> ! Pascal-RTL: Beim Beenden des Programms wird jetzt nicht mehr direkt der exit-Syscall aufgerufen, sondern exit() aus der libc. Dadurch geben auch Pascal-Programme einen vernuenftigen Exitcode zurueck und svn akzeptiert die in kedit eingegebene Commitmessage. Signed-off-by: Kevin Wolf --- src/modules/pas/lib/rtl/system.pas | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/pas/lib/rtl/system.pas b/src/modules/pas/lib/rtl/system.pas index 8fccd81..92701ea 100644 --- a/src/modules/pas/lib/rtl/system.pas +++ b/src/modules/pas/lib/rtl/system.pas @@ -81,12 +81,11 @@ end; {***************************************************************************** System Dependent Exit code *****************************************************************************} +procedure c_exit(exit_code: integer); cdecl; external name 'exit'; + procedure system_exit; begin - asm - mov SYSCALL_PM_EXIT_PROCESS, %eax - int $0x30 - end; + c_exit(exitcode); end; -- 1.5.6.5 From kevin at tyndur.org Sat Aug 8 16:06:49 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 16:06:49 +0200 Subject: [tyndur-devel] [PATCH 3/4] libc: strerror gibt die Fehlernummer aus In-Reply-To: <1249740410-9421-1-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> Message-ID: <1249740410-9421-4-git-send-email-kevin@tyndur.org> + libc: strerror gibt die Fehlernummer aus, wenn es schon keine richtigen Meldungen gibt Signed-off-by: Kevin Wolf --- src/lib/string/strerror.c | 45 ----------------------------------- src/modules/lib/posix/strerror.c | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 45 deletions(-) delete mode 100644 src/lib/string/strerror.c create mode 100644 src/modules/lib/posix/strerror.c diff --git a/src/lib/string/strerror.c b/src/lib/string/strerror.c deleted file mode 100644 index c1215a1..0000000 --- a/src/lib/string/strerror.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2007 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. - */ - -#include -#include - -/** - * Netter Fehlertext zu der angegebenen Fehlernummer zurueckgeben - * TODO: ATM nur stub - * - * @param error_code Fehlernummer - * - * @return Pointer auf internen Buffer mit Fehlermeldung - */ -char* strerror(int error_code) -{ - static char* error_message = "Unbekannter Fehler"; - return error_message; -} - diff --git a/src/modules/lib/posix/strerror.c b/src/modules/lib/posix/strerror.c new file mode 100644 index 0000000..e08f3e0 --- /dev/null +++ b/src/modules/lib/posix/strerror.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007 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. + */ + +#include +#include +#include + +/** + * Netter Fehlertext zu der angegebenen Fehlernummer zurueckgeben + * TODO: ATM nur stub + * + * @param error_code Fehlernummer + * + * @return Pointer auf internen Buffer mit Fehlermeldung + */ +char* strerror(int error_code) +{ + static char error_message[64]; + snprintf(error_message, sizeof(error_message), + "Unbekannter Fehler %d", error_code); + return error_message; +} + -- 1.5.6.5 From kevin at tyndur.org Sat Aug 8 16:06:50 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 16:06:50 +0200 Subject: [tyndur-devel] [PATCH 4/4] LostIOv1: Korrekter Fehlercode beim Loeschen nichtexistenter Dateien In-Reply-To: <1249740410-9421-1-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> Message-ID: <1249740410-9421-5-git-send-email-kevin@tyndur.org> ! LostIOv1: Wenn man eine Datei loescht, die es nicht gibt, muss am Ende ENOENT rauskommen, nicht ein undefinierbares EPERM. Signed-off-by: Kevin Wolf --- src/modules/lib/lostio/handler.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/lib/lostio/handler.c b/src/modules/lib/lostio/handler.c index 96791de..2f067d7 100644 --- a/src/modules/lib/lostio/handler.c +++ b/src/modules/lib/lostio/handler.c @@ -411,7 +411,7 @@ void rpc_io_link(pid_t pid, dword correlation_id, size_t data_size, void* data) * RPC-Rueckgabewerte: * 0: Erfolg * - * -1: Verzeichnis existiert nicht + * -1: Verzeichnis oder Datei existiert nicht * -2: Fuer das Verzeichnis ist kein Unlink-Handler eingetragen * -3: Das Format der erhaltenen RPC-Daten stimmt nicht * -4: Beim eigentlichen Loeschen des Links ist ein Fehler aufgetreten @@ -442,9 +442,14 @@ void rpc_io_unlink(pid_t pid, dword correlation_id, size_t data_size, void* data return; } - // Keine Datei loeschen die geoffnet ist. vfstree_node_t* node = vfstree_get_node_by_name(dir_filehandle->node, unlink_request->name); + if (node == NULL) { + rpc_send_int_response(pid, correlation_id, -1); + return; + } + + // Keine Datei loeschen die geoffnet ist. lostio_filehandle_t* fh; int i; for (i = 0; (fh = list_get_element_at(filehandles, i)); i++) { -- 1.5.6.5 From toni at tyndur.org Sat Aug 8 16:20:30 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 16:20:30 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: rmdir implementieren In-Reply-To: <1249740410-9421-2-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> <1249740410-9421-2-git-send-email-kevin@tyndur.org> Message-ID: <20090808142029.GA29774@einstein.kaufmann.lan> On Sat, Aug 08 16:06, Kevin Wolf wrote: > ! libc: POSIX: Ein implementiertes rmdir macht svn cleanup etwas gluecklicher > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 16:21:19 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 16:21:19 +0200 Subject: [tyndur-devel] [PATCH 2/4] Pascal-RTL: exit() aus der libc benutzen In-Reply-To: <1249740410-9421-3-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> <1249740410-9421-3-git-send-email-kevin@tyndur.org> Message-ID: <20090808142119.GB29774@einstein.kaufmann.lan> On Sat, Aug 08 16:06, Kevin Wolf wrote: > ! Pascal-RTL: Beim Beenden des Programms wird jetzt nicht mehr direkt der > exit-Syscall aufgerufen, sondern exit() aus der libc. Dadurch geben auch > Pascal-Programme einen vernuenftigen Exitcode zurueck und svn akzeptiert > die in kedit eingegebene Commitmessage. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 16:23:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 16:23:44 +0200 Subject: [tyndur-devel] [PATCH 3/4] libc: strerror gibt die Fehlernummer aus In-Reply-To: <1249740410-9421-4-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> <1249740410-9421-4-git-send-email-kevin@tyndur.org> Message-ID: <20090808142344.GC29774@einstein.kaufmann.lan> On Sat, Aug 08 16:06, Kevin Wolf wrote: > + libc: strerror gibt die Fehlernummer aus, wenn es schon keine richtigen > Meldungen gibt > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 8 16:27:52 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 8 Aug 2009 16:27:52 +0200 Subject: [tyndur-devel] [PATCH 4/4] LostIOv1: Korrekter Fehlercode beim Loeschen nichtexistenter Dateien In-Reply-To: <1249740410-9421-5-git-send-email-kevin@tyndur.org> References: <1249740410-9421-1-git-send-email-kevin@tyndur.org> <1249740410-9421-5-git-send-email-kevin@tyndur.org> Message-ID: <20090808142752.GD29774@einstein.kaufmann.lan> On Sat, Aug 08 16:06, Kevin Wolf wrote: > ! LostIOv1: Wenn man eine Datei loescht, die es nicht gibt, muss am Ende ENOENT > rauskommen, nicht ein undefinierbares EPERM. > > Signed-off-by: Kevin Wolf Hm aber eine geoeffnete Datei gibt vermutlich das selbe zurueck... Sieht Stdlib/POSIX da auch was vor? Aber damit hat das ja nichts zu tun, also Ack. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Aug 8 17:25:42 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 8 Aug 2009 17:25:42 +0200 Subject: [tyndur-devel] [PATCH] Libc: Erstes Stueck richtige libm In-Reply-To: <1249736447-2109-1-git-send-email-patrick@tyndur.org> References: <1249735080-6870-1-git-send-email-patrick@tyndur.org> <1249736447-2109-1-git-send-email-patrick@tyndur.org> Message-ID: <20090808152542.GB4812@debws.produktiv.lan> On Sat, Aug 08, 2009 at 03:00:47PM +0200, Patrick Kaufmann wrote: > From: patrick > > + Libc: Erstes Stueck richtige libm > > Signed-off-by: Patrick Kaufmann > --- > src/modules/include/math.h | 74 ++++++++++++---- > src/modules/lib/stdlibc/math.c | 45 ---------- > src/modules/lib/stdlibc/math/fabs.c | 67 ++++++++++++++ > src/modules/lib/stdlibc/math/fcos.c | 85 ++++++++++++++++++ > src/modules/lib/stdlibc/math/fexp.c | 58 ++++++++++++ > src/modules/lib/stdlibc/math/fldexp.c | 112 +++++++++++++++++++++++ > src/modules/lib/stdlibc/math/flog.c | 157 +++++++++++++++++++++++++++++++++ > src/modules/lib/stdlibc/math/fsin.c | 83 +++++++++++++++++ > src/modules/lib/stdlibc/math/fsqrt.c | 64 +++++++++++++ > src/modules/lib/stdlibc/math/ftan.c | 143 ++++++++++++++++++++++++++++++ > 10 files changed, 826 insertions(+), 62 deletions(-) > delete mode 100644 src/modules/lib/stdlibc/math.c > create mode 100644 src/modules/lib/stdlibc/math/fabs.c > create mode 100644 src/modules/lib/stdlibc/math/fcos.c > create mode 100644 src/modules/lib/stdlibc/math/fexp.c > create mode 100644 src/modules/lib/stdlibc/math/fldexp.c > create mode 100644 src/modules/lib/stdlibc/math/flog.c > create mode 100644 src/modules/lib/stdlibc/math/fsin.c > create mode 100644 src/modules/lib/stdlibc/math/fsqrt.c > create mode 100644 src/modules/lib/stdlibc/math/ftan.c > > diff --git a/src/modules/include/math.h b/src/modules/include/math.h > index 8be2d9c..a5d39b4 100644 > --- a/src/modules/include/math.h > +++ b/src/modules/include/math.h > @@ -1,8 +1,8 @@ > -/* > - * Copyright (c) 2007 The tyndur Project. All rights reserved. > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > - * by Antoine Kaufmann. > + * by Patrick Kaufmann. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -13,26 +13,66 @@ > * 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 > + * 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 > + * 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 _MATH_H_ > #define _MATH_H_ > -#include > > -// Betrag einer reelen Zahl errechen > -#ifndef CONFIG_LIBC_NO_STUBS > -double fabs(double x); > -#endif > +# define NAN (__builtin_nanf ("")) An dieser Stelle könnte man ruhig großzügiger Konstanten definieren. Die Manpage zu math.h führt da einiges auf, z.B. M_E, M_PI oder M_PI_2, die du stattdessen in der Implementierung gelegentlich definiert hast. Ich gehe jetzt bei den folgenden Funktionen durch, ob sie mit dem Testprogramm funktioniert haben (d.h. gleiches Ergebnis wie libm unter Linux) oder nicht. Getestet worden ist jeweils die double-Variante. > + > +double tan(double); > +float tanf(float); > +long double tanl(long double); Falsche Ergebnisse. > +double sqrt(double); > +float sqrtf(float); > +long double sqrtl(long double); Scheint den Originalwert zurückzugeben > +double sin(double); > +float sinf(float); > +long double sinl(long double); Ok. > > +double log2(double); > +float log2f(float); > +long double log2l(long double); Ok. > +double log10(double); > +float log10f(float); > +long double log10l(long double); Falsche Ergebnisse. > +double log(double); > +float logf(float); > +long double logl(long double); Falsche Ergebnisse. > +double ldexp(double, int); > +float ldexpf(float, int); > +long double ldexpl(long double, int); Berechnet x^y statt x * 2^y, wenn ich das richtig sehe > +double fabs(double); > +float fabsf(float); > +long double fabsl(long double); Ok. > +double exp(double); > +float expf(float); > +long double expl(long double); Falsche Ergebnisse. > +double cos(double); > +float cosf(float); > +long double cosl(long double); Ok > +double atan(double); > +float atanf(float); > +long double atanl(long double); Ok > +double atan2(double, double); > +float atan2f(float, float); > +long double atan2l(long double, long double); Falsche Ergebnisse > +double asin(double); > +float asinf(float); > +long double asinl(long double); > +double acos(double); > +float acosf(float); > +long double acosl(long double); Sehen ungenau aus, aber grob in Ordnung. Für 1.0 geben sie aber NaN zurück, das ist nicht so optimal. > > > #endif > + > diff --git a/src/modules/lib/stdlibc/math.c b/src/modules/lib/stdlibc/math.c > deleted file mode 100644 > index 76d437f..0000000 > --- a/src/modules/lib/stdlibc/math.c > +++ /dev/null > @@ -1,45 +0,0 @@ > -/* > - * Copyright (c) 2007 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. > - */ > - > -#include > -#include > -#include > - > -// FIXME: Nur bis der Float-Kram vom Kernel unterstuetzt wird > -#ifndef CONFIG_LIBC_NO_STUBS > - > -/** > - * Betrag einer reellen Zahl errechnen > - */ > -double fabs(double x) > -{ > - return ((x < 0) ? -x : x); > -} > - > -#endif > - > diff --git a/src/modules/lib/stdlibc/math/fabs.c b/src/modules/lib/stdlibc/math/fabs.c > new file mode 100644 > index 0000000..59633da > --- /dev/null > +++ b/src/modules/lib/stdlibc/math/fabs.c > @@ -0,0 +1,67 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Patrick 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. > + */ > + > +#include "math.h" Nicht ? > +#include > + > +double fabs(double x) > +{ > + double res; > + if (x < 0.0) { > + res = -x; > + } Ein überflüssiges Leerzeichen am Ende. Laut git am gibt es davon insgesamt sieben im ganzen Patch. Das else ist bei uns normal auch auf der Zeile vom } > [...] > > diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c > new file mode 100644 > index 0000000..de2f2ba > --- /dev/null > +++ b/src/modules/lib/stdlibc/math/ftan.c > @@ -0,0 +1,143 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Patrick 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. > + */ > + > +#include "math.h" > +#include > + > +#define pi 3.1415926535897932384 > +#define pio2 1.570796326794896619 > + > +static short sgn(double x) { Die geschweifte Klammer kommt auf eine neue Zeile Ich glaube, das sollte mal vorerst an Kommentaren reichen ;-) From alex at tyndur.org Sat Aug 8 22:30:41 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 8 Aug 2009 22:30:41 +0200 Subject: [tyndur-devel] [PATCH] cp: Kopieren mit Verzeichnis als Ziel gefixt. Message-ID: <1249763441-29749-1-git-send-email-alex@tyndur.org> --- trunk/src/modules/c/shell/cmds/cp.c | 14 +++----------- 1 files changed, 3 insertions(+), 11 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/cp.c b/trunk/src/modules/c/shell/cmds/cp.c index 0d66eaf..8fb4435 100644 --- a/trunk/src/modules/c/shell/cmds/cp.c +++ b/trunk/src/modules/c/shell/cmds/cp.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Kevin Wolf. + * by Kevin Wolf, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -229,15 +229,7 @@ int cp_file(char* src_path, char* dst_path) { FILE* dst = NULL; if (is_directory(dst_path)) { char* filename = io_split_filename(src_path); - size_t length = strlen(filename) + strlen(dst_path) + 1; - - char dst_file_path[length + 1]; - strcpy(dst_file_path, dst_path); - dst_file_path[strlen(dst_file_path) + 1] = '\0'; - dst_file_path[strlen(dst_file_path)] = '/'; - strcat(dst_file_path, filename); - dst_file_path[length] = '\0'; - dst_path = dst_file_path; + asprintf(&dst_path, "%s/%s", dst_path, filename); } dst = fopen(dst_path, "w"); -- 1.5.6.5 From alex at tyndur.org Sat Aug 8 22:35:33 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 8 Aug 2009 22:35:33 +0200 Subject: [tyndur-devel] [PATCH] cp: Kopieren mit Verzeichnis als Ziel gefixt. In-Reply-To: <1249763441-29749-1-git-send-email-alex@tyndur.org> References: <1249763441-29749-1-git-send-email-alex@tyndur.org> Message-ID: <1249763733-29815-1-git-send-email-alex@tyndur.org> --- trunk/src/modules/c/shell/cmds/cp.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/cp.c b/trunk/src/modules/c/shell/cmds/cp.c index 0d66eaf..afd84e5 100644 --- a/trunk/src/modules/c/shell/cmds/cp.c +++ b/trunk/src/modules/c/shell/cmds/cp.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Kevin Wolf. + * by Kevin Wolf, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -226,18 +226,13 @@ int cp_file(char* src_path, char* dst_path) { return -1; } + int free_dst_path = 0; FILE* dst = NULL; if (is_directory(dst_path)) { char* filename = io_split_filename(src_path); - size_t length = strlen(filename) + strlen(dst_path) + 1; - - char dst_file_path[length + 1]; - strcpy(dst_file_path, dst_path); - dst_file_path[strlen(dst_file_path) + 1] = '\0'; - dst_file_path[strlen(dst_file_path)] = '/'; - strcat(dst_file_path, filename); - dst_file_path[length] = '\0'; - dst_path = dst_file_path; + asprintf(&dst_path, "%s/%s", dst_path, filename); + free(filename); + free_dst_path = 1; } dst = fopen(dst_path, "w"); @@ -263,6 +258,10 @@ int cp_file(char* src_path, char* dst_path) { fwrite(buffer, length, 1, dst); } + if (free_dst_path) { + free(dst_path); + } + fclose(src); fclose(dst); -- 1.5.6.5 From alex at tyndur.org Sat Aug 8 23:39:10 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 8 Aug 2009 23:39:10 +0200 Subject: [tyndur-devel] [PATCH] ls: Versteckte Dateien, Mehrere Verzeichnisse listen Message-ID: <1249767550-4905-1-git-send-email-alex@tyndur.org> +ls: Erkennung & Handhabung versteckter Dateien +ls: Mehrere Verzeichnisse können zum auflisten angegeben werden *ls: Umstellung auf getopt für weitere Erweiterungen Signed-off-by: Alexander Siol --- trunk/src/modules/c/shell/cmds/ls.c | 110 +++++++++++++++++++++++++---------- 1 files changed, 78 insertions(+), 32 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/ls.c b/trunk/src/modules/c/shell/cmds/ls.c index 195f769..8cfe7c7 100644 --- a/trunk/src/modules/c/shell/cmds/ls.c +++ b/trunk/src/modules/c/shell/cmds/ls.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Antoine Kaufmann, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,6 +39,8 @@ #include "dir.h" #include "unistd.h" #include +#include +#include void ls_display_usage(void); @@ -48,46 +50,89 @@ void ls_display_usage(void); int main(int argc, char* argv[]) #endif { - if (argc > 2) { - ls_display_usage(); - return -1; - } - char* dir_path; - bool free_dir_path; + char* cwd_dir = NULL; bool success = TRUE; + bool show_hidden = FALSE; + list_t *dirs = list_create(); + bool print_dirnames = FALSE; - if (argc == 1) { - //Mit NULL als Parameter wird der buffer mit malloc() erstellt - dir_path = getcwd(NULL, 0); - free_dir_path = TRUE; - } else { - dir_path = argv[1]; - free_dir_path = FALSE; + static const struct option long_options[] = + { + { "all", no_argument, 0, 'a' }, + { "help", no_argument, 0, 1 }, + { 0, 0, 0, 0 } + }; + + optind = 0; + + while (optind < argc) { + int result = getopt_long(argc, argv, "a", long_options, NULL); + if (result == -1) { + break; + } + switch (result) { + case 'a': + show_hidden = TRUE; + break; + case 1: + ls_display_usage(); + return EXIT_SUCCESS; + default: + break; + } + } + + while (optind < argc) { + list_push(dirs, argv[optind++]); } + if (list_size(dirs) == 0) { + cwd_dir = getcwd(NULL, 0); + list_push(dirs, cwd_dir); + } + + if (list_size(dirs) > 1) { + print_dirnames = TRUE; + } - io_resource_t* dir_res = directory_open(dir_path); - if (dir_res != NULL) { - io_direntry_t* direntry; - while ((direntry = directory_read(dir_res))) { - if (direntry->type == IO_DIRENTRY_FILE) { - printf(" %s\n", direntry->name); - } else { - printf(" [DIR] %s\n", direntry->name); + while ((dir_path = list_pop(dirs))) { + if (print_dirnames) { + printf("%s:\n", dir_path); + } + io_resource_t* dir_res = directory_open(dir_path); + if (dir_res != NULL) { + io_direntry_t* direntry; + while ((direntry = directory_read(dir_res))) { + bool entry_hidden = FALSE; + if (strncmp(direntry->name, ".", 1) == 0) { + entry_hidden = TRUE; + } + if (entry_hidden == FALSE || show_hidden == TRUE) { + if (direntry->type == IO_DIRENTRY_FILE) { + printf(" %s\n", direntry->name); + } else { + printf(" [DIR] %s\n", direntry->name); + } + } + free(direntry); } - free(direntry); + + directory_close(dir_res); + } else { + printf("Konnte '%s' nicht zum lesen oeffnen!\n", dir_path); + success = FALSE; + } + if (list_size(dirs) > 0) { + printf("\n"); } - - directory_close(dir_res); - } else { - printf("Konnte '%s' nicht zum lesen oeffnen!\n", dir_path); - success = FALSE; } - if (free_dir_path == TRUE) { - free(dir_path); + if (cwd_dir != NULL) { + free(cwd_dir); } + + list_destroy(dirs); if (success == TRUE) { return EXIT_SUCCESS; @@ -98,6 +143,7 @@ void ls_display_usage(void); void ls_display_usage() { - puts("\nAufruf: ls [Verzeichnis]\n"); + puts("\nAufruf: ls [-a] [Verzeichnis]\n"); + puts("Mittels der Option -a werden versteckte Dateien angezeigt.\n"); } -- 1.5.6.5 From alex at tyndur.org Sun Aug 9 00:09:19 2009 From: alex at tyndur.org (Alexander Siol) Date: Sun, 9 Aug 2009 00:09:19 +0200 Subject: [tyndur-devel] [PATCH] bincat: Positionsangabe moeglich (wird auf 1k-Bloecke gerundet) Message-ID: <1249769359-8569-1-git-send-email-alex@tyndur.org> +bincat: Positionsangaben (Start, Länge und Ende) *bincat: Umstellung auf getopt Signed-off-by: Alexander Siol --- trunk/src/modules/c/shell/cmds/bincat.c | 75 +++++++++++++++++++++++++++--- 1 files changed, 67 insertions(+), 8 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/bincat.c b/trunk/src/modules/c/shell/cmds/bincat.c index 8c0372e..0fa8539 100644 --- a/trunk/src/modules/c/shell/cmds/bincat.c +++ b/trunk/src/modules/c/shell/cmds/bincat.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Antoine Kaufmann, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,35 +38,94 @@ #include "stdio.h" #include "unistd.h" #include +#include #define BLOCK_SIZE 1024 void bincat_display_usage(void); +#define min(a,b) (a < b)?(a):(b); + #ifdef CONFIG_SHELL_BUILTIN_ONLY int shell_command_bincat(int argc, char* argv[], const char* args) #else int main(int argc, char* argv[]) #endif { - if (argc != 2) { + static const struct option long_options[] = + { + { "start", required_argument, 0, 's' }, + { "size", required_argument, 0, 'l' }, + { "end", required_argument, 0, 'e' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + optind = 0; + int start = 0; + int end = 0; + int length = 0; + char *path = NULL; + int n = 0; + int m = 0; + size_t total_read = 0; + + + while (optind < argc) { + int result = getopt_long(argc, argv, "s:l:e:h", long_options, NULL); + if (result == -1) { + break; + } + switch (result) { + case 's': + start = atoi(optarg); + break; + case 'l': + length = atoi(optarg); + break; + case 'e': + end = atoi(optarg); + break; + case 'h': + bincat_display_usage(); + return EXIT_SUCCESS; + default: + break; + } + } + + if (length && end) { + printf("--size und --end schließen sich aus. Verwende --size\n"); + } else if (end) { + length = end - start; + } + + while (optind < argc) { + path = argv[optind++]; + } + + if (path == NULL) { bincat_display_usage(); - return -1; + return EXIT_SUCCESS; } - char* path = argv[1]; FILE* file = fopen(path, "r"); + fseek(file, start, SEEK_SET); + m = start / 8; + if (file == NULL) { printf("Konnte '%s' nicht zum lesen oeffnen!\n", path); return -1; } else { char buffer[BLOCK_SIZE]; size_t size; - int n, m = 0; - while (feof(file) != EOF) { + while (feof(file) != EOF && (total_read <= length || length == 0)) { + size = fread(buffer, 1, BLOCK_SIZE, file); + total_read += size; + printf("0x%08x: ", m); for (n=0; n < size; n++) { @@ -82,7 +141,7 @@ void bincat_display_usage(void); fclose(file); } - + printf("\n"); return EXIT_SUCCESS; } -- 1.5.6.5 From toni at tyndur.org Sun Aug 9 09:50:50 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 9 Aug 2009 09:50:50 +0200 Subject: [tyndur-devel] [PATCH] servmgr: Etwas grosszuegiger Dateien schliessen Message-ID: <1249804250-9299-1-git-send-email-toni@tyndur.org> ! servmgr: Wenn man in servmgr die Konfigurationsdateien nach dem Einlesen auch wieder schliesst, lassen sich diese danach sogar loeschen. Signed-off-by: Antoine Kaufmann --- src/modules/servmgr/config.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c index c722e41..ce7f8ef 100644 --- a/src/modules/servmgr/config.c +++ b/src/modules/servmgr/config.c @@ -161,6 +161,7 @@ static void config_parse_deps(const char* path, list_push(conf_serv->deps, dep); } + fclose(f); } /** @@ -190,6 +191,7 @@ static void config_parse_conf(const char* path, conf_serv->conf.wait = TERMINATE; } } + fclose(f); } -- 1.6.3.3 From kevin at tyndur.org Sun Aug 9 09:54:51 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 9 Aug 2009 09:54:51 +0200 Subject: [tyndur-devel] [PATCH] ls: Versteckte Dateien, Mehrere Verzeichnisse listen In-Reply-To: <1249767550-4905-1-git-send-email-alex@tyndur.org> References: <1249767550-4905-1-git-send-email-alex@tyndur.org> Message-ID: <20090809075451.GA3435@debws.produktiv.lan> On Sat, Aug 08, 2009 at 11:39:10PM +0200, Alexander Siol wrote: > +ls: Erkennung & Handhabung versteckter Dateien > +ls: Mehrere Verzeichnisse können zum auflisten angegeben werden > *ls: Umstellung auf getopt für weitere Erweiterungen > > Signed-off-by: Alexander Siol > --- > trunk/src/modules/c/shell/cmds/ls.c | 110 +++++++++++++++++++++++++---------- > 1 files changed, 78 insertions(+), 32 deletions(-) > > diff --git a/trunk/src/modules/c/shell/cmds/ls.c b/trunk/src/modules/c/shell/cmds/ls.c > index 195f769..8cfe7c7 100644 > --- a/trunk/src/modules/c/shell/cmds/ls.c > +++ b/trunk/src/modules/c/shell/cmds/ls.c > @@ -1,8 +1,8 @@ > /* > - * Copyright (c) 2007 The tyndur Project. All rights reserved. > + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > - * by Antoine Kaufmann. > + * by Antoine Kaufmann, Alexander Siol > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -39,6 +39,8 @@ > #include "dir.h" > #include "unistd.h" > #include > +#include > +#include > > void ls_display_usage(void); > > @@ -48,46 +50,89 @@ void ls_display_usage(void); > int main(int argc, char* argv[]) > #endif > { > - if (argc > 2) { > - ls_display_usage(); > - return -1; > - } > - > char* dir_path; > - bool free_dir_path; > + char* cwd_dir = NULL; > bool success = TRUE; > + bool show_hidden = FALSE; > + list_t *dirs = list_create(); > + bool print_dirnames = FALSE; > > - if (argc == 1) { > - //Mit NULL als Parameter wird der buffer mit malloc() erstellt > - dir_path = getcwd(NULL, 0); > - free_dir_path = TRUE; > - } else { > - dir_path = argv[1]; > - free_dir_path = FALSE; > + static const struct option long_options[] = > + { > + { "all", no_argument, 0, 'a' }, > + { "help", no_argument, 0, 1 }, > + { 0, 0, 0, 0 } > + }; > + > + optind = 0; > + > + while (optind < argc) { > + int result = getopt_long(argc, argv, "a", long_options, NULL); Warum kein -h erlauben? > + if (result == -1) { > + break; > + } > + switch (result) { > + case 'a': > + show_hidden = TRUE; > + break; > + case 1: > + ls_display_usage(); > + return EXIT_SUCCESS; > + default: > + break; > + } > + } > + > + while (optind < argc) { > + list_push(dirs, argv[optind++]); > } > > + if (list_size(dirs) == 0) { > + cwd_dir = getcwd(NULL, 0); > + list_push(dirs, cwd_dir); > + } > + > + if (list_size(dirs) > 1) { > + print_dirnames = TRUE; > + } > > - io_resource_t* dir_res = directory_open(dir_path); > - if (dir_res != NULL) { > - io_direntry_t* direntry; > - while ((direntry = directory_read(dir_res))) { > - if (direntry->type == IO_DIRENTRY_FILE) { > - printf(" %s\n", direntry->name); > - } else { > - printf(" [DIR] %s\n", direntry->name); > + while ((dir_path = list_pop(dirs))) { > + if (print_dirnames) { > + printf("%s:\n", dir_path); > + } > + io_resource_t* dir_res = directory_open(dir_path); > + if (dir_res != NULL) { > + io_direntry_t* direntry; > + while ((direntry = directory_read(dir_res))) { > + bool entry_hidden = FALSE; > + if (strncmp(direntry->name, ".", 1) == 0) { > + entry_hidden = TRUE; > + } Darf ich einen Gegenvorschlag machen? bool entry_hidden = (*direntry->name == '.'); > + if (entry_hidden == FALSE || show_hidden == TRUE) { if (!entry_hidden || show_hidden) > + if (direntry->type == IO_DIRENTRY_FILE) { > + printf(" %s\n", direntry->name); > + } else { > + printf(" [DIR] %s\n", direntry->name); > + } > + } > + free(direntry); > } > - free(direntry); > + > + directory_close(dir_res); > + } else { > + printf("Konnte '%s' nicht zum lesen oeffnen!\n", dir_path); öffnen mit ö > + success = FALSE; > + } > + if (list_size(dirs) > 0) { > + printf("\n"); > } > - > - directory_close(dir_res); > - } else { > - printf("Konnte '%s' nicht zum lesen oeffnen!\n", dir_path); > - success = FALSE; > } > > - if (free_dir_path == TRUE) { > - free(dir_path); > + if (cwd_dir != NULL) { > + free(cwd_dir); > } free(NULL) funktioniert ohne weiteres > + > + list_destroy(dirs); > > if (success == TRUE) { > return EXIT_SUCCESS; > @@ -98,6 +143,7 @@ void ls_display_usage(void); > > void ls_display_usage() > { > - puts("\nAufruf: ls [Verzeichnis]\n"); > + puts("\nAufruf: ls [-a] [Verzeichnis]\n"); > + puts("Mittels der Option -a werden versteckte Dateien angezeigt.\n"); Das könnte man auch in ein üblicheres Format bringen, also: -a: Versteckte Dateien anzeigen -h: -Dieser Hilfe > > > > } > > -- > 1.5.6.5 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From kevin at tyndur.org Sun Aug 9 09:58:00 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 9 Aug 2009 09:58:00 +0200 Subject: [tyndur-devel] [PATCH] servmgr: Etwas grosszuegiger Dateien schliessen In-Reply-To: <1249804250-9299-1-git-send-email-toni@tyndur.org> References: <1249804250-9299-1-git-send-email-toni@tyndur.org> Message-ID: <20090809075800.GB3435@debws.produktiv.lan> On Sun, Aug 09, 2009 at 09:50:50AM +0200, Antoine Kaufmann wrote: > ! servmgr: Wenn man in servmgr die Konfigurationsdateien nach dem > Einlesen auch wieder schliesst, lassen sich diese danach > sogar loeschen. > > Signed-off-by: Antoine Kaufmann Acked-by: Kevin Wolf > > > --- > src/modules/servmgr/config.c | 2 ++ > 1 files changed, 2 insertions(+), 0 deletions(-) > > diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c > index c722e41..ce7f8ef 100644 > --- a/src/modules/servmgr/config.c > +++ b/src/modules/servmgr/config.c > @@ -161,6 +161,7 @@ static void config_parse_deps(const char* path, > > list_push(conf_serv->deps, dep); > } > + fclose(f); > } > > /** > @@ -190,6 +191,7 @@ static void config_parse_conf(const char* path, > conf_serv->conf.wait = TERMINATE; > } > } > + fclose(f); > } > > > -- > 1.6.3.3 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From kevin at tyndur.org Sun Aug 9 10:08:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 9 Aug 2009 10:08:23 +0200 Subject: [tyndur-devel] [PATCH] bincat: Positionsangabe moeglich (wird auf 1k-Bloecke gerundet) In-Reply-To: <1249769359-8569-1-git-send-email-alex@tyndur.org> References: <1249769359-8569-1-git-send-email-alex@tyndur.org> Message-ID: <20090809080822.GC3435@debws.produktiv.lan> On Sun, Aug 09, 2009 at 12:09:19AM +0200, Alexander Siol wrote: > +bincat: Positionsangaben (Start, Länge und Ende) > *bincat: Umstellung auf getopt > > Signed-off-by: Alexander Siol > --- > trunk/src/modules/c/shell/cmds/bincat.c | 75 +++++++++++++++++++++++++++--- > 1 files changed, 67 insertions(+), 8 deletions(-) > > diff --git a/trunk/src/modules/c/shell/cmds/bincat.c b/trunk/src/modules/c/shell/cmds/bincat.c > index 8c0372e..0fa8539 100644 > --- a/trunk/src/modules/c/shell/cmds/bincat.c > +++ b/trunk/src/modules/c/shell/cmds/bincat.c > @@ -1,8 +1,8 @@ > /* > - * Copyright (c) 2007 The tyndur Project. All rights reserved. > + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > - * by Antoine Kaufmann. > + * by Antoine Kaufmann, Alexander Siol > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -38,35 +38,94 @@ > #include "stdio.h" > #include "unistd.h" > #include > +#include > > #define BLOCK_SIZE 1024 > > void bincat_display_usage(void); > > +#define min(a,b) (a < b)?(a):(b); > + > #ifdef CONFIG_SHELL_BUILTIN_ONLY > int shell_command_bincat(int argc, char* argv[], const char* args) > #else > int main(int argc, char* argv[]) > #endif > { > - if (argc != 2) { > + static const struct option long_options[] = > + { > + { "start", required_argument, 0, 's' }, > + { "size", required_argument, 0, 'l' }, Wenn -l, dann bitte doch auch --length > + { "end", required_argument, 0, 'e' }, > + { "help", no_argument, 0, 'h' }, > + { 0, 0, 0, 0 } > + }; > + > + optind = 0; > + int start = 0; > + int end = 0; > + int length = 0; Du willst vermutlich uint64_t > + char *path = NULL; > + int n = 0; > + int m = 0; > + size_t total_read = 0; > + > + > + while (optind < argc) { > + int result = getopt_long(argc, argv, "s:l:e:h", long_options, NULL); > + if (result == -1) { > + break; > + } > + switch (result) { > + case 's': > + start = atoi(optarg); Evtl. strtoull mit Basis 0, dann kann man auch in Hex eingeben. Ergebnis prüfen wäre auch noch eine Idee. > + break; > + case 'l': > + length = atoi(optarg); > + break; > + case 'e': > + end = atoi(optarg); > + break; > + case 'h': > + bincat_display_usage(); bincat_display_usage könnte auch ein Update vertragen > + return EXIT_SUCCESS; > + default: > + break; > + } > + } > + > + if (length && end) { > + printf("--size und --end schließen sich aus. Verwende --size\n"); Normal wäre, einfach abzubrechen > + } else if (end) { > + length = end - start; > + } > + > + while (optind < argc) { > + path = argv[optind++]; > + } Hm, also nur die letzte Datei wird angezeigt? Ich würde entweder nacheinander alle anzeigen oder einen Fehler ausgeben, wenn mehr als eine angegeben wird. > + > + if (path == NULL) { > bincat_display_usage(); > - return -1; > + return EXIT_SUCCESS; > } > > - char* path = argv[1]; > FILE* file = fopen(path, "r"); > > + fseek(file, start, SEEK_SET); > + m = start / 8; > + > if (file == NULL) { > printf("Konnte '%s' nicht zum lesen oeffnen!\n", path); > return -1; > } else { > char buffer[BLOCK_SIZE]; > size_t size; > - int n, m = 0; > - while (feof(file) != EOF) { > + while (feof(file) != EOF && (total_read <= length || length == 0)) { > + > size = fread(buffer, 1, BLOCK_SIZE, file); > > + total_read += size; > + > printf("0x%08x: ", m); > > for (n=0; n < size; n++) { > @@ -82,7 +141,7 @@ void bincat_display_usage(void); > > fclose(file); > } > - > + printf("\n"); > return EXIT_SUCCESS; > } > > -- > 1.5.6.5 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From patrick at tyndur.org Sun Aug 9 10:17:42 2009 From: patrick at tyndur.org (Patrick Kaufmann) Date: Sun, 9 Aug 2009 10:17:42 +0200 Subject: [tyndur-devel] [PATCH] Libc: Erstes Stueck richtige libm In-Reply-To: <20090808152542.GB4812@debws.produktiv.lan> References: <20090808152542.GB4812@debws.produktiv.lan> Message-ID: <1249805862-5253-1-git-send-email-patrick@tyndur.org> From: patrick + Libc: Erstes Stueck richtige libm Signed-off-by: Patrick Kaufmann --- src/modules/include/math.h | 94 ++++++++++++++++++++----- src/modules/lib/stdlibc/math.c | 45 ------------ src/modules/lib/stdlibc/math/fabs.c | 67 +++++++++++++++++ src/modules/lib/stdlibc/math/fcos.c | 85 ++++++++++++++++++++++ src/modules/lib/stdlibc/math/fexp.c | 72 ++++++++++++++++++ src/modules/lib/stdlibc/math/fldexp.c | 58 +++++++++++++++ src/modules/lib/stdlibc/math/flog.c | 128 +++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/math/fsin.c | 83 +++++++++++++++++++++ src/modules/lib/stdlibc/math/fsqrt.c | 64 ++++++++++++++++ src/modules/lib/stdlibc/math/ftan.c | 101 ++++++++++++++++++++++++++ 10 files changed, 735 insertions(+), 62 deletions(-) delete mode 100644 src/modules/lib/stdlibc/math.c create mode 100644 src/modules/lib/stdlibc/math/fabs.c create mode 100644 src/modules/lib/stdlibc/math/fcos.c create mode 100644 src/modules/lib/stdlibc/math/fexp.c create mode 100644 src/modules/lib/stdlibc/math/fldexp.c create mode 100644 src/modules/lib/stdlibc/math/flog.c create mode 100644 src/modules/lib/stdlibc/math/fsin.c create mode 100644 src/modules/lib/stdlibc/math/fsqrt.c create mode 100644 src/modules/lib/stdlibc/math/ftan.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 8be2d9c..49083ab 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -1,8 +1,8 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Patrick Kaufmann. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,26 +13,86 @@ * 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 + * 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 + * 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 _MATH_H_ #define _MATH_H_ -#include -// Betrag einer reelen Zahl errechen -#ifndef CONFIG_LIBC_NO_STUBS -double fabs(double x); -#endif +#define NAN (__builtin_nanf ("")) +#define INFINITY (__builtin_inff ()) +#define HUGE_VAL (__builtin_huge_val()) +#define MAXFLOAT 3.4028234663852886e+38 + + +#define M_E 2.71828182845904523536 +#define M_LOG2E 1.44269504088896340735 +#define M_LOG10E 0.43429448190325182765 +#define M_LN2 0.69314718055994530942 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.70710678118654752440 + + + +double tan(double); +float tanf(float); +long double tanl(long double); +double sqrt(double); +float sqrtf(float); +long double sqrtl(long double); +double sin(double); +float sinf(float); +long double sinl(long double); +double log2(double); +float log2f(float); +long double log2l(long double); +double log10(double); +float log10f(float); +long double log10l(long double); +double log(double); +float logf(float); +long double logl(long double); +double ldexp(double, int); +float ldexpf(float, int); +long double ldexpl(long double, int); +double fabs(double); +float fabsf(float); +long double fabsl(long double); +double exp(double); +float expf(float); +long double expl(long double); +double cos(double); +float cosf(float); +long double cosl(long double); +double atan(double); +float atanf(float); +long double atanl(long double); +double atan2(double, double); +float atan2f(float, float); +long double atan2l(long double, long double); +double asin(double); +float asinf(float); +long double asinl(long double); +double acos(double); +float acosf(float); +long double acosl(long double); #endif + diff --git a/src/modules/lib/stdlibc/math.c b/src/modules/lib/stdlibc/math.c deleted file mode 100644 index 76d437f..0000000 --- a/src/modules/lib/stdlibc/math.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2007 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. - */ - -#include -#include -#include - -// FIXME: Nur bis der Float-Kram vom Kernel unterstuetzt wird -#ifndef CONFIG_LIBC_NO_STUBS - -/** - * Betrag einer reellen Zahl errechnen - */ -double fabs(double x) -{ - return ((x < 0) ? -x : x); -} - -#endif - diff --git a/src/modules/lib/stdlibc/math/fabs.c b/src/modules/lib/stdlibc/math/fabs.c new file mode 100644 index 0000000..59633da --- /dev/null +++ b/src/modules/lib/stdlibc/math/fabs.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double fabs(double x) +{ + double res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + +float fabsf(float x) +{ + float res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + +long double fabsl(long double x) +{ + long double res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fcos.c b/src/modules/lib/stdlibc/math/fcos.c new file mode 100644 index 0000000..06d2d7d --- /dev/null +++ b/src/modules/lib/stdlibc/math/fcos.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pio2 1.570796326794896619 + +double cos(double x) +{ + double res; + asm("fcos;" : "=t" (res) : "0" (x)); + return res; +} + +float cosf(float x) +{ + float res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +long double cosl(long double x) +{ + long double res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +double acos(double x) { + double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +float acosf(float x) { + float res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +long double acosl(long double x) { + long double res; + if (x <= -1 || x >= 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fexp.c b/src/modules/lib/stdlibc/math/fexp.c new file mode 100644 index 0000000..9d7fc3d --- /dev/null +++ b/src/modules/lib/stdlibc/math/fexp.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double exp(double x) +{ + return expl(x); +} + +float expf(float x) +{ + return expl(x); +} + +long double expl(long double x) +{ + long double res; + asm(// st0 = x + "fldl2e;" // Laedt log2e + // st0 log2(e), st1 = x + "fmulp;" // Multipliziert mit x + // st0 = x*log2(e) + "fld %%st(0);" // + // st0 = st1 = x*log2(e) + "frndint;" + // st0 = int(x*log2(e)), st1 = x*log2(e) + "fld1;" + // st0 = 1, st1 = int(x*log2(e)), st2 = x*log2(e) + "fscale;" + // st0 = 2**(int(x*log2(e))), st1 = int(x*log2(e)), st2 = x*log2(e) + "fxch %%st(2);" + // st0 = x*log2(e), st1 = int(x*log2(e)), st2 = 2**(int(x*log2(e))) + "fsubp %%st(1);" + // st0 = x*log2(e) - int(x*log2(e)), st1 = 2**(int(x*log2(e))) + "f2xm1;" + // st0 = 2**(x*log2(e) - int(x*log2(e))) - 1, st1 = 2**(int(x*log2(e))) + "fld1;" + // st0 = 1, st1 = 2**(x*log2(e) - int(x*log2(e))) - 1, st2 = 2**(int(x*log2(e))) + "faddp;" + // st0 = 2**(x*log2(e) - int(x*log2(e))), st1 = 2**(int(x*log2(e))) + "fmulp" : "=t" (res) : "0" (x)); + + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fldexp.c b/src/modules/lib/stdlibc/math/fldexp.c new file mode 100644 index 0000000..eaea5cc --- /dev/null +++ b/src/modules/lib/stdlibc/math/fldexp.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double ldexp(double x, int exp) +{ + double res; + double e = exp; + asm("fscale;" + "fst %%st(0)" : "=t" (res) : "0" (x), "u" (e)); + return res; +} + +float ldexpf(float x, int exp) +{ + float res; + float e = exp; + asm("fscale;" + "fst %%st(0)": "=t" (res) : "0" (x), "u" (e)); + return res; +} + +long double ldexpl(long double x, int exp) +{ + long double res; + long double e = exp; + asm("fscale;" + "fst %%st(0)": "=t" (res) : "0" (x), "u" (e)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/flog.c b/src/modules/lib/stdlibc/math/flog.c new file mode 100644 index 0000000..ffe839e --- /dev/null +++ b/src/modules/lib/stdlibc/math/flog.c @@ -0,0 +1,128 @@ +#include "math.h" +#include + +double log2(double x) { + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float log2f(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + + +long double log2l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +double log(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float logf(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +long double logl(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fldl2e;" + "fyl2x;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + + +double log10(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fldl2t;" + "fyl2x;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +float log10f(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fldl2t;" + "fyl2x;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +long double log10l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fldl2t;" + "fyl2x;" + "fdivp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + diff --git a/src/modules/lib/stdlibc/math/fsin.c b/src/modules/lib/stdlibc/math/fsin.c new file mode 100644 index 0000000..e274d5a --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsin.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double sin(double x) +{ + double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +float sinf(float x) +{ + float res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +long double sinl(long double x) +{ + long double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +double asin(double x) { + double res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + +float asinf(float x) { + float res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = 2 * atanf(x / (1 + sqrtf(1 - (x * x)))); + return res; +} + +long double asinl(long double x) { + long double res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = 2 * atanl(x / (1 + sqrtl(1 - (x * x)))); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fsqrt.c b/src/modules/lib/stdlibc/math/fsqrt.c new file mode 100644 index 0000000..be1b2b3 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsqrt.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +long double sqrtl(long double x) +{ + long double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + +double sqrt(double x) +{ + double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + +float sqrtf(float x) +{ + float res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c new file mode 100644 index 0000000..ffb113a --- /dev/null +++ b/src/modules/lib/stdlibc/math/ftan.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pi 3.1415926535897932384 +#define pio2 1.570796326794896619 + + +double tan(double x) +{ + double res; + asm("fptan;" + "fstp %%st(0)": "=t" (res) : "0" (x)); + return res; +} + +float tanf(float x) +{ + float res; + asm("fptan;" + "fstp %%st(0)": "=t" (res) : "0" (x)); + return res; +} + +long double tanl(long double x) +{ + long double res; + asm("fptan;" + "fstp %%st(0)": "=t" (res) : "0" (x)); + return res; +} + +double atan(double x) +{ + + double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +float atanf(float x) +{ + float res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + + +long double atanl(long double x) +{ + long double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +double atan2(double x, double y) { + double res; + asm("fpatan" : "=t" (res) : "0" (x), "u" (y)); + return res; +} + + +float atan2f(float x, float y) { + float res; + asm("fpatan" : "=t" (res) : "0" (x), "u" (y)); + return res; +} + +long double atan2l(long double x, long double y) { + long double res; + asm("fpatan" : "=t" (res) : "0" (x), "u" (y)); + return res; +} + -- 1.6.3.3 From alex at tyndur.org Sun Aug 9 11:09:29 2009 From: alex at tyndur.org (Alexander Siol) Date: Sun, 9 Aug 2009 11:09:29 +0200 Subject: [tyndur-devel] [PATCH] ls: Versteckte Dateien, Mehrere Verzeichnisse listen In-Reply-To: <1249767550-4905-1-git-send-email-alex@tyndur.org> References: <1249767550-4905-1-git-send-email-alex@tyndur.org> Message-ID: <1249808969-13464-1-git-send-email-alex@tyndur.org> +ls: Erkennung & Handhabung versteckter Dateien +ls: Mehrere Verzeichnisse können zum auflisten angegeben werden *ls: Umstellung auf getopt für weitere Erweiterungen Signed-off-by: Alexander Siol --- trunk/src/modules/c/shell/cmds/ls.c | 140 ++++++++++++++++++++++++++-------- 1 files changed, 107 insertions(+), 33 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/ls.c b/trunk/src/modules/c/shell/cmds/ls.c index 195f769..59b235f 100644 --- a/trunk/src/modules/c/shell/cmds/ls.c +++ b/trunk/src/modules/c/shell/cmds/ls.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Antoine Kaufmann, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,8 +39,11 @@ #include "dir.h" #include "unistd.h" #include +#include +#include void ls_display_usage(void); +char* format_size(size_t size, bool human_readable); #ifdef CONFIG_SHELL_BUILTIN_ONLY int shell_command_ls(int argc, char* argv[], const char* args) @@ -48,46 +51,92 @@ void ls_display_usage(void); int main(int argc, char* argv[]) #endif { - if (argc > 2) { - ls_display_usage(); - return -1; - } - char* dir_path; - bool free_dir_path; + char* cwd_dir = NULL; bool success = TRUE; + bool show_hidden = FALSE; + bool human_readable = FALSE; + list_t *dirs = list_create(); + bool print_dirnames = FALSE; - if (argc == 1) { - //Mit NULL als Parameter wird der buffer mit malloc() erstellt - dir_path = getcwd(NULL, 0); - free_dir_path = TRUE; - } else { - dir_path = argv[1]; - free_dir_path = FALSE; - } + static const struct option long_options[] = + { + { "all", no_argument, 0, 'a' }, + { "help", no_argument, 0, 1 }, + { "human-readable", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + optind = 0; - io_resource_t* dir_res = directory_open(dir_path); - if (dir_res != NULL) { - io_direntry_t* direntry; - while ((direntry = directory_read(dir_res))) { - if (direntry->type == IO_DIRENTRY_FILE) { - printf(" %s\n", direntry->name); - } else { - printf(" [DIR] %s\n", direntry->name); - } - free(direntry); + while (optind < argc) { + int result = getopt_long(argc, argv, "ah", long_options, NULL); + if (result == -1) { + break; + } + switch (result) { + case 'a': + show_hidden = TRUE; + break; + case 'h': + human_readable = TRUE; + break; + case 1: + ls_display_usage(); + return EXIT_SUCCESS; + default: + break; } + } - directory_close(dir_res); - } else { - printf("Konnte '%s' nicht zum lesen oeffnen!\n", dir_path); - success = FALSE; + while (optind < argc) { + list_push(dirs, argv[optind++]); } - if (free_dir_path == TRUE) { - free(dir_path); + if (list_size(dirs) == 0) { + cwd_dir = getcwd(NULL, 0); + list_push(dirs, cwd_dir); + } + + if (list_size(dirs) > 1) { + print_dirnames = TRUE; } + + while ((dir_path = list_pop(dirs))) { + if (print_dirnames) { + printf("%s:\n", dir_path); + } + io_resource_t* dir_res = directory_open(dir_path); + if (dir_res != NULL) { + io_direntry_t* direntry; + while ((direntry = directory_read(dir_res))) { + bool entry_hidden = (*direntry->name == '.'); + if (!entry_hidden || show_hidden) { + if (direntry->type == IO_DIRENTRY_FILE) { + printf(" %06s %s\n", format_size(direntry->size, + human_readable), direntry->name); + } else { + printf(" [DIR] %06s %s\n", format_size(direntry->size, + human_readable), direntry->name); + } + } + free(direntry); + } + + directory_close(dir_res); + } else { + printf("Konnte '%s' nicht zum lesen öffnen!\n", dir_path); + success = FALSE; + } + if (list_size(dirs) > 0) { + printf("\n"); + } + } + + free(cwd_dir); + + + list_destroy(dirs); if (success == TRUE) { return EXIT_SUCCESS; @@ -96,8 +145,33 @@ void ls_display_usage(void); } } +char* format_size(size_t size, bool human_readable) +{ + char* retval = NULL; + if (!human_readable) { + asprintf(&retval, "% 6d", size); + } else { + int unit = 0; + char units[] = " KMGT"; + while (size > 1024 && units[unit]) { + size /= 1024; + unit++; + } + if (unit == 0) { + asprintf(&retval, "% 6d", size); + } else { + asprintf(&retval, " % 4d%c", size, units[unit]); + } + } + return retval; +} + void ls_display_usage() { - puts("\nAufruf: ls [Verzeichnis]\n"); + puts("\nAufruf: ls [Optionen] [Verzeichnisse]\n"); + puts(" -a, --all zeigt versteckte Dateien an"); + puts(" -h, --human-readable zeigt die Dateigröße menschenlesbar an " + "(z.b. 10M, 1G)"); + puts(" --help zeigt diese Hilfe an"); } -- 1.5.6.5 From alex at tyndur.org Sun Aug 9 11:10:31 2009 From: alex at tyndur.org (Alexander Siol) Date: Sun, 9 Aug 2009 11:10:31 +0200 Subject: [tyndur-devel] [PATCH] bincat: Positionsangabe moeglich (wird auf 1k-Bloecke gerundet) In-Reply-To: <1249769359-8569-1-git-send-email-alex@tyndur.org> References: <1249769359-8569-1-git-send-email-alex@tyndur.org> Message-ID: <1249809031-13525-1-git-send-email-alex@tyndur.org> +bincat: Positionsangaben (Start, Länge und Ende) *bincat: Umstellung auf getopt --- trunk/src/modules/c/shell/cmds/bincat.c | 104 ++++++++++++++++++++++++++++--- 1 files changed, 96 insertions(+), 8 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/bincat.c b/trunk/src/modules/c/shell/cmds/bincat.c index 8c0372e..c8fd907 100644 --- a/trunk/src/modules/c/shell/cmds/bincat.c +++ b/trunk/src/modules/c/shell/cmds/bincat.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Antoine Kaufmann, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,35 +38,116 @@ #include "stdio.h" #include "unistd.h" #include +#include +#include #define BLOCK_SIZE 1024 void bincat_display_usage(void); +#define min(a,b) (a < b)?(a):(b); + #ifdef CONFIG_SHELL_BUILTIN_ONLY int shell_command_bincat(int argc, char* argv[], const char* args) #else int main(int argc, char* argv[]) #endif { - if (argc != 2) { + static const struct option long_options[] = + { + { "start", required_argument, 0, 's' }, + { "length", required_argument, 0, 'l' }, + { "end", required_argument, 0, 'e' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + optind = 0; + uint64_t start = 0; + uint64_t end = 0; + uint64_t length = 0; + char *path = NULL; + int n = 0; + int m = 0; + size_t total_read = 0; + + + while (optind < argc) { + int result = getopt_long(argc, argv, "s:l:e:h", long_options, NULL); + if (result == -1) { + break; + } + errno = 0; + switch (result) { + case 's': + start = strtoull(optarg, NULL, 0); + if (errno) { + printf("Ihre Startangabe war ungültig!\n"); + start = 0; + } + break; + case 'l': + length = strtoull(optarg, NULL, 0); + if (errno) { + printf("Ihre Längenangabe war ungültig!\n"); + start = 0; + } + break; + case 'e': + end = strtoull(optarg, NULL, 0); + if (errno) { + printf("Ihre Endangabe war ungültig!\n"); + start = 0; + } + break; + case 'h': + bincat_display_usage(); + return EXIT_SUCCESS; + default: + break; + } + } + + if (length && end) { + printf("--length und --end schließen sich aus. Verwende --length\n"); + } else if (end) { + length = end - start; + } + + if (optind == argc) { bincat_display_usage(); + return EXIT_SUCCESS; + } + + if (optind + 1 == argc) { + path = argv[optind]; + } else { + printf("Fehler: bincat kann nur eine Datei auf einmal verarbeiten!\n"); return -1; } - char* path = argv[1]; + if (path == NULL) { + bincat_display_usage(); + return EXIT_SUCCESS; + } + FILE* file = fopen(path, "r"); + fseek(file, start, SEEK_SET); + m = start / 8; + if (file == NULL) { printf("Konnte '%s' nicht zum lesen oeffnen!\n", path); return -1; } else { char buffer[BLOCK_SIZE]; size_t size; - int n, m = 0; - while (feof(file) != EOF) { + while (feof(file) != EOF && (total_read <= length || length == 0)) { + size = fread(buffer, 1, BLOCK_SIZE, file); + total_read += size; + printf("0x%08x: ", m); for (n=0; n < size; n++) { @@ -82,12 +163,19 @@ void bincat_display_usage(void); fclose(file); } - + printf("\n"); return EXIT_SUCCESS; } void bincat_display_usage() { - puts("\nAufruf: bincat "); + puts("\nAufruf: bincat [Optionen] \n"); + puts(" -s, --start Gibt die Startposition an"); + puts(" -l, --length Gibt die Ausgabelänge an"); + puts(" -e, --end Gibt die Endposition an\n"); + puts("Falls --length und --end angegeben sind, erhält --length den " + "Vorrang.\n"); + puts("Position und Längen können optional via vorangestelltem 0x auch " + "Hexadezimal\n angegeben werden."); } -- 1.5.6.5 From patrick at tyndur.org Sun Aug 9 11:14:39 2009 From: patrick at tyndur.org (Patrick Kaufmann) Date: Sun, 9 Aug 2009 11:14:39 +0200 Subject: [tyndur-devel] [PATCH] Libc: Erstes Stueck richtige libm In-Reply-To: <20090808152542.GB4812@debws.produktiv.lan> References: <20090808152542.GB4812@debws.produktiv.lan> Message-ID: <1249809279-6590-1-git-send-email-patrick@tyndur.org> From: patrick + Libc: Erstes Stueck richtige libm Signed-off-by: Patrick Kaufmann --- src/modules/include/math.h | 94 ++++++++++++++++++++----- src/modules/lib/stdlibc/math.c | 45 ------------ src/modules/lib/stdlibc/math/fabs.c | 67 +++++++++++++++++ src/modules/lib/stdlibc/math/fcos.c | 85 ++++++++++++++++++++++ src/modules/lib/stdlibc/math/fexp.c | 72 ++++++++++++++++++ src/modules/lib/stdlibc/math/fldexp.c | 58 +++++++++++++++ src/modules/lib/stdlibc/math/flog.c | 128 +++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/math/fsin.c | 83 +++++++++++++++++++++ src/modules/lib/stdlibc/math/fsqrt.c | 64 ++++++++++++++++ src/modules/lib/stdlibc/math/ftan.c | 100 +++++++++++++++++++++++++ 10 files changed, 734 insertions(+), 62 deletions(-) delete mode 100644 src/modules/lib/stdlibc/math.c create mode 100644 src/modules/lib/stdlibc/math/fabs.c create mode 100644 src/modules/lib/stdlibc/math/fcos.c create mode 100644 src/modules/lib/stdlibc/math/fexp.c create mode 100644 src/modules/lib/stdlibc/math/fldexp.c create mode 100644 src/modules/lib/stdlibc/math/flog.c create mode 100644 src/modules/lib/stdlibc/math/fsin.c create mode 100644 src/modules/lib/stdlibc/math/fsqrt.c create mode 100644 src/modules/lib/stdlibc/math/ftan.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 8be2d9c..49083ab 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -1,8 +1,8 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Patrick Kaufmann. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,26 +13,86 @@ * 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 + * 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 + * 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 _MATH_H_ #define _MATH_H_ -#include -// Betrag einer reelen Zahl errechen -#ifndef CONFIG_LIBC_NO_STUBS -double fabs(double x); -#endif +#define NAN (__builtin_nanf ("")) +#define INFINITY (__builtin_inff ()) +#define HUGE_VAL (__builtin_huge_val()) +#define MAXFLOAT 3.4028234663852886e+38 + + +#define M_E 2.71828182845904523536 +#define M_LOG2E 1.44269504088896340735 +#define M_LOG10E 0.43429448190325182765 +#define M_LN2 0.69314718055994530942 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.70710678118654752440 + + + +double tan(double); +float tanf(float); +long double tanl(long double); +double sqrt(double); +float sqrtf(float); +long double sqrtl(long double); +double sin(double); +float sinf(float); +long double sinl(long double); +double log2(double); +float log2f(float); +long double log2l(long double); +double log10(double); +float log10f(float); +long double log10l(long double); +double log(double); +float logf(float); +long double logl(long double); +double ldexp(double, int); +float ldexpf(float, int); +long double ldexpl(long double, int); +double fabs(double); +float fabsf(float); +long double fabsl(long double); +double exp(double); +float expf(float); +long double expl(long double); +double cos(double); +float cosf(float); +long double cosl(long double); +double atan(double); +float atanf(float); +long double atanl(long double); +double atan2(double, double); +float atan2f(float, float); +long double atan2l(long double, long double); +double asin(double); +float asinf(float); +long double asinl(long double); +double acos(double); +float acosf(float); +long double acosl(long double); #endif + diff --git a/src/modules/lib/stdlibc/math.c b/src/modules/lib/stdlibc/math.c deleted file mode 100644 index 76d437f..0000000 --- a/src/modules/lib/stdlibc/math.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2007 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. - */ - -#include -#include -#include - -// FIXME: Nur bis der Float-Kram vom Kernel unterstuetzt wird -#ifndef CONFIG_LIBC_NO_STUBS - -/** - * Betrag einer reellen Zahl errechnen - */ -double fabs(double x) -{ - return ((x < 0) ? -x : x); -} - -#endif - diff --git a/src/modules/lib/stdlibc/math/fabs.c b/src/modules/lib/stdlibc/math/fabs.c new file mode 100644 index 0000000..b1f407f --- /dev/null +++ b/src/modules/lib/stdlibc/math/fabs.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double fabs(double x) +{ + double res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + +float fabsf(float x) +{ + float res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + +long double fabsl(long double x) +{ + long double res; + if (x < 0.0) { + res = -x; + } + else { + res = x; + } + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fcos.c b/src/modules/lib/stdlibc/math/fcos.c new file mode 100644 index 0000000..ff69b2c --- /dev/null +++ b/src/modules/lib/stdlibc/math/fcos.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pio2 1.570796326794896619 + +double cos(double x) +{ + double res; + asm("fcos;" : "=t" (res) : "0" (x)); + return res; +} + +float cosf(float x) +{ + float res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +long double cosl(long double x) +{ + long double res; + asm("fcos" : "=t" (res) : "0" (x)); + return res; +} + +double acos(double x) { + double res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +float acosf(float x) { + float res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + +long double acosl(long double x) { + long double res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = pio2 - asin(x); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fexp.c b/src/modules/lib/stdlibc/math/fexp.c new file mode 100644 index 0000000..9d7fc3d --- /dev/null +++ b/src/modules/lib/stdlibc/math/fexp.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double exp(double x) +{ + return expl(x); +} + +float expf(float x) +{ + return expl(x); +} + +long double expl(long double x) +{ + long double res; + asm(// st0 = x + "fldl2e;" // Laedt log2e + // st0 log2(e), st1 = x + "fmulp;" // Multipliziert mit x + // st0 = x*log2(e) + "fld %%st(0);" // + // st0 = st1 = x*log2(e) + "frndint;" + // st0 = int(x*log2(e)), st1 = x*log2(e) + "fld1;" + // st0 = 1, st1 = int(x*log2(e)), st2 = x*log2(e) + "fscale;" + // st0 = 2**(int(x*log2(e))), st1 = int(x*log2(e)), st2 = x*log2(e) + "fxch %%st(2);" + // st0 = x*log2(e), st1 = int(x*log2(e)), st2 = 2**(int(x*log2(e))) + "fsubp %%st(1);" + // st0 = x*log2(e) - int(x*log2(e)), st1 = 2**(int(x*log2(e))) + "f2xm1;" + // st0 = 2**(x*log2(e) - int(x*log2(e))) - 1, st1 = 2**(int(x*log2(e))) + "fld1;" + // st0 = 1, st1 = 2**(x*log2(e) - int(x*log2(e))) - 1, st2 = 2**(int(x*log2(e))) + "faddp;" + // st0 = 2**(x*log2(e) - int(x*log2(e))), st1 = 2**(int(x*log2(e))) + "fmulp" : "=t" (res) : "0" (x)); + + return res; +} + diff --git a/src/modules/lib/stdlibc/math/fldexp.c b/src/modules/lib/stdlibc/math/fldexp.c new file mode 100644 index 0000000..eaea5cc --- /dev/null +++ b/src/modules/lib/stdlibc/math/fldexp.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double ldexp(double x, int exp) +{ + double res; + double e = exp; + asm("fscale;" + "fst %%st(0)" : "=t" (res) : "0" (x), "u" (e)); + return res; +} + +float ldexpf(float x, int exp) +{ + float res; + float e = exp; + asm("fscale;" + "fst %%st(0)": "=t" (res) : "0" (x), "u" (e)); + return res; +} + +long double ldexpl(long double x, int exp) +{ + long double res; + long double e = exp; + asm("fscale;" + "fst %%st(0)": "=t" (res) : "0" (x), "u" (e)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/flog.c b/src/modules/lib/stdlibc/math/flog.c new file mode 100644 index 0000000..ea3862f --- /dev/null +++ b/src/modules/lib/stdlibc/math/flog.c @@ -0,0 +1,128 @@ +#include "math.h" +#include + +double log2(double x) { + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float log2f(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + + +long double log2l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +double log(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +float logf(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; +} + +long double logl(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2e;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + + +double log10(double x) +{ + double one = 1; + double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +float log10f(float x) +{ + float one = 1; + float res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + +long double log10l(long double x) +{ + long double one = 1; + long double res; + if (x <= 0.0) { + errno = EDOM; + return NAN; + } + asm("fyl2x;" + "fldl2t;" + "fdivrp" : "=t" (res) : "0" (x), "u" (one)); + return res; + +} + diff --git a/src/modules/lib/stdlibc/math/fsin.c b/src/modules/lib/stdlibc/math/fsin.c new file mode 100644 index 0000000..e274d5a --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsin.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +double sin(double x) +{ + double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +float sinf(float x) +{ + float res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +long double sinl(long double x) +{ + long double res; + asm("fsin" : "=t" (res) : "0" (x)); + return res; +} + +double asin(double x) { + double res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = 2 * atan(x / (1 + sqrt(1 - (x * x)))); + return res; +} + +float asinf(float x) { + float res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = 2 * atanf(x / (1 + sqrtf(1 - (x * x)))); + return res; +} + +long double asinl(long double x) { + long double res; + if (x < -1 || x > 1) { + errno = EDOM; + return NAN; + } + res = 2 * atanl(x / (1 + sqrtl(1 - (x * x)))); + return res; +} + + diff --git a/src/modules/lib/stdlibc/math/fsqrt.c b/src/modules/lib/stdlibc/math/fsqrt.c new file mode 100644 index 0000000..be1b2b3 --- /dev/null +++ b/src/modules/lib/stdlibc/math/fsqrt.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +long double sqrtl(long double x) +{ + long double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + +double sqrt(double x) +{ + double res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + +float sqrtf(float x) +{ + float res; + if (x < 0.0) { + errno = EDOM; + return NAN; + } + asm("fsqrt" : "=t" (res) : "0" (x)); + return res; +} + diff --git a/src/modules/lib/stdlibc/math/ftan.c b/src/modules/lib/stdlibc/math/ftan.c new file mode 100644 index 0000000..3919ee7 --- /dev/null +++ b/src/modules/lib/stdlibc/math/ftan.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Patrick 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. + */ + +#include "math.h" +#include + +#define pi 3.1415926535897932384 +#define pio2 1.570796326794896619 + + +double tan(double x) +{ + double res; + asm("fptan;" + "fstp %%st(0)": "=t" (res) : "0" (x)); + return res; +} + +float tanf(float x) +{ + float res; + asm("fptan;" + "fstp %%st(0)": "=t" (res) : "0" (x)); + return res; +} + +long double tanl(long double x) +{ + long double res; + asm("fptan;" + "fstp %%st(0)": "=t" (res) : "0" (x)); + return res; +} + +double atan(double x) +{ + double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +float atanf(float x) +{ + float res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + + +long double atanl(long double x) +{ + long double res; + asm("fld1; fpatan" : "=t" (res) : "0" (x)); + return res; +} + +double atan2(double x, double y) { + double res; + asm("fpatan" : "=t" (res) : "0" (y), "u" (x)); + return res; +} + + +float atan2f(float x, float y) { + float res; + asm("fpatan" : "=t" (res) : "0" (y), "u" (x)); + return res; +} + +long double atan2l(long double x, long double y) { + long double res; + asm("fpatan" : "=t" (res) : "0" (y), "u" (x)); + return res; +} + -- 1.6.3.3 From kevin at tyndur.org Sun Aug 9 11:17:50 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 9 Aug 2009 11:17:50 +0200 Subject: [tyndur-devel] [PATCH] ls: Versteckte Dateien, Mehrere Verzeichnisse listen In-Reply-To: <1249808969-13464-1-git-send-email-alex@tyndur.org> References: <1249767550-4905-1-git-send-email-alex@tyndur.org> <1249808969-13464-1-git-send-email-alex@tyndur.org> Message-ID: <20090809091750.GD3435@debws.produktiv.lan> On Sun, Aug 09, 2009 at 11:09:29AM +0200, Alexander Siol wrote: > +ls: Erkennung & Handhabung versteckter Dateien > +ls: Mehrere Verzeichnisse können zum auflisten angegeben werden > *ls: Umstellung auf getopt für weitere Erweiterungen > > Signed-off-by: Alexander Siol > --- > trunk/src/modules/c/shell/cmds/ls.c | 140 ++++++++++++++++++++++++++-------- > 1 files changed, 107 insertions(+), 33 deletions(-) > > diff --git a/trunk/src/modules/c/shell/cmds/ls.c b/trunk/src/modules/c/shell/cmds/ls.c > index 195f769..59b235f 100644 > --- a/trunk/src/modules/c/shell/cmds/ls.c > +++ b/trunk/src/modules/c/shell/cmds/ls.c > @@ -1,8 +1,8 @@ > /* > - * Copyright (c) 2007 The tyndur Project. All rights reserved. > + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > - * by Antoine Kaufmann. > + * by Antoine Kaufmann, Alexander Siol > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -39,8 +39,11 @@ > #include "dir.h" > #include "unistd.h" > #include > +#include > +#include > > void ls_display_usage(void); > +char* format_size(size_t size, bool human_readable); > > #ifdef CONFIG_SHELL_BUILTIN_ONLY > int shell_command_ls(int argc, char* argv[], const char* args) > @@ -48,46 +51,92 @@ void ls_display_usage(void); > int main(int argc, char* argv[]) > #endif > { > - if (argc > 2) { > - ls_display_usage(); > - return -1; > - } > - > char* dir_path; > - bool free_dir_path; > + char* cwd_dir = NULL; > bool success = TRUE; > + bool show_hidden = FALSE; > + bool human_readable = FALSE; > + list_t *dirs = list_create(); > + bool print_dirnames = FALSE; > > - if (argc == 1) { > - //Mit NULL als Parameter wird der buffer mit malloc() erstellt > - dir_path = getcwd(NULL, 0); > - free_dir_path = TRUE; > - } else { > - dir_path = argv[1]; > - free_dir_path = FALSE; > - } > + static const struct option long_options[] = > + { > + { "all", no_argument, 0, 'a' }, > + { "help", no_argument, 0, 1 }, > + { "human-readable", no_argument, 0, 'h' }, > + { 0, 0, 0, 0 } > + }; > > + optind = 0; > > - io_resource_t* dir_res = directory_open(dir_path); > - if (dir_res != NULL) { > - io_direntry_t* direntry; > - while ((direntry = directory_read(dir_res))) { > - if (direntry->type == IO_DIRENTRY_FILE) { > - printf(" %s\n", direntry->name); > - } else { > - printf(" [DIR] %s\n", direntry->name); > - } > - free(direntry); > + while (optind < argc) { > + int result = getopt_long(argc, argv, "ah", long_options, NULL); > + if (result == -1) { > + break; > + } > + switch (result) { > + case 'a': > + show_hidden = TRUE; > + break; > + case 'h': > + human_readable = TRUE; > + break; > + case 1: > + ls_display_usage(); > + return EXIT_SUCCESS; > + default: > + break; > } > + } > > - directory_close(dir_res); > - } else { > - printf("Konnte '%s' nicht zum lesen oeffnen!\n", dir_path); > - success = FALSE; > + while (optind < argc) { > + list_push(dirs, argv[optind++]); > } > > - if (free_dir_path == TRUE) { > - free(dir_path); > + if (list_size(dirs) == 0) { > + cwd_dir = getcwd(NULL, 0); > + list_push(dirs, cwd_dir); > + } Whitespace > + > + if (list_size(dirs) > 1) { > + print_dirnames = TRUE; > } > + > + while ((dir_path = list_pop(dirs))) { > + if (print_dirnames) { > + printf("%s:\n", dir_path); > + } > + io_resource_t* dir_res = directory_open(dir_path); > + if (dir_res != NULL) { > + io_direntry_t* direntry; > + while ((direntry = directory_read(dir_res))) { > + bool entry_hidden = (*direntry->name == '.'); > + if (!entry_hidden || show_hidden) { > + if (direntry->type == IO_DIRENTRY_FILE) { > + printf(" %06s %s\n", format_size(direntry->size, > + human_readable), direntry->name); Wer gibt den Rückgabewert von format_size wieder frei? > + } else { > + printf(" [DIR] %06s %s\n", format_size(direntry->size, > + human_readable), direntry->name); > + } > + } > + free(direntry); > + } > + Whitespace > + directory_close(dir_res); > + } else { > + printf("Konnte '%s' nicht zum lesen öffnen!\n", dir_path); > + success = FALSE; > + } > + if (list_size(dirs) > 0) { > + printf("\n"); > + } > + } > + > + free(cwd_dir); > + > + > + list_destroy(dirs); > > if (success == TRUE) { > return EXIT_SUCCESS; > @@ -96,8 +145,33 @@ void ls_display_usage(void); > } > } > > +char* format_size(size_t size, bool human_readable) > +{ > + char* retval = NULL; > + if (!human_readable) { > + asprintf(&retval, "% 6d", size); Sechs Zeichen ist etwas knapp für Dateigrößen. Besser neun oder so. > + } else { > + int unit = 0; > + char units[] = " KMGT"; > + while (size > 1024 && units[unit]) { > + size /= 1024; > + unit++; > + } > + if (unit == 0) { > + asprintf(&retval, "% 6d", size); > + } else { > + asprintf(&retval, " % 4d%c", size, units[unit]); > + } > + } > + return retval; > +} > + > void ls_display_usage() > { > - puts("\nAufruf: ls [Verzeichnis]\n"); > + puts("\nAufruf: ls [Optionen] [Verzeichnisse]\n"); > + puts(" -a, --all zeigt versteckte Dateien an"); > + puts(" -h, --human-readable zeigt die Dateigröße menschenlesbar an " > + "(z.b. 10M, 1G)"); > + puts(" --help zeigt diese Hilfe an"); > } Sieht ansonsten gut aus. Kann rein, wenn das gefixt ist From toni at tyndur.org Sun Aug 9 16:35:57 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 9 Aug 2009 16:35:57 +0200 Subject: [tyndur-devel] [PATCH] bincat: Positionsangabe moeglich (wird auf 1k-Bloecke gerundet) In-Reply-To: <1249809031-13525-1-git-send-email-alex@tyndur.org> References: <1249769359-8569-1-git-send-email-alex@tyndur.org> <1249809031-13525-1-git-send-email-alex@tyndur.org> Message-ID: <20090809143557.GB28946@einstein.kaufmann.lan> On Sun, Aug 09 11:10, Alexander Siol wrote: > +bincat: Positionsangaben (Start, Länge und Ende) > *bincat: Umstellung auf getopt > --- > trunk/src/modules/c/shell/cmds/bincat.c | 104 ++++++++++++++++++++++++++++--- > 1 files changed, 96 insertions(+), 8 deletions(-) > > diff --git a/trunk/src/modules/c/shell/cmds/bincat.c b/trunk/src/modules/c/shell/cmds/bincat.c > index 8c0372e..c8fd907 100644 > --- a/trunk/src/modules/c/shell/cmds/bincat.c > +++ b/trunk/src/modules/c/shell/cmds/bincat.c > @@ -1,8 +1,8 @@ > /* > - * Copyright (c) 2007 The tyndur Project. All rights reserved. > + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > - * by Antoine Kaufmann. > + * by Antoine Kaufmann, Alexander Siol > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -38,35 +38,116 @@ > #include "stdio.h" > #include "unistd.h" > #include > +#include > +#include > > #define BLOCK_SIZE 1024 > > void bincat_display_usage(void); > > +#define min(a,b) (a < b)?(a):(b); Weg damit, wird ja, soweit ich sehe nicht benutzt > + > #ifdef CONFIG_SHELL_BUILTIN_ONLY > int shell_command_bincat(int argc, char* argv[], const char* args) > #else > int main(int argc, char* argv[]) > #endif > { > - if (argc != 2) { > + static const struct option long_options[] = > + { > + { "start", required_argument, 0, 's' }, > + { "length", required_argument, 0, 'l' }, > + { "end", required_argument, 0, 'e' }, > + { "help", no_argument, 0, 'h' }, > + { 0, 0, 0, 0 } > + }; > + > + optind = 0; > + uint64_t start = 0; > + uint64_t end = 0; > + uint64_t length = 0; > + char *path = NULL; > + int n = 0; > + int m = 0; > + size_t total_read = 0; > + > + > + while (optind < argc) { > + int result = getopt_long(argc, argv, "s:l:e:h", long_options, NULL); > + if (result == -1) { > + break; > + } > + errno = 0; > + switch (result) { > + case 's': > + start = strtoull(optarg, NULL, 0); > + if (errno) { > + printf("Ihre Startangabe war ungültig!\n"); > + start = 0; > + } Hier vielleicht auch pruefen ob der Kram Block-aligned ist, und ggf. abbrechen/korrigieren und warnen? > + break; > + case 'l': > + length = strtoull(optarg, NULL, 0); > + if (errno) { > + printf("Ihre Längenangabe war ungültig!\n"); > + start = 0; > + } > + break; > + case 'e': > + end = strtoull(optarg, NULL, 0); > + if (errno) { > + printf("Ihre Endangabe war ungültig!\n"); > + start = 0; > + } > + break; > + case 'h': > + bincat_display_usage(); > + return EXIT_SUCCESS; > + default: > + break; > + } > + } > + > + if (length && end) { > + printf("--length und --end schließen sich aus. Verwende --length\n"); > + } else if (end) { > + length = end - start; > + } > + > + if (optind == argc) { > bincat_display_usage(); > + return EXIT_SUCCESS; > + } > + > + if (optind + 1 == argc) { > + path = argv[optind]; > + } else { > + printf("Fehler: bincat kann nur eine Datei auf einmal verarbeiten!\n"); > return -1; > } > > - char* path = argv[1]; > + if (path == NULL) { > + bincat_display_usage(); > + return EXIT_SUCCESS; > + } Kann dieser Fall denn überhaupt eintreten? Dann müsste er doch beim if oben rausfallen? > + > FILE* file = fopen(path, "r"); > > + fseek(file, start, SEEK_SET); fseek nimmt nur einen 32-Bit Offset. Nimm besser lio_seek, das kann auch 64 bit. > + m = start / 8; > + > if (file == NULL) { > printf("Konnte '%s' nicht zum lesen oeffnen!\n", path); > return -1; > } else { > char buffer[BLOCK_SIZE]; > size_t size; > - int n, m = 0; > - while (feof(file) != EOF) { > + while (feof(file) != EOF && (total_read <= length || length == 0)) { > + > size = fread(buffer, 1, BLOCK_SIZE, file); > > + total_read += size; > + > printf("0x%08x: ", m); > > for (n=0; n < size; n++) { > @@ -82,12 +163,19 @@ void bincat_display_usage(void); > > fclose(file); > } > - > + printf("\n"); > return EXIT_SUCCESS; > } > > void bincat_display_usage() > { > - puts("\nAufruf: bincat "); > + puts("\nAufruf: bincat [Optionen] \n"); > + puts(" -s, --start Gibt die Startposition an"); > + puts(" -l, --length Gibt die Ausgabelänge an"); > + puts(" -e, --end Gibt die Endposition an\n"); > + puts("Falls --length und --end angegeben sind, erhält --length den " > + "Vorrang.\n"); > + puts("Position und Längen können optional via vorangestelltem 0x auch " > + "Hexadezimal\n angegeben werden."); Hier könnte man auch noch darauf hinweisen, dass das ganze nur mit ganzen Blocks der Grösse BLOCK_SIZE das Erwartete tut. .> } > > -- > 1.5.6.5 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From alex at tyndur.org Sun Aug 9 16:46:47 2009 From: alex at tyndur.org (Alexander Siol) Date: Sun, 9 Aug 2009 16:46:47 +0200 Subject: [tyndur-devel] [PATCH] bincat: Positionsangabe moeglich (wird auf 1k-Bloecke gerundet) In-Reply-To: <1249809031-13525-1-git-send-email-alex@tyndur.org> References: <1249809031-13525-1-git-send-email-alex@tyndur.org> Message-ID: <1249829207-3557-1-git-send-email-alex@tyndur.org> +bincat: Positionsangaben (Start, Länge und Ende) *bincat: Umstellung auf getopt --- trunk/src/modules/c/shell/cmds/bincat.c | 108 +++++++++++++++++++++++++++---- 1 files changed, 96 insertions(+), 12 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/bincat.c b/trunk/src/modules/c/shell/cmds/bincat.c index 8c0372e..825e81e 100644 --- a/trunk/src/modules/c/shell/cmds/bincat.c +++ b/trunk/src/modules/c/shell/cmds/bincat.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. + * by Antoine Kaufmann, Alexander Siol * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,11 +33,14 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "types.h" -#include "stdlib.h" -#include "stdio.h" -#include "unistd.h" +#include +#include +#include +#include #include +#include +#include +#include #define BLOCK_SIZE 1024 @@ -49,24 +52,97 @@ void bincat_display_usage(void); int main(int argc, char* argv[]) #endif { - if (argc != 2) { + static const struct option long_options[] = + { + { "start", required_argument, 0, 's' }, + { "length", required_argument, 0, 'l' }, + { "end", required_argument, 0, 'e' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + optind = 0; + uint64_t start = 0; + uint64_t end = 0; + uint64_t length = 0; + char *path = NULL; + int n = 0; + int m = 0; + size_t total_read = 0; + + + while (optind < argc) { + int result = getopt_long(argc, argv, "s:l:e:h", long_options, NULL); + if (result == -1) { + break; + } + errno = 0; + switch (result) { + case 's': + start = strtoull(optarg, NULL, 0); + start -= start % 8; + if (errno) { + printf("Ihre Startangabe war ungültig!\n"); + start = 0; + } + break; + case 'l': + length = strtoull(optarg, NULL, 0); + if (errno) { + printf("Ihre Längenangabe war ungültig!\n"); + length = 0; + } + break; + case 'e': + end = strtoull(optarg, NULL, 0); + if (errno) { + printf("Ihre Endangabe war ungültig!\n"); + end = 0; + } + break; + case 'h': + bincat_display_usage(); + return EXIT_SUCCESS; + default: + break; + } + } + + if (length && end) { + printf("--length und --end schließen sich aus. Verwende --length\n"); + } else if (end) { + length = end - start; + } + + if (optind == argc) { bincat_display_usage(); + return EXIT_SUCCESS; + } + + if (optind + 1 == argc) { + path = argv[optind]; + } else { + printf("Fehler: bincat kann nur eine Datei auf einmal verarbeiten!\n"); return -1; } - char* path = argv[1]; FILE* file = fopen(path, "r"); + lio_seek(file, start, SEEK_SET); + m = start / 8; + if (file == NULL) { printf("Konnte '%s' nicht zum lesen oeffnen!\n", path); return -1; } else { char buffer[BLOCK_SIZE]; size_t size; - int n, m = 0; - while (feof(file) != EOF) { + while (feof(file) != EOF && (total_read <= length || length == 0)) { + size = fread(buffer, 1, BLOCK_SIZE, file); + total_read += size; + printf("0x%08x: ", m); for (n=0; n < size; n++) { @@ -82,12 +158,20 @@ void bincat_display_usage(void); fclose(file); } - + printf("\n"); return EXIT_SUCCESS; } void bincat_display_usage() { - puts("\nAufruf: bincat "); + puts("\nAufruf: bincat [Optionen] \n"); + puts(" -s, --start Gibt die Startposition an"); + puts(" -l, --length Gibt die Ausgabelänge an"); + puts(" -e, --end Gibt die Endposition an\n"); + puts("Falls --length und --end angegeben sind, erhält --length den " + "Vorrang.\n"); + printf("Position und Längen können optional via vorangestelltem 0x auch " + "Hexadezimal\n angegeben werden, müssen aber in jedem Fall ganzzahlige " + "Vielfache der\n Blockgröße (%d Bytes) sein.\n", BLOCK_SIZE); } -- 1.5.6.5 From toni at tyndur.org Sun Aug 9 16:50:41 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 9 Aug 2009 16:50:41 +0200 Subject: [tyndur-devel] [PATCH] bincat: Positionsangabe moeglich (wird auf 1k-Bloecke gerundet) In-Reply-To: <1249829207-3557-1-git-send-email-alex@tyndur.org> References: <1249809031-13525-1-git-send-email-alex@tyndur.org> <1249829207-3557-1-git-send-email-alex@tyndur.org> Message-ID: <20090809145041.GC28946@einstein.kaufmann.lan> On Sun, Aug 09 16:46, Alexander Siol wrote: > +bincat: Positionsangaben (Start, Länge und Ende) > *bincat: Umstellung auf getopt Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Mon Aug 10 15:16:32 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 10 Aug 2009 15:16:32 +0200 Subject: [tyndur-devel] [PATCH] libm: Rundungsfunktionen Message-ID: <1249910192-22291-1-git-send-email-kevin@tyndur.org> + libm: floor, ceil, round, trunc, nearbyint, fesetround, fegetround Signed-off-by: Kevin Wolf --- src/modules/include/math.h | 25 ++++ src/modules/lib/stdlibc/math/round.c | 212 ++++++++++++++++++++++++++++++++++ 2 files changed, 237 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/stdlibc/math/round.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 49083ab..138fff3 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -49,6 +49,12 @@ #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.70710678118654752440 +enum { + FE_TONEAREST, + FE_UPWARD, + FE_DOWNWARD, + FE_TOWARDZERO, +}; double tan(double); @@ -94,5 +100,24 @@ double acos(double); float acosf(float); long double acosl(long double); + +double floor(double x); +float floorf(float x); +long double floorl(long double x); +double ceil(double x); +float ceilf(float x); +long double ceill(long double x); +double trunc(double x); +float truncf(float x); +long double truncl(long double x); +double round(double x); +float roundf(float x); +long double roundl(long double x); +int fegetround(void); +int fesetround(int rounding_mode); +double nearbyint(double x); +float nearbyintf(float x); +long double nearbyintl(long double x); + #endif diff --git a/src/modules/lib/stdlibc/math/round.c b/src/modules/lib/stdlibc/math/round.c new file mode 100644 index 0000000..b4fd618 --- /dev/null +++ b/src/modules/lib/stdlibc/math/round.c @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2009 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. + * + * 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. + */ + +#include +#include +#include + +#define ROUND_NEAR "$0x000" +#define ROUND_DOWN "$0x400" +#define ROUND_UP "$0x800" +#define ROUND_TRUNC "$0xc00" + +static int rounding_mode = FE_TONEAREST; + +/* + * Achtung: + * + * Die folgenden Funktionen basieren auf der Annahme, dass das RC-Feld im FPU + * Control Word normalerweise immer auf 0 gesetzt ist, also der neue Wert durch + * ein einfaches or eingetragen werden kann. + */ + +long double floorl(long double x) +{ + long double res; + uint16_t control_word; + + asm( + // Rundungsmodus setzen + "fnstcw %2;" + "mov %2, %%eax;" + "orl " ROUND_DOWN ", %2;" + "fldcw %2;" + + // Zahl auf dem Stack runden + "frndint;" + + // Wieder den Standardrundungsmodus setzen + "mov %%eax, %2;" + "fldcw %2;" + : "=t" (res) : "0" (x), "m" (control_word) : "eax"); + + return res; +} + +double floor(double x) +{ + return floorl(x); +} + +float floorf(float x) +{ + return floorl(x); +} + + +long double ceill(long double x) +{ + long double res; + uint16_t control_word; + + asm( + // Rundungsmodus setzen + "fnstcw %2;" + "mov %2, %%eax;" + "orl " ROUND_UP ", %2;" + "fldcw %2;" + + // Zahl auf dem Stack runden + "frndint;" + + // Wieder den Standardrundungsmodus setzen + "mov %%eax, %2;" + "fldcw %2;" + : "=t" (res) : "0" (x), "m" (control_word) : "eax"); + + return res; +} + +double ceil(double x) +{ + return ceill(x); +} + +float ceilf(float x) +{ + return ceill(x); +} + +long double truncl(long double x) +{ + long double res; + uint16_t control_word; + + asm( + // Rundungsmodus setzen + "fnstcw %2;" + "mov %2, %%eax;" + "orl " ROUND_TRUNC ", %2;" + "fldcw %2;" + + // Zahl auf dem Stack runden + "frndint;" + + // Wieder den Standardrundungsmodus setzen + "mov %%eax, %2;" + "fldcw %2;" + : "=t" (res) : "0" (x), "m" (control_word) : "eax"); + + return res; +} + +double trunc(double x) +{ + return truncl(x); +} + +float truncf(float x) +{ + return truncl(x); +} + +long double roundl(long double x) +{ + long double res; + + asm("frndint" : "=t" (res) : "0" (x)); + + return res; +} + +double round(double x) +{ + return roundl(x); +} + +float roundf(float x) +{ + return roundl(x); +} + +long double nearbyintl(long double x) +{ + switch (rounding_mode) { + case FE_TONEAREST: + return roundl(x); + case FE_TOWARDZERO: + return truncl(x); + case FE_DOWNWARD: + return floorl(x); + case FE_UPWARD: + return ceill(x); + } + + abort(); + return x; +} + +double nearbyint(double x) +{ + return nearbyintl(x); +} + +float nearbyintf(float x) +{ + return nearbyintl(x); +} + +int fegetround(void) +{ + return rounding_mode; +} + +int fesetround(int mode) +{ + switch(mode) { + case FE_TONEAREST: + case FE_TOWARDZERO: + case FE_DOWNWARD: + case FE_UPWARD: + rounding_mode = mode; + return 0; + + default: + return -1; + } +} -- 1.6.0.2 From alexanderkluth at gmx.de Mon Aug 10 21:02:46 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Mon, 10 Aug 2009 21:02:46 +0200 Subject: [tyndur-devel] [PATCH] ! -disable-werrors, damit binutils unter Ubuntu Jaunty nicht meckert In-Reply-To: <1> References: <1> Message-ID: <1249930966-26662-1-git-send-email-alexanderkluth@gmx.de> From: Alexander Hartmut Kluth Signed-off-by: Alexander Hartmut Kluth --- scripts/build_crosstools | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/scripts/build_crosstools b/scripts/build_crosstools index d3a0496..febb5eb 100755 --- a/scripts/build_crosstools +++ b/scripts/build_crosstools @@ -19,7 +19,7 @@ echo "[binutils] Patch anwenden..." patch -p0 -d binutils-2.18/ < ${PATCHES}/binutils/2.18/binutils-2.18.patch >${LOGS}/binutils.log || exit -1 cd build echo "[binutils] Konfigurieren..." -../binutils-2.18/configure --prefix="${PREFIX}" --with-sysroot=${PREFIX} --target=${TARGET} --disable-nls >>${LOGS}/binutils.log || exit -1 +../binutils-2.18/configure --prefix="${PREFIX}" --with-sysroot=${PREFIX} --target=${TARGET} --disable-nls --disable-werror >>${LOGS}/binutils.log || exit -1 echo "[binutils] Kompilieren..." make ${MAKEOPTS} >>${LOGS}/binutils.log 2>>${LOGS}/binutils.log || exit -1 echo "[binutils] Installieren..." -- 1.6.0.4 From Patrick Tue Aug 11 01:22:15 2009 From: Patrick (Patrick) Date: Tue, 11 Aug 2009 01:22:15 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D__Meiner_erste_Commit_ins_Git?= =?utf-8?q?_Repo_von_tyndur=2E_Und_ahm_nunja=2E_AC97_Treiber_unvoll?= =?utf-8?q?st=C3=A4ndig_hinzugef=C3=BCgt=2E_Wichtig_sind_mir_die_Ko?= =?utf-8?q?mmentare_zu_der_CDI/Sound_definition?= Message-ID: <1249946535-15187-1-git-send-email-user@Cazad-Dum> From: deathly-sequences at web.de --- src/modules/cdi/ac97/Makefile.all | 6 + src/modules/cdi/ac97/ac97.c | 189 ++++++++++++++++++++++++++++++++++ src/modules/cdi/ac97/includes/ac97.h | 80 ++++++++++++++ src/modules/cdi/ac97/main.c | 123 ++++++++++++++++++++++ src/modules/cdi/include/cdi.h | 1 + src/modules/cdi/include/cdi/sound.h | 151 +++++++++++++++++++++++++++ 6 files changed, 550 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/ac97/Makefile.all create mode 100644 src/modules/cdi/ac97/ac97.c create mode 100644 src/modules/cdi/ac97/includes/ac97.h create mode 100644 src/modules/cdi/ac97/main.c create mode 100644 src/modules/cdi/include/cdi/sound.h diff --git a/src/modules/cdi/ac97/Makefile.all b/src/modules/cdi/ac97/Makefile.all new file mode 100644 index 0000000..d231938 --- /dev/null +++ b/src/modules/cdi/ac97/Makefile.all @@ -0,0 +1,6 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/modules/ac97" +$LOST_TOOLS_LD -Ttext=0x40000000 -oac97.mod *.o --start-group $2 --end-group +$LOST_TOOLS_STRIP -s ac97.mod -o $1/modules/ac97 diff --git a/src/modules/cdi/ac97/ac97.c b/src/modules/cdi/ac97/ac97.c new file mode 100644 index 0000000..25ec1cd --- /dev/null +++ b/src/modules/cdi/ac97/ac97.c @@ -0,0 +1,189 @@ +#include +#include +#include +#include +#include + +#include "cdi/pci.h" +#include "cdi/io.h" +#include "cdi/misc.h" + +#include "includes/ac97.h" + +/*NOTE: Code kommt zum Teil aus lowlevel.brainsware.org/wiki/AC97 Stand: + 3.8.2009*/ + +/*FIXME: This Code sucks ass!*/ + +static void ac97_handle_interrupt(struct cdi_device* device); +static void play_smpl(struct cdi_device* dev); + +/*FIXME: Code Struktur verbessern*/ + +void ac97_init_device(struct cdi_device* device){ + struct ac97_device *codec; + int i,j; + j=0; + codec=(struct ac97_device*)device; + /*PCI Strukturen initialisieren*/ + DEBUG_MSG("AC97:- Interrupthandler und Ports initialisieren"); + cdi_register_irq(codec->pci->irq,ac97_handle_interrupt,device); + cdi_pci_alloc_ioports(codec->pci); + /*IO-Räume finden: nambar und nabmbar, diese Stehen in der reslist*/ + cdi_list_t reslist=codec->pci->resources; + struct cdi_pci_resource* res;/*zum Reslist traversieren*/ + codec->nambar=0; + codec->nabmbar=0; + /*Reslist wird traversiert*/ + for(i=0; (res=cdi_list_get(reslist,i));i++){ + if((res->type==CDI_PCI_IOPORTS)&&(codec->nabmbar==0)){ + /*Nabmbar steht vor Nambar in der Liste!*/ + codec->nabmbar=res->start; + DEBUG_MSG("verm. Nabmbar"); + } + else if((res->type==CDI_PCI_IOPORTS)&&(codec->nambar==0)){ + /*Nambar eintragen*/ + DEBUG_MSG("verm. Nambar"); + codec->nambar=res->start; + } + else if(res->type==CDI_PCI_IOPORTS){ + DEBUG_MSG("IOPORT unbekannt"); + } + else{ + DEBUG_MSG("res->type unbekannt"); + } + } + cdi_sleep_ms(1000); + /* Karte Resetten */ + DEBUG_MSG("Karte resetten"); + cdi_outw(codec->nambar+NAM_RESET,42);/*Reset der Karte durchführen*/ + cdi_outb(codec->nabmbar+NABM_GLB_CTRL_STAT,0x02);/*wird auch zum Resetten +benötigt*/ + cdi_sleep_ms(1000); /*1sec warten*/ + + /* Lautstärke einstellen */ + DEBUG_MSG("Lautstärke einstellen"); + /*Lautstärke geht von 0x00 bis 0x1f, wobei 0x00 laut und 0x1f leise ist*/ + /*Funktioniert anscheinend nicht unter qemu*/ + uint16_t volume=0x1f; + /*Allgemeine Laustärke für Links und Rechts*/ + cdi_outw(codec->nambar+NAM_MASTER_VOLUME,(volume<<8)|volume); + cdi_outw(codec->nambar+NAM_MONO_VOLUME,volume);/*Mono Lautstärke*/ + cdi_outw(codec->nambar+NAM_PC_BEEP,volume);/*PC BEEP Lautstärke*/ + /*PCM Lautstärke für links und rechts*/ + cdi_outw(codec->nambar+NAM_PCM_VOLUME,(volume<<8)|volume); + cdi_sleep_ms(1000); /*1sec warten*/ + + /*Sample rate einstellen*/ + DEBUG_MSG("Sample Rates Einstellen"); + if(!((cdi_inw(codec->nambar+NAM_EXT_AUDIO_ID)&0x01))){ + /* Hier liegt die Spl Rate auf fix bei 48kHz*/} + else + { + DEBUG_MSG("Sample Rates Konfigurieren"); + cdi_outw(codec->nambar+NAM_EXT_AUDIO_STC,cdi_inw(codec->nambar+ +NAM_EXT_AUDIO_ID)|1); /*Variable Sample Rate einstellen*/ + cdi_sleep_ms(1000);/*Warten!*/ + /*FIXME: Aus Parametern auslesen!*/ + /*Front Sample Rate*/ + cdi_outw(codec->nambar+NAM_FRONT_SPLRATE,44100); + /*Links Rechts Sample Rate*/ + cdi_outw(codec->nambar+NAM_LR_SPLRATE,44100); + cdi_sleep_ms(1000);/*Warten!*/ + } + /*Buffer initialisieren.*/ + DEBUG_MSG("Bufferlist initialisieren - Nur zum Test,\ +gehört hier nicht hin!"); + /*FIXME: Bitmap bringt glaub ich nichts.*/ + codec->valid_buffs=0x00;/*Bisher ist keiner der Buffer gültig*/ + /* Buffer list anlegen*/ + if(cdi_alloc_phys_mem(32*sizeof(buf),(void **)&codec->buffer_list, + &codec->paddr_buf_list)==-1){ + DEBUG_MSG("MEMALLOC FEHLGESCHLAGEN!"); + return; + } + /* Buffer anlegen, eintragen und mit Werten füllen*/ + /*Letzteres nur zum Test*/ + DEBUG_MSG("Buffer anlegen und eintragen"); + for(i=0;i<32;i++) + { + void* vbuf=0;/*virtuelle Adresse des Buffers*/ + void* pbuf=0;/*physische Adresse*/ + if(cdi_alloc_phys_mem(0x10000,&vbuf,&pbuf)==-1){ + /*0x20000 funzt hier offensichtlich nich*/ + DEBUG_MSG("MEMALLOC FEHLGESCHLAGEN -- BUFFER INITIALISIEREN"); + return; + } + /*Buffer füllen -- Nur zu Testzwecken*/ + else{ + codec->buffer_list[i].buffer=pbuf;/*Physikalische Adresse*/ + /*Maximale Sample Länge.*/ + codec->buffer_list[i].sample_length=0x7ffe; + if(i==31){ + codec->buffer_list[i].bup=1; /*Buffer underrun Policy setzen.*/ + } + else{ + codec->buffer_list[i].bup=0; /*Buffer underrun Policy setzen.*/ + } + codec->buffer_list[i].ioc=1; /*Interrupt on completion bit setzen.*/ + codec->buf_virt[i]=(uint16_t*)vbuf; + codec->buf_phys[i]=(uint16_t*)pbuf; + uint16_t* xbuf=(uint16_t*)vbuf; + for(j=0;j<0x8000;j+=2) + { + xbuf[j]=0; + xbuf[j+1]=0; + } + } + } + play_smpl((struct cdi_device*) codec); + DEBUG_MSG("Abspielen!"); + cdi_sleep_ms(1000);/*Warten! Dieses hat aber keinen besonderen Grund*/ + /*Lister der Buffer Deskriptoren an das Gerät übergeben*/ + cdi_outl(codec->nabmbar+NABM_POBDBAR,(uint32_t)codec->paddr_buf_list); + /*Letzten gültigen Buffer eintragen.*/ + cdi_outb(codec->nabmbar+NABM_POLVI,31); + /*Das Gerät die Buffer abspielen lassen.*/ + /*Hierzu wird das letzte Bit in nabmbar+NABM_POCONTROL gesetzt.*/ + cdi_outb(codec->nabmbar+NABM_POCONTROL,0x01); +} + +static void play_smpl(struct cdi_device* dev){ + struct ac97_device *codec; + codec=(struct ac97_device*)dev; + FILE *pf; + pf=fopen("startup.wav","br"); + char c,d; + int i; + if(!pf){ + DEBUG_MSG("Fehler beim öffnen!"); + return; + } + /*Header überspringen. Nervt grad nur.*/ + for(i=0;i<52;i++){ + c=fgetc(pf); + } + DEBUG_MSG("Header uebersprungen"); + /*sooo :) dinge auslesen*/ + i=0; + uint16_t *xbuf=(uint16_t *)codec->buf_virt[0]; + while((!feof(pf))&&(i<0x10000)){ + d=c; + c=fgetc(pf); + i++; + if(i%2==0){xbuf[(i-i%2)/2]=(c<<8)+d;}; + if(c==d){printf("\r FUCK IT!%d %x %x",i,c,d);} + } + DEBUG_MSG("SOO LONG!"); + fclose(pf); +} + +void ac97_remove_device(struct cdi_device* device){ + ; +} + +static void ac97_handle_interrupt(struct cdi_device* device){ + DEBUG_MSG("Interrupts"); +} + +/* EOF */ diff --git a/src/modules/cdi/ac97/includes/ac97.h b/src/modules/cdi/ac97/includes/ac97.h new file mode 100644 index 0000000..5cd0a43 --- /dev/null +++ b/src/modules/cdi/ac97/includes/ac97.h @@ -0,0 +1,80 @@ + +#ifndef __ac97_h__ +#define __ac97_h__ + +#include + +#include "cdi.h" +#include "cdi/net.h" +#include "cdi/pci.h" + +/* Benötigte Konstanten */ +/* Quelle: lowlevel.brainsware.org/wiki/AC97: Stand: 3.8.2009 */ + +#define NAM_RESET 0x0000 +#define NAM_MASTER_VOLUME 0x0002 +#define NAM_MONO_VOLUME 0x0006 +#define NAM_PC_BEEP 0x000A +#define NAM_PCM_VOLUME 0x0018 +#define NAM_EXT_AUDIO_ID 0x0028 +#define NAM_EXT_AUDIO_STC 0x002A +#define NAM_FRONT_SPLRATE 0x002C +#define NAM_LR_SPLRATE 0x0032 +#define NABM_POBDBAR 0x0010 +#define NABM_POLVI 0x0015 +#define NABM_POCONTROL 0x001B +#define NABM_GLB_CTRL_STAT 0x0060 + +/* Makros */ + +#define DEBUG_MSG(s) printf("[AC97] debug: %s() '%s'\n", __FUNCTION__, s) + +struct ac97_buffer_desc_t{ + void* buffer; + uint16_t sample_length; + uint16_t reserved:14; + uint16_t bup:1; + uint16_t ioc:1; + +}__attribute__((packed)); + +typedef struct ac97_buffer_desc_t buf; + +struct ac97_device{ + struct cdi_device cdi; + struct cdi_pci_device* pci; + void* phys; + buf* buffer_list; /*Liste der Buffer*/ + void* paddr_buf_list;/*phyisische Adresse der Buffer Descriptor list*/ + uint32_t valid_buffs; /*mini bitmap welche buffer gerade gültig sind :)*/ + uint16_t* buf_virt[32];/*Virtuelle Adressen der einzelnen buffer*/ + uint16_t* buf_phys[32];/*Physische Adressen der einzelnen buffer*/ + + uint32_t nambar; /*Native Audio Mixer Base Address Register*/ + uint32_t nabmbar; /*Native Audio Bus Master Base Address Register*/ + + uint16_t vol;/*Lautstärke*/ + uint16_t splrate;/*Samplerate*/ + + //TODO: Volume, Sample Rates etc. +}; + +/** + * Initialisiert das AC97 Gerät. + * + * @param device Struktur zur Verwaltung des Gerätes. Elterklasse von ac97_device + **/ + +void ac97_init_device(struct cdi_device* device); + +/** + * Führt die Aufraumaurbeiten durch. Wie zum Beispiel: Speicherfreigabe. + * + * @param device Struktur zur Verwaltung des Gerätes. Elterklasse von ac97_device + **/ +void ac97_remove_device(struct cdi_device* device); + +#endif + +/* EOF */ + diff --git a/src/modules/cdi/ac97/main.c b/src/modules/cdi/ac97/main.c new file mode 100644 index 0000000..f8aa1b2 --- /dev/null +++ b/src/modules/cdi/ac97/main.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include + +#include "cdi/pci.h" +#include "cdi/io.h" +#include "cdi/misc.h" + +#include "includes/ac97.h" + +struct ac97_options{ + uint32_t mode; + uint16_t vol;/*Lautstärke*/ + uint16_t splr;/*Sample Rate*/ +}; + +typedef struct ac97_options dro; + +struct ac97_driver { + struct cdi_driver drv; +}; + +static struct ac97_driver ac97; + +static const char* driver_name="ac97"; + +static void ac97_parameters(dro* modi, int argc, char *argv[]); +static void ac97driver_init(int argc, char *argv[]); +static void ac97driver_destroy(struct cdi_driver* driver); + +#ifdef CDI_STANDALONE +int main(int argc, char* argv[]) +#else +int init_ac97(int argc, char* argv[]) +#endif +{ + cdi_init(); + ac97driver_init(argc,argv); + cdi_driver_register((struct cdi_driver*) &ac97); +#ifdef CDI_STANDALONE + cdi_run_drivers(); +#endif + return 0; +} + +static void ac97driver_init(int argc, char *argv[]){ + dro options={ + /*Standardwerte setzen*/ + .mode=0x00, + .vol=0x0f, + .splr=44100 + }; + + ac97_parameters(&options, argc,argv); + ac97.drv.name=driver_name; + ac97.drv.type=CDI_SOUND; + ac97.drv.init_device=ac97_init_device; + ac97.drv.remove_device=ac97_remove_device; + ac97.drv.destroy=ac97driver_destroy; + + cdi_list_t pci_devices=cdi_list_create(); + cdi_pci_get_all_devices(pci_devices); + struct cdi_pci_device* get=0; + int i; + for(i=0;(get=cdi_list_get(pci_devices,i));i++){ + printf("PCI_DEVICE: %x\n",get->device_id); + if((get->vendor_id==0x8086)&&(get->device_id==0x2415)){ + void* p_phys_device; + struct ac97_device* ac97_d; + if((cdi_alloc_phys_mem(sizeof(*ac97_d),(void**) &ac97_d, +&p_phys_device))==-1){ + DEBUG_MSG("Memalloc fehlgeschlagen!"); + } + memset(ac97_d,0,sizeof(struct ac97_device)); + ac97_d->phys=p_phys_device; + ac97_d->pci=get; + ac97_d->vol=options.vol; + ac97_d->splrate=options.splr; + ac97_init_device((struct cdi_device*)ac97_d); + } + else{ + cdi_pci_device_destroy(get); + } + } + cdi_list_destroy(pci_devices); +} + + +/*TODO: Debugging, einfach überprüfen ob alles funzt*/ +static void ac97_parameters(dro* options, int argc, char *argv[]){ + int i,j; + uint32_t flags=0; + for( i=1;ivol=(uint16_t)strtoul(argv[i+1],NULL,0); + flags|=0x00000001; + i++; /*Index muss sich noch um eins erhöhen.*/ + continue; + } + else if(!(strcmp("--sample-rate",argv[i])&&strcmp("-s",argv[i])&& + (flags&0x00000010))){ + options->splr=(uint16_t)strtoul(argv[i+1],NULL,0); + flags|=0x00000010; + i++; + continue; + } + else{ + DEBUG_MSG("Unbekannte oder Wiederhohlte Argumente!"); + printf("Argumentenliste:\n"); + for(j=0;j +#include + +#include "cdi.h" + +/* Angelehnt an net.h */ + +struct cdi_sound_device{ + struct cdi_device dev; + /* Im folgenden bezeichnet driver immer das Gerät. */ + /* Ausführlichere Kommentare/Dokumentation findet man in den jeweiligen + Implementationen der Treiber. Hier werden nur Funktionszeiger + definiert. */ + + /** @brief Damit das Gerät auch beginnt Daten abzuspielen. + * + * Weißt den Treiber an, Daten abzuspielen, wenn neue vorhanden sind. + * + * @param driver Treiber, der die Daten abspielen soll. + * + */ + void (*cdi_sound_play)(struct cdi_sound_driver *driver); + + /** @brief Hält die Audioausgabe des Treibers an. + * + * Wenn der Treiber nicht gerade von einer anderen Anwendung blockiert wird, + * wird die Audioausgabe angehalten. Wird ignoriert, wenn der Treiber + * 'in use' ist. + * + * @param driver Treiber, der die Audioausgabe anhalten soll. + */ + void (*cdi_sound_stop)(struct cdi_sound_driver *driver); + + /** @brief Ein Prozess darf die in_use Option betätigen. + * + * Die in use Option ist mir eingefallen, als ich mir das Zusammenspiel + * Amarok, Firefox mit flashplayer plugin und der rest des Systems angesehen + * habe. Die schließen sich gegenseitig aus. Sobald Amarok an ist, kann + * der Rest nichts mehr abspielen. Hat auch gute Seiten. Funktionszeiger ... + * + * @param driver Treiber der in use gestellt werden soll. + * @param pid Prozess ID des Prozesses. Dient später nur zur Überprüfung. + * + * @return 0 bei Erfolg. 1 bei Misserfolg. + * + */ + uint32_t (*cdi_sound_in_use_enable)(struct cdi_sound_driver *driver, + uint32_t pid); + + /** @brief Der gleiche Prozess darf das in_use Privileg abgeben. + * + * Anhand von pid wird nur überprüft ob der richtige Prozess die in use + * Option abstellt. Funktionszeiger ... + * + * @param driver Treiber der die in use Option abschalten soll. + * @param pid Prozessnummer. + * + * @return 0 bei Erfolg. 1 bei Misserfolg. + */ + uint32_t (*cdi_sound_in_use_disable)(struct cdi_sound_driver *driver, + uint32_t pid); + + /** @brief Funktionszeiger für eine Schnittstelle, in der man den aktuellen + * Status des Treibers/Gerätes abrufen kann. + * + * Diese Funktion ist dafür gedacht um herauszufinden ob der Treiber gerade + * Daten abspielt oder nicht. Hier ist die Schnittstelle Treiber/CDI + * + * @param driver Soundtreiber, dessen Zustand ermittelt werden soll. + * + * @return Die Returncodes können von Treiber zu Treiber variieren. Hier + * ist eine Liste, von Codes, die auf jeden Fall genauso + * implementiert werden sollen (Zusätzliche können angehangen + * werden): 0 - Treiber/Gerät nicht arbeitsbereit/initialisiert. + * 1 - Gerät arbeitsbereit. Spielt keine Daten ab. 2 - Treiber + * erhält Daten. 4 - Gerät spielt Daten ab. Datenempfang möglich. + * 8 - Gerät ist gestoppt, aber es sind noch Daten zum spielen + * übrig. Neue Daten können jederzeit hinzugefügt werden. + * 16 - Bit ist gesetzt, wenn Qucik Mixing (lineare Superposition + * mit Clippingunterdrückung) erlaubt ist. 32 - Dieses Bit zeigt an + * ob der Treiber gerade von einem Prozess "blockiert" wird. + * + */ + uint32_t (*cdi_sound_driver_state)(struct cdi_sound_driver *driver); + + /** @brief Funktionszeiger für eine Schnittstelle, die dem Treiber die + * als nächstes abzuspielenden Daten übergibt. + * + * Dies ist ein Funktionszeiger und für die Schnittstelle Treiber CDI + * gedacht. + * + * @param driver Soundtreiber an den die Daten geschickt werden sollen. + * @param data_start Zeiger auf den Beginn der Daten. Es wird angenommen, + * dass alle Daten hintereinander liegen. + * @param data_length Länge des Datenblockes. + * @param pid Datenbereiche werden Treiberintern mit einer PID versehen, um + * diese z.B. noch zurückziehen zu können. Prozess beendet. + * Datenbereiche wurden deallokiert. + * + * @return 0 - bei Erfolg, 1 - bei Fehler, wiederhohlung kann ihn beheben + * 2 - Fehler nicht durch wiederhohlte Ausführung behebbar + * kann. Wenn Gerät z.B. von einem Prozess benutzt wird, der Mixing + * nicht zulassen will. Ansonnsten, werden Daten von verschiednen + * Geräten linear superponiert, oder einfach nacheinander + * abgespielt (Flags beachten). + */ + uint32_t (*cdi_sound_input_data)(struct cdi_sound_driver *driver, + uint32_t* data_start, + uint32_t data_length, + uint32_t pid); + + /** @brief Funktionszeiger für eine Schnittstelle, damit ein Prozess die an + * den Treiber übergebenen Daten zurückziehen kann. + * + * Diese Funktion ist dafür Gedacht, damit ein Prozess alle Daten, die in + * noch nicht fertiggestellten Buffer vorliegen, löschen kann, falls er z.B. + * beendet wird. Funktionszeiger für die Schnittstelle Treiber CDI. + * + * @param driver Treiber, der die entsprechenden Daten nicht mehr benutzen + * soll. + * @param pid Prozess ID, des entsprechenden Prozesses. + */ + void (*cdi_sound_remove_data)(struct cdi_sound_driver *driver, + uint32_t pid); + +} + +struct cdi_sound_driver{ + struct cdi_driver *drv; +} + +#endif + +/* EOF */ -- 1.6.0.4 From matheeguru at gmx.de Tue Aug 11 18:39:07 2009 From: matheeguru at gmx.de (Paul Lange) Date: Tue, 11 Aug 2009 18:39:07 +0200 Subject: [tyndur-devel] [PATCH] FTP-Client Message-ID: <1250008747-21318-1-git-send-email-matheeguru@gmx.de> From: Paul Lange + ftp FTP-Client (nocht nicht ganz ausgereift) Signed-off-by: Paul Lange --- src/modules/c/ftp/Makefile.all | 7 ++ src/modules/c/ftp/command.c | 66 +++++++++++ src/modules/c/ftp/command.h | 36 ++++++ src/modules/c/ftp/ftp.c | 235 ++++++++++++++++++++++++++++++++++++++++ src/modules/c/ftp/ftp.h | 40 +++++++ src/modules/c/ftp/main.c | 89 +++++++++++++++ 6 files changed, 473 insertions(+), 0 deletions(-) create mode 100755 src/modules/c/ftp/Makefile.all create mode 100644 src/modules/c/ftp/command.c create mode 100644 src/modules/c/ftp/command.h create mode 100644 src/modules/c/ftp/ftp.c create mode 100644 src/modules/c/ftp/ftp.h create mode 100644 src/modules/c/ftp/main.c diff --git a/src/modules/c/ftp/Makefile.all b/src/modules/c/ftp/Makefile.all new file mode 100755 index 0000000..fb31509 --- /dev/null +++ b/src/modules/c/ftp/Makefile.all @@ -0,0 +1,7 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/ftp" +$LOST_TOOLS_LD -oftp -Ttext=0x40000000 *.o --start-group $2 --end-group + +mv ftp $1/apps/ diff --git a/src/modules/c/ftp/command.c b/src/modules/c/ftp/command.c new file mode 100644 index 0000000..5bc06fc --- /dev/null +++ b/src/modules/c/ftp/command.c @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Paul Lange. + * + * 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. + */ + +#include +#include +#include + +#define LINE_LENGTH 80 + +extern char *host; +extern FILE *handle; + +void ls(void) +{ + FILE *data_handle; + char c; + char buffer[LINE_LENGTH]; + int i; + + data_handle = ftp_data_connect(); + request("LIST\r\n"); + while (!feof(data_handle)) { + i = 0; + while (((c = fgetc(data_handle)) != '\n') && + i < (LINE_LENGTH - 1) && !feof(data_handle)) { + if (c != EOF) { + buffer[i++] = c; + } + } + buffer[i] = '\0'; + printf("%s\n", buffer); + } + response(); +} diff --git a/src/modules/c/ftp/command.h b/src/modules/c/ftp/command.h new file mode 100644 index 0000000..bf1542c --- /dev/null +++ b/src/modules/c/ftp/command.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Paul Lange. + * + * 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. + */ + +void ls(void); diff --git a/src/modules/c/ftp/ftp.c b/src/modules/c/ftp/ftp.c new file mode 100644 index 0000000..77679b0 --- /dev/null +++ b/src/modules/c/ftp/ftp.c @@ -0,0 +1,235 @@ +/** + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Paul Lange. + * + * 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, INCZLUDING, 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. + */ + +#include +#include +#include +#include +#include + +#define COMMAND_PORT 21 +#define LINE_LENGTH 80 + +extern char *host; +extern FILE *handle; + +/** + * sendet einen Befehl an den Server und gibt den Request aus + * + * @param *command enthaelt den Befehl für den Server + */ +void request(const char *command) +{ + char buffer; + char response[LINE_LENGTH]; + bool line_end = TRUE; + int i = 0; + + fprintf(handle, "%s\r\n", command); + fflush(handle); + + while (line_end) { + while (((buffer = fgetc(handle)) != '\n') && i < (LINE_LENGTH - 1)) { + if (buffer != EOF) { + response[i++] = buffer; + } + } + response[i] = '\0'; + printf("%s\n", response); + line_end = FALSE; + + if (response[3] == '-') { + line_end = TRUE; + i = 0; + } + } +} + + +/** + * gibt den Request string auf dem Bildschirm aus + */ +void response(void) +{ + char buffer; + char response[LINE_LENGTH]; + bool line_end = TRUE; + int i = 0; + + while (line_end) { + while (((buffer = fgetc(handle)) != '\n') && i < (LINE_LENGTH - 1)) { + if (buffer != EOF) { + response[i++] = buffer; + } + } + response[i] = '\0'; + printf("%s\n", response); + line_end = FALSE; + + if (response[3] == '-') { + line_end = TRUE; + i = 0; + } + } +} + + +/** + * Stellt eine Verbindung zum Server her + */ +void ftp_connect(void) +{ + char *host_path; + char *prompt; + char *input; + char *c; + + puts("\033[1;37mVerbinde...\033[0m"); + asprintf(&host_path, "tcpip:/%s:%d", host, COMMAND_PORT); + handle = fopen(host_path, "r+"); + free(host_path); + + if (!handle) { + puts("\033[1;37mFehler: Host nicht erreichbar!\033[0m"); + handle = NULL; + return; + } + printf("\033[1;37mVerbunden mit %s, warte auf Antwort...\033[0m\n", host); + response(); + + asprintf(&prompt, "\033[1;37mBenutzer (%s): \033[0m", host); + input = readline(prompt); + free(prompt); + + // sorgt dafür, dass die Leerzeichen entfernt werden + for (; isspace(*input); input++); + for (c = input; !isspace(*c) && *c; c++); + *c = '\0'; + + fprintf(handle, "USER %s\r\n", input); + fflush(handle); + response(); + + input = readline("\033[1;37mPasswort: \033[0m"); + // sorgt dafür, dass die Leerzeichen entfernt werden + for (; isspace(*input); input++); + for (c = input; !isspace(*c) && *c; c++); + *c = '\0'; + + fprintf(handle, "PASS %s\r\n", input); + fflush(handle); + response(); +} + + +/** + * Schliest die Verbindung zum Server + */ +void ftp_disconnect(void) +{ + if (!handle) return; + request("QUIT"); + fclose(handle); + puts("\033[1;37mVerbindung getrennt...\033[0m"); +} + + +/** + * Öffnet eine passive Datenverbindung zum Server + * + * @return Handle zum Datenfluss + */ +FILE* ftp_data_connect(void) +{ + char buffer; + char *c, *host_path; + char response[LINE_LENGTH], portI[4], portII[4]; + bool line_end = TRUE; + unsigned int port, port_low; + int i = 0; + FILE *data_handle = NULL; + + fprintf(handle, "%s\r\n", "PASV"); + fflush(handle); + + while (line_end) { + while (((buffer = fgetc(handle)) != '\n') && i < (LINE_LENGTH - 1)) { + if (buffer != EOF) { + response[i++] = buffer; + } + } + response[i] = '\0'; + printf("%s\n", response); + line_end = FALSE; + + if (response[3] == '-') { + line_end = TRUE; + i = 0; + } + } + for (c = response; *c != '(' || *c == '\n'; c++); + + i = 0; + while (i < 4) { + for (; *(c++) != ',' || *c == '\n';); + i++; + } + + i = 0; + while (*c != ',' || *c == '\n') { + portI[i] = *c; + i++; + c++; + } + portI[i++] = '\0'; + c++; + i = 0; + while (*c != ')' || *c == '\n') { + portII[i] = *c; + i++; + c++; + } + portII[i++] = '\0'; + port = atoi(portI); + port *= 256; + port_low = atoi(portII); + port += port_low; + + asprintf(&host_path, "tcpip:/%s:%d", host, port); + data_handle = fopen(host_path, "r+"); + free(host_path); + + return data_handle; +} diff --git a/src/modules/c/ftp/ftp.h b/src/modules/c/ftp/ftp.h new file mode 100644 index 0000000..bb7189e --- /dev/null +++ b/src/modules/c/ftp/ftp.h @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Paul Lange. + * + * 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. + */ + +extern void ftp_connect(void); +extern FILE* ftp_data_connect(void); +extern void ftp_disconnect(void); +extern void request(const char*); +extern void response(void); diff --git a/src/modules/c/ftp/main.c b/src/modules/c/ftp/main.c new file mode 100644 index 0000000..4425534 --- /dev/null +++ b/src/modules/c/ftp/main.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Paul Lange. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +char *host; +FILE *handle; + +int main(int argc, char *argv[]) +{ + bool prgm_end = FALSE; + char *input, *buffer; + + if (argc == 2) { + host = argv[1]; + ftp_connect(); + } + + // Bildet den Ablauf des kompletten Programmes + do { + input = readline("\033[1;37mFTP>\033[0m"); + // durchlaeuft den String bis zum ersten Zeichen + for (; isspace(*input); input++); + + if (!strncmp(input, "exit", 4)) { + prgm_end = TRUE; + } else if (!strncmp(input, "close", 5)) { + ftp_disconnect(); + handle = NULL; + } else if (!strncmp(input, "quit", 4)) { + ftp_disconnect(); + handle = NULL; + prgm_end = TRUE; + } else if (!strncmp(input, "help", 4)) { + } else if (!strncmp(input, "open", 4)) { + // parst den host aus dem string + input += 5; + for (; isspace(*input); input++); + for (buffer = input; !isspace(*buffer) && *buffer; buffer++); + *buffer = '\0'; + + host = input; + ftp_connect(); + } else if (!strncmp(input, "ls", 2)) { + ls(); + } else { + puts("\033[1;37mFehler: Falschen Befehl eingegeben! Geben sie " + "help ein um eine Liste aller\nBefehle zu erhalten\033[0m"); + } + } while (!prgm_end); + return 0; +} -- 1.6.0.4 From kevin at tyndur.org Tue Aug 11 19:35:36 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 19:35:36 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: POSIX: alarm(0) In-Reply-To: <1250012138-17824-1-git-send-email-kevin@tyndur.org> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> Message-ID: <1250012138-17824-2-git-send-email-kevin@tyndur.org> ! libc: POSIX: alarm(0) bricht nur laufende Timer ab, aber erstellt keinen neuen. Signed-off-by: Kevin Wolf --- src/modules/lib/posix/signal.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c index 4b9fe5a..ef95739 100644 --- a/src/modules/lib/posix/signal.c +++ b/src/modules/lib/posix/signal.c @@ -368,7 +368,11 @@ long alarm(long seconds) timer_cancel(id); } - id = timer_register(do_alarm, seconds * 1000000); + if (seconds != 0) { + id = timer_register(do_alarm, seconds * 1000000); + } else { + id = 0; + } // FIXME return 0; -- 1.6.0.2 From kevin at tyndur.org Tue Aug 11 19:35:35 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 19:35:35 +0200 Subject: [tyndur-devel] [PATCH 0/3] git-Patches, Teil 1 Message-ID: <1250012138-17824-1-git-send-email-kevin@tyndur.org> Ein paar Patches, die fuer den git-lbuild noetig sind. Kevin Wolf (3): libc: POSIX: alarm(0) libc: POSIX: herror() und hstrerror() libc: POSIX: libgen.h src/modules/include/libgen.h | 46 +++++++++++++++++++++++ src/modules/include/netdb.h | 14 ++++++- src/modules/lib/posix/libgen.c | 80 ++++++++++++++++++++++++++++++++++++++++ src/modules/lib/posix/net.c | 34 +++++++++++++++++ src/modules/lib/posix/signal.c | 6 ++- 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 src/modules/include/libgen.h create mode 100644 src/modules/lib/posix/libgen.c From kevin at tyndur.org Tue Aug 11 19:35:37 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 19:35:37 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: POSIX: herror() und hstrerror() In-Reply-To: <1250012138-17824-1-git-send-email-kevin@tyndur.org> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> Message-ID: <1250012138-17824-3-git-send-email-kevin@tyndur.org> + libc: POSIX: herror() und hstrerror(). Diese Funktionen zu haben überzeugen git davon, dass er kein -lresolv benutzen sollte. Signed-off-by: Kevin Wolf --- src/modules/include/netdb.h | 14 +++++++++++++- src/modules/lib/posix/net.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletions(-) diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h index 88cd98c..feb0ba2 100644 --- a/src/modules/include/netdb.h +++ b/src/modules/include/netdb.h @@ -78,7 +78,7 @@ struct protoent* getprotobyname(const char* name); /** Fehlerstatus fuer gethostbyaddr() und gethostbyname() */ extern int h_errno; -/** Werte fuer h_error */ +/** Werte fuer h_errno */ enum { HOST_NOT_FOUND, NO_DATA, @@ -86,5 +86,17 @@ enum { TRY_AGAIN, }; +/** + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck + */ +const char* hstrerror(int error); + +/** + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. + */ +void herror(const char* str); + + #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 44b45b5..f747da6 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -57,6 +57,40 @@ unsigned short int ntohs(unsigned short int netshort) } /** + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck + */ +const char* hstrerror(int error) +{ + static const char* errors[] = { + [HOST_NOT_FOUND] = "Unbekannter Rechner", + [NO_DATA] = "Der gesuchte Name hat keine IP-Adresse", + [NO_RECOVERY] = "Ein DNS-Fehler ist aufgetreten", + [TRY_AGAIN] = "Zeitweiliger DNS-Fehler; erneut versuchen", + }; + + if ((error < HOST_NOT_FOUND) || (error > TRY_AGAIN)) { + return NULL; + } + + return errors[error]; +} + +/** + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. + */ +void herror(const char* str) +{ + if (str && *str) { + fprintf(stderr, "%s: %s\n", str, hstrerror(h_errno)); + } else { + fprintf(stderr, "%s\n", hstrerror(h_errno)); + } +} + + + +/** * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen * 32-Bit-Wert um. * -- 1.6.0.2 From kevin at tyndur.org Tue Aug 11 19:35:38 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 19:35:38 +0200 Subject: [tyndur-devel] [PATCH 3/3] libc: POSIX: libgen.h In-Reply-To: <1250012138-17824-1-git-send-email-kevin@tyndur.org> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> Message-ID: <1250012138-17824-4-git-send-email-kevin@tyndur.org> + libc: POSIX: libgen.h mit dirname() und basename() hinzugefuegt Signed-off-by: Kevin Wolf --- src/modules/include/libgen.h | 46 +++++++++++++++++++++++ src/modules/lib/posix/libgen.c | 80 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/libgen.h create mode 100644 src/modules/lib/posix/libgen.c diff --git a/src/modules/include/libgen.h b/src/modules/include/libgen.h new file mode 100644 index 0000000..5b5f58c --- /dev/null +++ b/src/modules/include/libgen.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009 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. + * + * 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 _LIBGEN_H_ +#define _LIBGEN_H_ + +/** + * Trennt den Dateinamen aus einem Pfad heraus. Wenn path ein Nullpointer ist, + * wird "." zurueckgegeben. Der Rueckgabestring befindet sich in einem + * statischen Puffer. + */ +char* basename(char* path); + +/** + * Trennt den Verzeichnisnamen aus einem Pfad heraus. Wenn path ein Nullpointer + * ist, wird "." zurueckgegeben. Der Rueckgabestring befindet sich in einem + * statischen Puffer. + */ +char* dirname(char* path); + +#endif diff --git a/src/modules/lib/posix/libgen.c b/src/modules/lib/posix/libgen.c new file mode 100644 index 0000000..b483bf5 --- /dev/null +++ b/src/modules/lib/posix/libgen.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2009 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. + * + * 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. + */ + +#include +#include +#include +#include + +/** + * Trennt den Dateinamen aus einem Pfad heraus. Wenn path ein Nullpointer ist, + * wird "." zurueckgegeben. Der Rueckgabestring befindet sich in einem + * statischen Puffer. + */ +char* basename(char* path) +{ + static char result[256]; + char* ret; + + if (!path) { + result[0] = '.'; + result[1] = '\0'; + return result; + } + + ret = io_split_filename(path); + strncpy(result, ret, 255); + result[255] = '\0'; + free(ret); + + return result; +} + +/** + * Trennt den Verzeichnisnamen aus einem Pfad heraus. Wenn path ein Nullpointer + * ist, wird "." zurueckgegeben. Der Rueckgabestring befindet sich in einem + * statischen Puffer. + */ +char* dirname(char* path) +{ + static char result[256]; + char* ret; + + if (!path) { + result[0] = '.'; + result[1] = '\0'; + return result; + } + + ret = io_split_dirname(path); + strncpy(result, ret, 255); + result[255] = '\0'; + free(ret); + + return result; +} -- 1.6.0.2 From xanclic at googlemail.com Tue Aug 11 20:02:56 2009 From: xanclic at googlemail.com (Max Reitz) Date: Tue, 11 Aug 2009 20:02:56 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_T=C3=BDndurspezifisches_ausg?= =?utf-8?q?eweitet=2C_string=2Eh?= Message-ID: <1250013776-17404-1-git-send-email-xanclic@googlemail.com> * string.h muss bei einigen Dateien eingebunden werden (ist jedenfalls nützlich, um keine implicit declarations zu bekommen) * Da gehört noch mehr nach #ifdef TYNDUR - ohne das gibt es unter nicht-týndur-Betriebs- systemem zweimal "unused" bei sis900 --- e1000/device.c | 1 + e1000/main.c | 1 + pcnet/main.c | 1 + pcnet/pcnet.c | 1 + sis900/device.c | 1 + sis900/main.c | 6 ++++-- 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/e1000/device.c b/e1000/device.c index 7026958..5979e03 100644 --- a/e1000/device.c +++ b/e1000/device.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi.h" #include "cdi/misc.h" diff --git a/e1000/main.c b/e1000/main.c index 39da9f6..a96e055 100644 --- a/e1000/main.c +++ b/e1000/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi/net.h" #include "cdi/pci.h" diff --git a/pcnet/main.c b/pcnet/main.c index 9feac59..d3e3a83 100644 --- a/pcnet/main.c +++ b/pcnet/main.c @@ -35,6 +35,7 @@ #include #include +#include #include "cdi/net.h" #include "cdi/pci.h" diff --git a/pcnet/pcnet.c b/pcnet/pcnet.c index 8bccbf4..c934910 100644 --- a/pcnet/pcnet.c +++ b/pcnet/pcnet.c @@ -37,6 +37,7 @@ #include "cdi/io.h" #include +#include static void pcnet_handle_interrupt(struct cdi_device* device); static void pcnet_reset(struct pcnet_device *netcard); diff --git a/sis900/device.c b/sis900/device.c index fd433f1..ab0479a 100644 --- a/sis900/device.c +++ b/sis900/device.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi.h" #include "cdi/misc.h" diff --git a/sis900/main.c b/sis900/main.c index bee701e..4bf028f 100644 --- a/sis900/main.c +++ b/sis900/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi/net.h" #include "cdi/pci.h" @@ -43,9 +44,8 @@ struct module_options { #ifdef TYNDUR uint32_t string_to_ip(char* ip); -#endif - static void process_parameter(struct module_options* options, char* param); +#endif struct sis900_driver { struct cdi_net_driver net; @@ -78,11 +78,13 @@ int init_sis900(int argc, char* argv[]) */ static void sis900_driver_init(int argc, char* argv[]) { +#ifdef TYNDUR struct module_options options = { // TODO Auf 0 setzen und am Ende prüfen und ggf. einfach was // freies suchen .ip = 0x0b01a8c0 }; +#endif // Konstruktor der Vaterklasse cdi_net_driver_init((struct cdi_net_driver*) &driver); -- 1.6.0.2 From kevin at tyndur.org Tue Aug 11 20:08:32 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 20:08:32 +0200 Subject: [tyndur-devel] [PATCH] CDI/Sound In-Reply-To: <1249946535-15187-1-git-send-email-user@Cazad-Dum> References: <1249946535-15187-1-git-send-email-user@Cazad-Dum> Message-ID: <20090811180821.GA9759@silvanus> On Tue, Aug 11, 2009 at 01:22:15AM +0200, Patrick at sv0.famkaufmann.info wrote: > From: deathly-sequences at web.de > > --- > src/modules/cdi/ac97/Makefile.all | 6 + > src/modules/cdi/ac97/ac97.c | 189 ++++++++++++++++++++++++++++++++++ > src/modules/cdi/ac97/includes/ac97.h | 80 ++++++++++++++ > src/modules/cdi/ac97/main.c | 123 ++++++++++++++++++++++ > src/modules/cdi/include/cdi.h | 1 + > src/modules/cdi/include/cdi/sound.h | 151 +++++++++++++++++++++++++++ > 6 files changed, 550 insertions(+), 0 deletions(-) > create mode 100644 src/modules/cdi/ac97/Makefile.all > create mode 100644 src/modules/cdi/ac97/ac97.c > create mode 100644 src/modules/cdi/ac97/includes/ac97.h > create mode 100644 src/modules/cdi/ac97/main.c > create mode 100644 src/modules/cdi/include/cdi/sound.h Ich ignoriere mal den AC97-Treiber, von dem hast du ja gesagt, dass er noch nicht fertig genug ist. Sag Bescheid, wenn ich ihn anschauen soll. > diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h > index c6215a6..c3a48ee 100644 > --- a/src/modules/cdi/include/cdi.h > +++ b/src/modules/cdi/include/cdi.h > @@ -25,6 +25,7 @@ typedef enum { > CDI_NETWORK = 1, > CDI_STORAGE = 2, > CDI_SCSI = 3, > + CDI_SOUND = 4, > } cdi_device_type_t; > > struct cdi_driver; > diff --git a/src/modules/cdi/include/cdi/sound.h b/src/modules/cdi/include/cdi/sound.h > new file mode 100644 > index 0000000..680553a > --- /dev/null > +++ b/src/modules/cdi/include/cdi/sound.h > @@ -0,0 +1,151 @@ > + > +/** @file sound.h > + * > + * Diese Datei enthält die Datenstrukturen, von denen die Datenstrukturen der > + * Treiber abgeleitet werden. Außerdem werden hier die Funktionsprototypen für > + * die Schnittstelle Soundtreiber, CDI definiert. > + **/ > + > +/** > + * Treiber für die Soundkarten. > + * > + * @defgroup sound > + **/ > + > +#ifndef __sound_h__ > +#define __sound_h__ > + > +#include > +#include > + > +#include "cdi.h" > + > +/* Angelehnt an net.h */ > + > +struct cdi_sound_device{ > + struct cdi_device dev; > + /* Im folgenden bezeichnet driver immer das Gerät. */ Das klingt irgendwie auffällig falschrum. Ein Gerät sollte ein cdi_sound_device sein. Mit einem cdi_sound_driver kann der Treiber vermutlich nicht so viel anfangen, wenn er die ganzen Informationen ordentlich in einem cdi_sound_device abgelegt hat (wie das dein AC97-Treiber zu tun scheint) > + /* Ausführlichere Kommentare/Dokumentation findet man in den jeweiligen > + Implementationen der Treiber. Hier werden nur Funktionszeiger > + definiert. */ > + > + /** @brief Damit das Gerät auch beginnt Daten abzuspielen. > + * > + * Weißt den Treiber an, Daten abzuspielen, wenn neue vorhanden sind. > + * > + * @param driver Treiber, der die Daten abspielen soll. > + * > + */ > + void (*cdi_sound_play)(struct cdi_sound_driver *driver); > + > + /** @brief Hält die Audioausgabe des Treibers an. > + * > + * Wenn der Treiber nicht gerade von einer anderen Anwendung blockiert wird, > + * wird die Audioausgabe angehalten. Wird ignoriert, wenn der Treiber > + * 'in use' ist. > + * > + * @param driver Treiber, der die Audioausgabe anhalten soll. > + */ > + void (*cdi_sound_stop)(struct cdi_sound_driver *driver); Ich überlege grad, ob das reicht. Irgendeine Lib dahinter wird ja vermutlich mehrere Sounds zusammenmixen. Wenn jetzt einer von zwei gerade abgespielten Sounds gestoppt wird, brauchen wir eigentlich keinen kompletten Stop, sondern... * ... ein Stop direkt gefolgt von einem Start, das den übriggebliebenen Sound wieder startet. Dazu brauchen wir wenigstens die aktuelle Position, an der angehalten wurde. * ... oder ein cdi_sound_replace() oder sowas, das einen neuen Puffer kriegt, dort die aktuelle Stelle raussucht und an die Soundkarte schickt, was jetzt zu spielen ist Ist der Gedanke so ungefähr nachvollziehbar? > + > + /** @brief Ein Prozess darf die in_use Option betätigen. > + * > + * Die in use Option ist mir eingefallen, als ich mir das Zusammenspiel > + * Amarok, Firefox mit flashplayer plugin und der rest des Systems angesehen > + * habe. Die schließen sich gegenseitig aus. Sobald Amarok an ist, kann > + * der Rest nichts mehr abspielen. Hat auch gute Seiten. Funktionszeiger ... > + * > + * @param driver Treiber der in use gestellt werden soll. > + * @param pid Prozess ID des Prozesses. Dient später nur zur Überprüfung. > + * > + * @return 0 bei Erfolg. 1 bei Misserfolg. > + * > + */ > + uint32_t (*cdi_sound_in_use_enable)(struct cdi_sound_driver *driver, > + uint32_t pid); > + Zum einen solltest du drauf achten, keine Leerzeichen am Zeilenende zu haben (gibt noch einige mehr davon, hier ist es mir aufgefallen). Zum anderen ist das hier die falsche Ebene. Den Soundtreiber haben Sachen wie Prozesse nicht zu interessieren. Der Treiber spielt Sound ab, und das war's. Um Prozesse kann sich dann vielleicht die CDI-Lib kümmern. > + /** @brief Der gleiche Prozess darf das in_use Privileg abgeben. > + * > + * Anhand von pid wird nur überprüft ob der richtige Prozess die in use > + * Option abstellt. Funktionszeiger ... > + * > + * @param driver Treiber der die in use Option abschalten soll. > + * @param pid Prozessnummer. > + * > + * @return 0 bei Erfolg. 1 bei Misserfolg. > + */ > + uint32_t (*cdi_sound_in_use_disable)(struct cdi_sound_driver *driver, > + uint32_t pid); > + > + /** @brief Funktionszeiger für eine Schnittstelle, in der man den aktuellen > + * Status des Treibers/Gerätes abrufen kann. > + * > + * Diese Funktion ist dafür gedacht um herauszufinden ob der Treiber gerade > + * Daten abspielt oder nicht. Hier ist die Schnittstelle Treiber/CDI > + * > + * @param driver Soundtreiber, dessen Zustand ermittelt werden soll. > + * > + * @return Die Returncodes können von Treiber zu Treiber variieren. Hier > + * ist eine Liste, von Codes, die auf jeden Fall genauso > + * implementiert werden sollen (Zusätzliche können angehangen > + * werden): 0 - Treiber/Gerät nicht arbeitsbereit/initialisiert. > + * 1 - Gerät arbeitsbereit. Spielt keine Daten ab. 2 - Treiber > + * erhält Daten. 4 - Gerät spielt Daten ab. Datenempfang möglich. > + * 8 - Gerät ist gestoppt, aber es sind noch Daten zum spielen > + * übrig. Neue Daten können jederzeit hinzugefügt werden. > + * 16 - Bit ist gesetzt, wenn Qucik Mixing (lineare Superposition > + * mit Clippingunterdrückung) erlaubt ist. 32 - Dieses Bit zeigt an > + * ob der Treiber gerade von einem Prozess "blockiert" wird. > + * > + */ > + uint32_t (*cdi_sound_driver_state)(struct cdi_sound_driver *driver); Nein, sie kann nicht von Treiber zu Treiber variieren. Der Sinn und Zweck von CDI ist ein _standardisiertes_ Interface. Also: Ich schreibe anhand dieser Dokumentation eine CDI-Implementierung für mein OS, dann nehme ich einen beliebigen dazu passenden Soundtreiber und es funktioniert. Oder ich schreibe einen Soundtreiber, der sich daran hält, und kopiere ihn auf jedes beliebige OS, das CDI kann, und er funktioniert. An dieser Stelle braucht es also eine definitive Aussage, was es gibt und was nicht. Die Sachen, die es gibt, sollten als Konstante definiert werden (z.B. irgendwo ein enum für die zulässigen status) statt direkt magische Zahlen zu verwenden. > + > + /** @brief Funktionszeiger für eine Schnittstelle, die dem Treiber die > + * als nächstes abzuspielenden Daten übergibt. > + * > + * Dies ist ein Funktionszeiger und für die Schnittstelle Treiber CDI > + * gedacht. > + * > + * @param driver Soundtreiber an den die Daten geschickt werden sollen. > + * @param data_start Zeiger auf den Beginn der Daten. Es wird angenommen, > + * dass alle Daten hintereinander liegen. > + * @param data_length Länge des Datenblockes. > + * @param pid Datenbereiche werden Treiberintern mit einer PID versehen, um > + * diese z.B. noch zurückziehen zu können. Prozess beendet. > + * Datenbereiche wurden deallokiert. > + * > + * @return 0 - bei Erfolg, 1 - bei Fehler, wiederhohlung kann ihn beheben > + * 2 - Fehler nicht durch wiederhohlte Ausführung behebbar > + * kann. Wenn Gerät z.B. von einem Prozess benutzt wird, der Mixing > + * nicht zulassen will. Ansonnsten, werden Daten von verschiednen > + * Geräten linear superponiert, oder einfach nacheinander > + * abgespielt (Flags beachten). > + */ > + uint32_t (*cdi_sound_input_data)(struct cdi_sound_driver *driver, > + uint32_t* data_start, > + uint32_t data_length, > + uint32_t pid); Siehe oben, pid geht den Treiber nichts an. Kevin From m.nemo at gmx.net Tue Aug 11 21:10:04 2009 From: m.nemo at gmx.net (Andreas Freimuth) Date: Tue, 11 Aug 2009 21:10:04 +0200 Subject: [tyndur-devel] [PATCH] libc: gmtime() und localtime() Message-ID: <4A81C20C.7080109@gmx.net> -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : localtime.patch Dateityp : text/x-diff Dateigröße : 4799 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 899 bytes Beschreibung: OpenPGP digital signature URL : From kevin at tyndur.org Tue Aug 11 21:12:08 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 21:12:08 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_T=FDndurspezifisches_au?= =?iso-8859-1?q?sgeweitet=2C_string=2Eh?= In-Reply-To: <1250013776-17404-1-git-send-email-xanclic@googlemail.com> References: <1250013776-17404-1-git-send-email-xanclic@googlemail.com> Message-ID: <20090811191207.GB9759@silvanus> On Tue, Aug 11, 2009 at 08:02:56PM +0200, Max Reitz wrote: > * string.h muss bei einigen Dateien eingebunden > werden (ist jedenfalls nützlich, um keine > implicit declarations zu bekommen) > * Da gehört noch mehr nach #ifdef TYNDUR - ohne > das gibt es unter nicht-týndur-Betriebs- > systemem zweimal "unused" bei sis900 Ich nehme an, das ist gegen cdi.git? Ich habe dort grad die letzten Änderungen aus dem tyndur-Repo übernommen und jetzt passt dein Patch nicht mehr drauf. Kannst du den nochmal gegen die aktuelle Version schicken? (Der Teil mit dem #ifdef dürfte unnötig geworden sein) Außerdem bitte das Signed-off-by nicht vergessen. From kevin at tyndur.org Tue Aug 11 21:39:07 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 11 Aug 2009 21:39:07 +0200 Subject: [tyndur-devel] [PATCH] libc: gmtime() und localtime() In-Reply-To: <4A81C20C.7080109@gmx.net> References: <4A81C20C.7080109@gmx.net> Message-ID: <20090811193900.GC9759@silvanus> On Tue, Aug 11, 2009 at 09:10:04PM +0200, Andreas Freimuth wrote: > > # HG changeset patch > # User Andreas Freimuth > # Date 1250016661 -7200 > # Node ID 35b73a071d85076542f0e0f4e1a466a9e784a45d > # Parent 8134734351cb5895acc183021bd8a6b9af38cd0a > + libc: gmtime() und localtime() > localtime geht noch fest von UTC+1 aus Vorneweg ein paar allgemeine Sachen: Die Codeformatierung ist so nicht ganz in Ordnung (wir benutzen 4 Leerzeichen als Einrückung, du hast Tabs geschickt; außerdem hast du manchmal übrige Leerzeichen am Zeilenende). Und das Signed-off-by fehlt. Die Details inline: > > diff --git a/src/modules/include/time.h b/src/modules/include/time.h > --- a/src/modules/include/time.h > +++ b/src/modules/include/time.h > @@ -46,6 +46,13 @@ > > time_t time(time_t* t); > > +/// Timestamp in tm-Struct einfuellen > +struct tm* gmtime(const time_t* time_ptr); > +struct tm* gmtime_r(const time_t* time_ptr, struct tm* result); > + > +struct tm* localtime(const time_t* time_ptr); > +struct tm* localtime_r(const time_t* time_ptr, struct tm* result); > + > #ifndef CONFIG_LIBC_NO_STUBS > /// Datum und Uhrzeit in einen String umwandeln > char* ctime(const time_t* time_ptr); > @@ -53,11 +60,6 @@ > /// Zeit und Datum als String > char* asctime(const struct tm* time_ptr); > > -/// Timestamp in tm-Struct einfuellen > -struct tm* gmtime(const time_t* time_ptr); > - > -struct tm* localtime(const time_t* time_ptr); > - > time_t mktime(struct tm* time_ptr); > #endif > > diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c > --- a/src/modules/lib/stdlibc/time.c > +++ b/src/modules/lib/stdlibc/time.c > @@ -30,18 +30,9 @@ > #include > #include > > +static struct tm tm; > + > #ifndef CONFIG_LIBC_NO_STUBS > -static struct tm tm = { > - .tm_wday = 3, > - .tm_mday = 42, > - .tm_mon = 6, > - .tm_year = 1337, > - .tm_yday = 1337, > - > - .tm_hour = 13, > - .tm_min = 37, > - .tm_sec = 42 > -}; > static char* asctime_buf = "Wed Jun 42 13:37:42 1337\n"; > static char* ctime_string = "Wed Jun 42 13:37:42 1337\n"; > #endif > @@ -71,30 +62,114 @@ > return result; > } > > -#ifndef CONFIG_LIBC_NO_STUBS > /** > - * TODO > - **/ > -struct tm* localtime(const time_t* time) > + * Timestamp, unter Bachtung der Zeitzone, in tm-Struktur einfuellen > + * > + * @param timer_ptr Pointer auf den Timestamp > + * @param result Pointer auf die tm-Struktur in die Fehlt da nicht irgendwie ein halber Satz? > + * > + * @return result > + */ > +struct tm* localtime_r(const time_t* time_ptr, struct tm* result) > { > - // TODO > - return &tm; > + /* FIXME hier wird fest von UTC+1 ausgegangen */ > + time_t ltime = *time_ptr + 60*60; > + return gmtime_r(<ime, result); > +} > + > +/** > + * Timestamp, unter Bachtung der Zeitzone, in tm-Struktur einfuellen > + * > + * @param timer_ptr Pointer auf den Timestamp > + * > + * @return Pointer auf die interne statisch allozierte tm-Struktur. Diese kann > + * bei jedem Aufruf einer Zeitfunktion ueberschrieben werden! > + */ > +struct tm* localtime(const time_t* time_ptr) > +{ > + return localtime_r(time_ptr, &tm); > } > > /** > * Timestamp in tm-Struktur einfuellen > * > - * @param time_ptr Pointer auf den Timestamp > + * @param timer_ptr Pointer auf den Timestamp > + * @param result Pointer auf die tm-Struktur in die > + * > + * @return result > + */ > +struct tm* gmtime_r(const time_t* timer_ptr, struct tm* result) > +{ > + static const int monat[2][12] = { > + { 0,31,59,90,120,151,181,212,243,273,304,334}, > + { 0,31,60,91,121,152,182,213,244,274,305,335} > + }; > + time_t time = *timer_ptr; > + int schaltjahr = 0; > + > + /* die Uhrzeit ist noch einfach */ > + result->tm_sec = time % 60; > + time /= 60; > + result->tm_min = time % 60; > + time /= 60; > + result->tm_hour = time % 24; > + time /= 24; > + > + /* 01.01.70 wahr ein Donnerstag (5) */ > + result->tm_wday = (time + 5) % 7; Müßte Donnerstag nicht 4 sein? Die Manpage sagt 0 = Sonntag. > + > + /* jetzt kommen die Schaltjahre ins Spiel */ > + > + /* rebase auf 1969-01-01 00:00:00 UTC > + * dann ist jedes 4. Jahr ein Schaltjahr > + */ > + time += 365; > + > + int tmp_years = 69 + 4 * (time / (4*365 + 1)); > + time %= 4*365 + 1; > + > + if( (time / 365) > 2 ) { > + schaltjahr = 1; > + result->tm_year = tmp_years + 3; > + result->tm_yday = time - 3*365 + 1; > + } else { > + result->tm_year = tmp_years + (time / 365); > + result->tm_yday = time % 365 + 1; > + } tm_yday fängt bei 0 für 1. Januar an. Damit ist das + 1 dann eins zuviel, oder? > + > + /* den richtigen monat raussuchen */ > + if( monat[schaltjahr][result->tm_yday / 30] > result->tm_yday ) { > + result->tm_mon = (result->tm_yday / 30) - 1; > + } else if( monat[schaltjahr][result->tm_yday / 30 + 1] > result->tm_yday ) { > + result->tm_mon = (result->tm_yday / 30); > + } else { > + result->tm_mon = (result->tm_yday / 30) + 1; > + } Hm, lustige Methode. Könnte aber sogar hinkommen. ;-) > + > + result->tm_mday = 1 + (result->tm_yday - monat[schaltjahr][result->tm_mon]); > + > + /* keine Ahnung was das ist */ > + result->tm_isdst = -1; Das ist ein Flag, das gesetzt ist, wenn das Datum in der Sommerzeit (DST = Daylight Saving Time) liegt. Sieht ansonsten gut aus, soweit ich das sagen kann. From xanclic at googlemail.com Tue Aug 11 21:26:38 2009 From: xanclic at googlemail.com (Max Reitz) Date: Tue, 11 Aug 2009 21:26:38 +0200 Subject: [tyndur-devel] [PATCH] string.h Message-ID: <1250018798-21689-1-git-send-email-xanclic@googlemail.com> * string.h sollte für memset() & Co. inkludiert werden Signed-off-by: Max Reitz --- e1000/device.c | 1 + e1000/main.c | 1 + pcnet/main.c | 1 + pcnet/pcnet.c | 1 + sis900/device.c | 1 + sis900/main.c | 2 ++ 6 files changed, 7 insertions(+), 0 deletions(-) diff --git a/e1000/device.c b/e1000/device.c index 5534b3b..48f3a58 100644 --- a/e1000/device.c +++ b/e1000/device.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi.h" #include "cdi/misc.h" diff --git a/e1000/main.c b/e1000/main.c index 39da9f6..a96e055 100644 --- a/e1000/main.c +++ b/e1000/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi/net.h" #include "cdi/pci.h" diff --git a/pcnet/main.c b/pcnet/main.c index dd94159..a2c3929 100644 --- a/pcnet/main.c +++ b/pcnet/main.c @@ -35,6 +35,7 @@ #include #include +#include #include "cdi/net.h" #include "cdi/pci.h" diff --git a/pcnet/pcnet.c b/pcnet/pcnet.c index af79158..130b29a 100644 --- a/pcnet/pcnet.c +++ b/pcnet/pcnet.c @@ -37,6 +37,7 @@ #include "cdi/io.h" #include +#include static void pcnet_handle_interrupt(struct cdi_device* device); static void pcnet_reset(struct pcnet_device *netcard); diff --git a/sis900/device.c b/sis900/device.c index fd433f1..ab0479a 100644 --- a/sis900/device.c +++ b/sis900/device.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "cdi.h" #include "cdi/misc.h" diff --git a/sis900/main.c b/sis900/main.c index 1904c6e..1409c90 100644 --- a/sis900/main.c +++ b/sis900/main.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "cdi/net.h" #include "cdi/pci.h" -- 1.6.0.2 From m.nemo at gmx.net Tue Aug 11 22:20:13 2009 From: m.nemo at gmx.net (Andreas Freimuth) Date: Tue, 11 Aug 2009 22:20:13 +0200 Subject: [tyndur-devel] [PATCH] libc: gmtime() und localtime() In-Reply-To: <20090811193900.GC9759@silvanus> References: <4A81C20C.7080109@gmx.net> <20090811193900.GC9759@silvanus> Message-ID: <4A81D27D.6000906@gmx.net> Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : localtime.patch Dateityp : text/x-diff Dateigröße : 5277 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 899 bytes Beschreibung: OpenPGP digital signature URL : From patrick_steinmueller at gmx.de Tue Aug 11 23:24:17 2009 From: patrick_steinmueller at gmx.de (=?iso-8859-1?Q?=22Patrick_Steinm=FCller=22?=) Date: Tue, 11 Aug 2009 23:24:17 +0200 Subject: [tyndur-devel] [PATCH] CDI/Sound In-Reply-To: <20090811180821.GA9759@silvanus> References: <1249946535-15187-1-git-send-email-user@Cazad-Dum> <20090811180821.GA9759@silvanus> Message-ID: <20090811212417.28830@gmx.net> -------- Original-Nachricht -------- > Datum: Tue, 11 Aug 2009 20:08:32 +0200 > Von: Kevin Wolf > An: tyndur-devel at tyndur.org > Betreff: Re: [tyndur-devel] [PATCH] CDI/Sound > On Tue, Aug 11, 2009 at 01:22:15AM +0200, Patrick at sv0.famkaufmann.info > wrote: > > From: deathly-sequences at web.de > > > > --- > > src/modules/cdi/ac97/Makefile.all | 6 + > > src/modules/cdi/ac97/ac97.c | 189 > ++++++++++++++++++++++++++++++++++ > > src/modules/cdi/ac97/includes/ac97.h | 80 ++++++++++++++ > > src/modules/cdi/ac97/main.c | 123 ++++++++++++++++++++++ > > src/modules/cdi/include/cdi.h | 1 + > > src/modules/cdi/include/cdi/sound.h | 151 +++++++++++++++++++++++++++ > > 6 files changed, 550 insertions(+), 0 deletions(-) > > create mode 100644 src/modules/cdi/ac97/Makefile.all > > create mode 100644 src/modules/cdi/ac97/ac97.c > > create mode 100644 src/modules/cdi/ac97/includes/ac97.h > > create mode 100644 src/modules/cdi/ac97/main.c > > create mode 100644 src/modules/cdi/include/cdi/sound.h > > Ich ignoriere mal den AC97-Treiber, von dem hast du ja gesagt, dass er > noch nicht fertig genug ist. Sag Bescheid, wenn ich ihn anschauen soll. > > > diff --git a/src/modules/cdi/include/cdi.h > b/src/modules/cdi/include/cdi.h > > index c6215a6..c3a48ee 100644 > > --- a/src/modules/cdi/include/cdi.h > > +++ b/src/modules/cdi/include/cdi.h > > @@ -25,6 +25,7 @@ typedef enum { > > CDI_NETWORK = 1, > > CDI_STORAGE = 2, > > CDI_SCSI = 3, > > + CDI_SOUND = 4, > > } cdi_device_type_t; > > > > struct cdi_driver; > > diff --git a/src/modules/cdi/include/cdi/sound.h > b/src/modules/cdi/include/cdi/sound.h > > new file mode 100644 > > index 0000000..680553a > > --- /dev/null > > +++ b/src/modules/cdi/include/cdi/sound.h > > @@ -0,0 +1,151 @@ > > + > > +/** @file sound.h > > + * > > + * Diese Datei enthält die Datenstrukturen, von denen die > Datenstrukturen der > > + * Treiber abgeleitet werden. Außerdem werden hier die > Funktionsprototypen für > > + * die Schnittstelle Soundtreiber, CDI definiert. > > + **/ > > + > > +/** > > + * Treiber für die Soundkarten. > > + * > > + * @defgroup sound > > + **/ > > + > > +#ifndef __sound_h__ > > +#define __sound_h__ > > + > > +#include > > +#include > > + > > +#include "cdi.h" > > + > > +/* Angelehnt an net.h */ > > + > > +struct cdi_sound_device{ > > + struct cdi_device dev; > > + /* Im folgenden bezeichnet driver immer das Gerät. */ > > Das klingt irgendwie auffällig falschrum. Ein Gerät sollte ein > cdi_sound_device sein. Mit einem cdi_sound_driver kann der Treiber > vermutlich nicht so viel anfangen, wenn er die ganzen Informationen > ordentlich in einem cdi_sound_device abgelegt hat (wie das dein > AC97-Treiber zu tun scheint) gefixt. > > > + /* Ausführlichere Kommentare/Dokumentation findet man in den > jeweiligen > > + Implementationen der Treiber. Hier werden nur Funktionszeiger > > + definiert. */ > > + > > + /** @brief Damit das Gerät auch beginnt Daten abzuspielen. > > + * > > + * Weißt den Treiber an, Daten abzuspielen, wenn neue vorhanden > sind. > > + * > > + * @param driver Treiber, der die Daten abspielen soll. > > + * > > + */ > > + void (*cdi_sound_play)(struct cdi_sound_driver *driver); > > + > > + /** @brief Hält die Audioausgabe des Treibers an. > > + * > > + * Wenn der Treiber nicht gerade von einer anderen Anwendung > blockiert wird, > > + * wird die Audioausgabe angehalten. Wird ignoriert, wenn der > Treiber > > + * 'in use' ist. > > + * > > + * @param driver Treiber, der die Audioausgabe anhalten soll. > > + */ > > + void (*cdi_sound_stop)(struct cdi_sound_driver *driver); > > Ich überlege grad, ob das reicht. Irgendeine Lib dahinter wird ja > vermutlich mehrere Sounds zusammenmixen. Wenn jetzt einer von zwei > gerade abgespielten Sounds gestoppt wird, brauchen wir eigentlich keinen > kompletten Stop, sondern... > > * ... ein Stop direkt gefolgt von einem Start, das den übriggebliebenen > Sound wieder startet. Dazu brauchen wir wenigstens die aktuelle > Position, an der angehalten wurde. > * ... oder ein cdi_sound_replace() oder sowas, das einen neuen Puffer > kriegt, dort die aktuelle Stelle raussucht und an die Soundkarte > schickt, was jetzt zu spielen ist > > Ist der Gedanke so ungefähr nachvollziehbar? > Hmm ich glaube aber dass das unnötig ist. Da ein buffer weniger als eine Sekunde spielt. Wenn ein Sound gestoppt wird, kann ja CDI/Lib den übernächsten Buffer neuschreiben lassen. Bei 44,1 kHz abtastrate sind 2 buffer, maximal 1,49 Sekunden. Das heißt, wenn es einem wirklich auf speed ankommt kann man ab dem übernächsten Buffer alles neuschreiben. Der nächste macht wohl keinen sinn, da man nicht weiß wo die Ausführung im aktuelle Buffer gerade ist. Es sollte jetzt auch nicht so häufig vorkommen, dass ein Sound so fix geändert werden muss. Wenn man kein quickmix reinbaut, dann ist es einfacher, weil man dann einfach anhalten kann, wenn der sound gerade gespielt wird und zum nächsten springen kann, oder den sound vorher einfach aus der queue löschen kann. > + > > > + /** @brief Ein Prozess darf die in_use Option betätigen. > > + * > > + * Die in use Option ist mir eingefallen, als ich mir das > Zusammenspiel > > + * Amarok, Firefox mit flashplayer plugin und der rest des Systems > angesehen > > + * habe. Die schließen sich gegenseitig aus. Sobald Amarok an ist, > kann > > + * der Rest nichts mehr abspielen. Hat auch gute Seiten. > Funktionszeiger ... > > + * > > + * @param driver Treiber der in use gestellt werden soll. > > + * @param pid Prozess ID des Prozesses. Dient später nur zur > Überprüfung. > > + * > > + * @return 0 bei Erfolg. 1 bei Misserfolg. > > + * > > + */ > > + uint32_t (*cdi_sound_in_use_enable)(struct cdi_sound_driver > *driver, > > + uint32_t pid); > > + > > Zum einen solltest du drauf achten, keine Leerzeichen am Zeilenende zu > haben (gibt noch einige mehr davon, hier ist es mir aufgefallen). > > Zum anderen ist das hier die falsche Ebene. Den Soundtreiber haben > Sachen wie Prozesse nicht zu interessieren. Der Treiber spielt Sound ab, > und das war's. Um Prozesse kann sich dann vielleicht die CDI-Lib > kümmern. gefixt. > > > + /** @brief Der gleiche Prozess darf das in_use Privileg abgeben. > > + * > > + * Anhand von pid wird nur überprüft ob der richtige Prozess die > in use > > + * Option abstellt. Funktionszeiger ... > > + * > > + * @param driver Treiber der die in use Option abschalten soll. > > + * @param pid Prozessnummer. > > + * > > + * @return 0 bei Erfolg. 1 bei Misserfolg. > > + */ > > + uint32_t (*cdi_sound_in_use_disable)(struct cdi_sound_driver > *driver, > > + uint32_t pid); > > + > > + /** @brief Funktionszeiger für eine Schnittstelle, in der man den > aktuellen > > + * Status des Treibers/Gerätes abrufen kann. > > + * > > + * Diese Funktion ist dafür gedacht um herauszufinden ob der > Treiber gerade > > + * Daten abspielt oder nicht. Hier ist die Schnittstelle > Treiber/CDI > > + * > > + * @param driver Soundtreiber, dessen Zustand ermittelt werden > soll. > > + * > > + * @return Die Returncodes können von Treiber zu Treiber > variieren. Hier > > + * ist eine Liste, von Codes, die auf jeden Fall genauso > > + * implementiert werden sollen (Zusätzliche können > angehangen > > + * werden): 0 - Treiber/Gerät nicht > arbeitsbereit/initialisiert. > > + * 1 - Gerät arbeitsbereit. Spielt keine Daten ab. 2 - > Treiber > > + * erhält Daten. 4 - Gerät spielt Daten ab. Datenempfang > möglich. > > + * 8 - Gerät ist gestoppt, aber es sind noch Daten zum > spielen > > + * übrig. Neue Daten können jederzeit hinzugefügt > werden. > > + * 16 - Bit ist gesetzt, wenn Qucik Mixing (lineare > Superposition > > + * mit Clippingunterdrückung) erlaubt ist. 32 - Dieses Bit > zeigt an > > + * ob der Treiber gerade von einem Prozess "blockiert" > wird. > > + * > > + */ > > + uint32_t (*cdi_sound_driver_state)(struct cdi_sound_driver > *driver); > > Nein, sie kann nicht von Treiber zu Treiber variieren. Der Sinn und > Zweck von CDI ist ein _standardisiertes_ Interface. Also: Ich schreibe > anhand dieser Dokumentation eine CDI-Implementierung für mein OS, dann > nehme ich einen beliebigen dazu passenden Soundtreiber und es > funktioniert. > > Oder ich schreibe einen Soundtreiber, der sich daran hält, und kopiere > ihn auf jedes beliebige OS, das CDI kann, und er funktioniert. > > An dieser Stelle braucht es also eine definitive Aussage, was es gibt > und was nicht. Die Sachen, die es gibt, sollten als Konstante definiert > werden (z.B. irgendwo ein enum für die zulässigen status) statt direkt > magische Zahlen zu verwenden. > gefixt. > > + > > + /** @brief Funktionszeiger für eine Schnittstelle, die dem Treiber > die > > + * als nächstes abzuspielenden Daten übergibt. > > + * > > + * Dies ist ein Funktionszeiger und für die Schnittstelle Treiber > CDI > > + * gedacht. > > + * > > + * @param driver Soundtreiber an den die Daten geschickt werden > sollen. > > + * @param data_start Zeiger auf den Beginn der Daten. Es wird > angenommen, > > + * dass alle Daten hintereinander liegen. > > + * @param data_length Länge des Datenblockes. > > + * @param pid Datenbereiche werden Treiberintern mit einer PID > versehen, um > > + * diese z.B. noch zurückziehen zu können. Prozess > beendet. > > + * Datenbereiche wurden deallokiert. > > + * > > + * @return 0 - bei Erfolg, 1 - bei Fehler, wiederhohlung kann ihn > beheben > > + * 2 - Fehler nicht durch wiederhohlte Ausführung behebbar > > + * kann. Wenn Gerät z.B. von einem Prozess benutzt wird, > der Mixing > > + * nicht zulassen will. Ansonnsten, werden Daten von > verschiednen > > + * Geräten linear superponiert, oder einfach nacheinander > > + * abgespielt (Flags beachten). > > + */ > > + uint32_t (*cdi_sound_input_data)(struct cdi_sound_driver *driver, > > + uint32_t* data_start, > > + uint32_t data_length, > > + uint32_t pid); > > Siehe oben, pid geht den Treiber nichts an. > gefixt. > Kevin > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 From m.nemo at gmx.net Wed Aug 12 01:11:40 2009 From: m.nemo at gmx.net (Andreas Freimuth) Date: Wed, 12 Aug 2009 01:11:40 +0200 Subject: [tyndur-devel] [PATCH] libc: gmtime() und localtime() In-Reply-To: <4A81D27D.6000906@gmx.net> References: <4A81C20C.7080109@gmx.net> <20090811193900.GC9759@silvanus> <4A81D27D.6000906@gmx.net> Message-ID: <4A81FAAC.3020609@gmx.net> Ich habe es tatsächlich geschaft noch einen neuen Fehler einzubauen. -- Andreas Freimuth -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : localtime.patch Dateityp : text/x-diff Dateigröße : 5281 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 899 bytes Beschreibung: OpenPGP digital signature URL : From alexanderkluth at gmx.de Wed Aug 12 05:23:04 2009 From: alexanderkluth at gmx.de (alexanderkluth at gmx.de) Date: Wed, 12 Aug 2009 05:23:04 +0200 Subject: [tyndur-devel] [PATCH] strftime() In-Reply-To: <1> References: <1> Message-ID: <1250047384-16310-1-git-send-email-alexanderkluth@gmx.de> From: Alexander Hartmut Kluth + strftime() hinzugefügt + enum's und nen const-Array hinzugefügt, die das Leben leichter machen Signed-off-by: Alexander Hartmut Kluth --- src/modules/include/time.h | 2 + src/modules/lib/stdlibc/time.c | 233 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+), 0 deletions(-) diff --git a/src/modules/include/time.h b/src/modules/include/time.h index 4ee4b2e..b6c928e 100644 --- a/src/modules/include/time.h +++ b/src/modules/include/time.h @@ -46,6 +46,8 @@ struct tm { time_t time(time_t* t); +size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm); + #ifndef CONFIG_LIBC_NO_STUBS /// Datum und Uhrzeit in einen String umwandeln char* ctime(const time_t* time_ptr); diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c index 76e82d0..70b4902 100644 --- a/src/modules/lib/stdlibc/time.c +++ b/src/modules/lib/stdlibc/time.c @@ -46,6 +46,27 @@ static char* asctime_buf = "Wed Jun 42 13:37:42 1337\n"; static char* ctime_string = "Wed Jun 42 13:37:42 1337\n"; #endif +enum { + aJan, aFeb, aMar, aApr, aMay, aJun, aJul, aAug, aSep, aOct, aNov, aDec, + Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, + aSun, aMon, aTue, aWed, aThu, aFri, aSat, + Sun, Mon, Tue, Wed, Thu, Fri, Sat, + Local_time, Local_date, DFL_FMT, + AM, PM, DATE_FMT, + LAST +}; + +static const char * __time[] = { + "Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec", + "January", "February", "March","April", + "May","June", "July", "August", "September", + "October", "November", "December", + "Sun","Mon", "Tue", "Wed","Thu", "Fri","Sat", + "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday", + "%H:%M:%S","%m/%d/%y", "%a %b %d %H:%M:%S %Y", + "AM", "PM", "%a %b %e %T %Z %Y", NULL +}; + /** * Unix-Timestamp aus der aktuellen Zeit generieren. * @@ -128,3 +149,215 @@ time_t mktime(struct tm* time_ptr) #endif +/** + * Erzeugt einen String anhand eines Datumsformats aus einer bestimmten + * Anzahl Zeichen. + * + * TODO: %z für Zeitzone, %c und %C für lokalisierte Datums- und Zeitformat, + * %x und %X für lokalisiertes Datums-, bzw. Zeitformat + * + * @param str Pointer auf einen String + * @param maxs Maximal zu erzeugende Anzahl an Zeichen + * @param datestr Pointer auf den Datumsformatstring + * @param tm Struktur auf aktuelle Datums- und Zeitangaben + * + * @return 0 bei Misserfolg, ansonsten Anzahl erzeugter Zeichen + **/ +size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm) +{ + char i, c; + size_t size = 0, n; + char *nstr; + char dflcase[] = "%?"; + + // TODO: Aktuelle Zeit ermitteln + if (datestr == NULL) { + nstr = ""; + } + + // Datumsformatstring parsen + while ((c = *datestr++) != '\0') { + if (c != '%') { + if (++size >= maxs) { + return 0; + } + + *str++ = c; + continue; + } + + switch (*datestr++) { + case '%': + nstr = "%"; + break; + + case 'a': // Abgekürzter Wochentagsname + nstr = (char *)__time[aSun + tm->tm_wday]; + break; + + case 'A': // Wochentagsname + nstr = (char *)__time[Sun + tm->tm_wday]; + break; + + case 'b': // Abgekürzter Montatsname + case 'h': + nstr = (char *)__time[aJan + tm->tm_mon]; + break; + + + case 'B': // Monatsname + nstr = (char *)__time[Jan + tm->tm_mon]; + + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'd': // Tagesnummer + //p = itoa(tm->tm_mday, nstr, 2); + break; + + case 'D': + nstr = "%m/%d/%y"; + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'e': + itoa(tm->tm_mday, nstr, 2); + if (tm->tm_mday < 10) { + nstr[0] = ' '; + } + + break; + + case 'H': // 24-Stunden + itoa(tm->tm_hour, nstr, 2); + break; + + case 'I': // 12-Stunden + if ((i = tm->tm_hour % 12) == 0) + i = 12; + itoa(i, nstr, 2); + break; + + case 'j': // Julianisches Datum + itoa(tm->tm_yday + 1, nstr, 3); + break; + + case 'm': // Monats-Nummer + itoa(tm->tm_mon + 1, nstr, 2); + break; + + case 'M': // Minute + itoa(tm->tm_min, nstr, 2); + break; + + case 'n': // Newline + nstr = "\n"; + break; + + case 'p': // AM oder PM + if (tm->tm_hour >= 12) + nstr = (char *)__time[PM]; + else + nstr = (char *)__time[AM]; + break; + + case 'r': + if (tm->tm_hour >= 12) + nstr = "%I:%M:%S PM"; + else + nstr = "%I:%M:%S AM"; + + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'R': + nstr = "%H:%M"; + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'S': // Sekunden + //p = itoa(tm->tm_sec, nstr, 2); + break; + + case 't': // Tabulator + nstr = "\t"; + break; + + case 'T': + nstr = "%H:%M:%S"; + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'U': // Tagesnummer des Jahres, bei Sonntag als 1. Tag + itoa((tm->tm_yday - tm->tm_wday + 7)/7, nstr, 2); + break; + + case 'w': // Wochentagsnummer + itoa(tm->tm_wday, nstr, 1); + break; + + case 'W': // Tagesnummer des Jahres, bei Montag als 1. Tag + if ((i = 8 - tm->tm_wday) == 8) { + i = 1; + } + itoa((tm->tm_yday + i)/7, nstr, 2); + break; + + + case 'y': // Jahr in Form von "xx" + itoa(tm->tm_year, nstr, 2); + break; + + case 'Y': // Jahr in Form von "xxxx" + itoa(1900 + tm->tm_year, nstr, 4); + break; + + default: + dflcase[1] = *(datestr - 1); + nstr = (char *)dflcase; + break; + + continue; + } + + n = strlen(nstr); + + if ((size += n) >= maxs) { + return 0; + } + + strcpy(str, nstr); + str += n; + } + + *str = '\0'; + return size; +} + + + -- 1.6.0.4 From alexanderkluth at gmx.de Wed Aug 12 08:34:02 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Wed, 12 Aug 2009 08:34:02 +0200 Subject: [tyndur-devel] [PATCH] signal.h In-Reply-To: <1> References: <1> Message-ID: <1250058842-24300-1-git-send-email-alexanderkluth@gmx.de> + Neue Signale hinzugefügt Signed-off-by: Alexander Hartmut Kluth --- src/modules/include/signal.h | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h index d10bc2e..28eae8c 100644 --- a/src/modules/include/signal.h +++ b/src/modules/include/signal.h @@ -87,11 +87,27 @@ typedef uint32_t sig_atomic_t; /// Ende des frei verwendbaren Bereichs #define SIGRTMAX 63 -// Hier sollte noch viel mehr kommen +/// Prozess stoppen +#define SIGTSTP 64 + +/// Prozess gestoppt +#define SIGSTOP 65 + +/// Prozess forgesetzt +#define SIGCONT 66 + +/// Terminal-Größe verändert +#define SIGWINCH 67 + +/// Child-Prozess beendet +#define SIGCHLD 71 + +/// Keine Notifikation geben, wenn Child-Prozess gestoppt wird (POSIX?) +#define SA_NOCLDSTOP 73 /// Nur fuer interne Verwendung. Muss immer 1 groesser sein als die groesste /// Signalnummer und teilbar durch 8 -#define _SIGNO_MAX 64 +#define _SIGNO_MAX 72 -- 1.6.0.4 From alexanderkluth at gmx.de Wed Aug 12 08:45:15 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Wed, 12 Aug 2009 08:45:15 +0200 Subject: [tyndur-devel] [PATCH] pwd.h & sys/socket.h In-Reply-To: <1> References: <1> Message-ID: <1250059515-15371-1-git-send-email-alexanderkluth@gmx.de> Paar Sachen hinzugefügt + pwd.h: char* pw_gecos in struct passwd + sys/socket.h: PF_INET und IPPROTO_IP Signed-off-by: Alexander Hartmut Kluth --- src/modules/include/pwd.h | 2 ++ src/modules/include/sys/socket.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/modules/include/pwd.h b/src/modules/include/pwd.h index b6e441b..a2aea98 100644 --- a/src/modules/include/pwd.h +++ b/src/modules/include/pwd.h @@ -43,6 +43,8 @@ struct passwd { char* pw_dir; /** Login-Shell */ char* pw_shell; + + char* pw_gecos; }; diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index a8446f6..263d181 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -34,6 +34,8 @@ typedef int socklen_t; typedef unsigned int sa_family_t; +const int IPPROTO_IP = 0; + /** * Beschreibt die Adresse einer Gegenstelle fuer einen Socket. * @@ -61,7 +63,7 @@ enum { /// Adressfamilien enum { /// IPv4 - AF_INET, + AF_INET, PF_INET }; /// Protokolle fuer IP -- 1.6.0.4 From toni at tyndur.org Wed Aug 12 09:44:56 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Wed, 12 Aug 2009 09:44:56 +0200 Subject: [tyndur-devel] [PATCH] libc: gmtime() und localtime() In-Reply-To: <4A81FAAC.3020609@gmx.net> Message-ID: <20090812074456.GA1631@thales.kaufmann.lan> Wie ich gerade feststellen musste, hatte das mit dem Postfix gestern noch nicht so recht geklappt, was dazu führte, dass mailman die Mails nicht an die Adressen ausserhalb meines Servers zustellen konnte. Deshalb sende ich diese Nachricht nochmal. ----- Forwarded message from Andreas Freimuth ----- Date: Wed, 12 Aug 2009 01:11:40 +0200 From: Andreas Freimuth To: tyndur-Patches Subject: Re: [tyndur-devel] [PATCH] libc: gmtime() und localtime() Ich habe es tatsächlich geschaft noch einen neuen Fehler einzubauen. -- Andreas Freimuth + libc: gmtime() und localtime() localtime geht noch fest von UTC+1 aus Signed-off-by: Andreas Freimuth diff --git a/src/modules/include/time.h b/src/modules/include/time.h --- a/src/modules/include/time.h +++ b/src/modules/include/time.h @@ -46,6 +46,13 @@ time_t time(time_t* t); +/// Timestamp in tm-Struct einfuellen +struct tm* gmtime(const time_t* time_ptr); +struct tm* gmtime_r(const time_t* time_ptr, struct tm* result); + +struct tm* localtime(const time_t* time_ptr); +struct tm* localtime_r(const time_t* time_ptr, struct tm* result); + #ifndef CONFIG_LIBC_NO_STUBS /// Datum und Uhrzeit in einen String umwandeln char* ctime(const time_t* time_ptr); @@ -53,11 +60,6 @@ /// Zeit und Datum als String char* asctime(const struct tm* time_ptr); -/// Timestamp in tm-Struct einfuellen -struct tm* gmtime(const time_t* time_ptr); - -struct tm* localtime(const time_t* time_ptr); - time_t mktime(struct tm* time_ptr); #endif diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c --- a/src/modules/lib/stdlibc/time.c +++ b/src/modules/lib/stdlibc/time.c @@ -30,18 +30,9 @@ #include #include +static struct tm tm; + #ifndef CONFIG_LIBC_NO_STUBS -static struct tm tm = { - .tm_wday = 3, - .tm_mday = 42, - .tm_mon = 6, - .tm_year = 1337, - .tm_yday = 1337, - - .tm_hour = 13, - .tm_min = 37, - .tm_sec = 42 -}; static char* asctime_buf = "Wed Jun 42 13:37:42 1337\n"; static char* ctime_string = "Wed Jun 42 13:37:42 1337\n"; #endif @@ -54,14 +45,14 @@ time_t time(time_t* t) { time_t result = 0; - + FILE* time_file = fopen("cmos:/unix_time", "r"); if (time_file == NULL) { printf("time():Konnte 'cmos:/unix_time' nicht oeffnen. Ist das "); printf("cmos-Modul geladen?\n"); return 0; } - + fread(&result, sizeof(time_t), 1, time_file); fclose(time_file); @@ -71,33 +62,117 @@ return result; } -#ifndef CONFIG_LIBC_NO_STUBS /** - * TODO - **/ -struct tm* localtime(const time_t* time) + * Timestamp, unter Bachtung der Zeitzone, in tm-Struktur einfuellen + * + * @param timer_ptr Pointer auf den Timestamp + * @param result Pointer auf die tm-Struktur, die gefuellt werden soll. + * + * @return result + */ +struct tm* localtime_r(const time_t* time_ptr, struct tm* result) { - // TODO - return &tm; + /* FIXME hier wird fest von UTC+1 ausgegangen */ + time_t ltime = *time_ptr + 60*60; + return gmtime_r(<ime, result); +} + +/** + * Timestamp, unter Bachtung der Zeitzone, in tm-Struktur einfuellen + * + * @param timer_ptr Pointer auf den Timestamp + * + * @return Pointer auf die interne statisch allozierte tm-Struktur. Diese kann + * bei jedem Aufruf einer Zeitfunktion ueberschrieben werden! + */ +struct tm* localtime(const time_t* time_ptr) +{ + return localtime_r(time_ptr, &tm); } /** * Timestamp in tm-Struktur einfuellen * - * @param time_ptr Pointer auf den Timestamp + * @param timer_ptr Pointer auf den Timestamp + * @param result Pointer auf die tm-Struktur, die gefuellt werden soll. + * + * @return result + */ +struct tm* gmtime_r(const time_t* timer_ptr, struct tm* result) +{ + static const int monat[2][12] = { + { 0,31,59,90,120,151,181,212,243,273,304,334}, + { 0,31,60,91,121,152,182,213,244,274,305,335} + }; + + time_t time = *timer_ptr; + int schaltjahr = 0; + + /* die Uhrzeit ist noch einfach */ + result->tm_sec = time % 60; + time /= 60; + result->tm_min = time % 60; + time /= 60; + result->tm_hour = time % 24; + time /= 24; + + /* 01.01.70 wahr ein Donnerstag (4) */ + result->tm_wday = (time + 4) % 7; + + /* jetzt kommen die Schaltjahre ins Spiel */ + + /* rebase auf 1969-01-01 00:00:00 UTC + * dann ist jedes 4. Jahr ein Schaltjahr + */ + time += 365; + + int tmp_years = 69 + 4 * (time / (4*365 + 1)); + time %= 4*365 + 1; + + if( (time / 365) > 2 ) { + schaltjahr = 1; + result->tm_year = tmp_years + 3; + result->tm_yday = time - 3*365; + } else { + result->tm_year = tmp_years + (time / 365); + result->tm_yday = time % 365; + } + + /* den richtigen monat raussuchen */ + if( monat[schaltjahr][result->tm_yday / 30] > result->tm_yday ) { + result->tm_mon = (result->tm_yday / 30) - 1; + } else if( monat[schaltjahr][result->tm_yday / 30 + 1] > result->tm_yday ) { + result->tm_mon = (result->tm_yday / 30); + } else { + result->tm_mon = (result->tm_yday / 30) + 1; + } + + result->tm_mday = 1 + (result->tm_yday - monat[schaltjahr][result->tm_mon]); + + result->tm_isdst = -1; + + return result; +} + +/** + * Timestamp in tm-Struktur einfuellen + * + * @param timer_ptr Pointer auf den Timestamp * * @return Pointer auf die interne statisch allozierte tm-Struktur. Diese kann * bei jedem Aufruf einer Zeitfunktion ueberschrieben werden! */ -struct tm* gmtime(const time_t* time_ptr) +struct tm* gmtime(const time_t* timer_ptr) { - // TODO - return &tm; + return gmtime_r(timer_ptr, &tm); } + +#ifndef CONFIG_LIBC_NO_STUBS + /** * TODO - **/ + */ char* asctime(const struct tm* time) { // TODO ----- End forwarded message ----- -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Wed Aug 12 09:55:13 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Wed, 12 Aug 2009 09:55:13 +0200 Subject: [tyndur-devel] [PATCH] strftime() Message-ID: <20090812075513.GB1631@thales.kaufmann.lan> Auch noch eine Mail, die steckengeblieben ist. ----- Forwarded message from alexanderkluth at gmx.de ----- Date: Wed, 12 Aug 2009 05:23:04 +0200 From: alexanderkluth at gmx.de To: tyndur-devel at tyndur.org Subject: [tyndur-devel] [PATCH] strftime() From: Alexander Hartmut Kluth + strftime() hinzugefügt + enum's und nen const-Array hinzugefügt, die das Leben leichter machen Signed-off-by: Alexander Hartmut Kluth --- src/modules/include/time.h | 2 + src/modules/lib/stdlibc/time.c | 233 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+), 0 deletions(-) diff --git a/src/modules/include/time.h b/src/modules/include/time.h index 4ee4b2e..b6c928e 100644 --- a/src/modules/include/time.h +++ b/src/modules/include/time.h @@ -46,6 +46,8 @@ struct tm { time_t time(time_t* t); +size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm); + #ifndef CONFIG_LIBC_NO_STUBS /// Datum und Uhrzeit in einen String umwandeln char* ctime(const time_t* time_ptr); diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c index 76e82d0..70b4902 100644 --- a/src/modules/lib/stdlibc/time.c +++ b/src/modules/lib/stdlibc/time.c @@ -46,6 +46,27 @@ static char* asctime_buf = "Wed Jun 42 13:37:42 1337\n"; static char* ctime_string = "Wed Jun 42 13:37:42 1337\n"; #endif +enum { + aJan, aFeb, aMar, aApr, aMay, aJun, aJul, aAug, aSep, aOct, aNov, aDec, + Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, + aSun, aMon, aTue, aWed, aThu, aFri, aSat, + Sun, Mon, Tue, Wed, Thu, Fri, Sat, + Local_time, Local_date, DFL_FMT, + AM, PM, DATE_FMT, + LAST +}; + +static const char * __time[] = { + "Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec", + "January", "February", "March","April", + "May","June", "July", "August", "September", + "October", "November", "December", + "Sun","Mon", "Tue", "Wed","Thu", "Fri","Sat", + "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday", + "%H:%M:%S","%m/%d/%y", "%a %b %d %H:%M:%S %Y", + "AM", "PM", "%a %b %e %T %Z %Y", NULL +}; + /** * Unix-Timestamp aus der aktuellen Zeit generieren. * @@ -128,3 +149,215 @@ time_t mktime(struct tm* time_ptr) #endif +/** + * Erzeugt einen String anhand eines Datumsformats aus einer bestimmten + * Anzahl Zeichen. + * + * TODO: %z für Zeitzone, %c und %C für lokalisierte Datums- und Zeitformat, + * %x und %X für lokalisiertes Datums-, bzw. Zeitformat + * + * @param str Pointer auf einen String + * @param maxs Maximal zu erzeugende Anzahl an Zeichen + * @param datestr Pointer auf den Datumsformatstring + * @param tm Struktur auf aktuelle Datums- und Zeitangaben + * + * @return 0 bei Misserfolg, ansonsten Anzahl erzeugter Zeichen + **/ +size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm) +{ + char i, c; + size_t size = 0, n; + char *nstr; + char dflcase[] = "%?"; + + // TODO: Aktuelle Zeit ermitteln + if (datestr == NULL) { + nstr = ""; + } + + // Datumsformatstring parsen + while ((c = *datestr++) != '\0') { + if (c != '%') { + if (++size >= maxs) { + return 0; + } + + *str++ = c; + continue; + } + + switch (*datestr++) { + case '%': + nstr = "%"; + break; + + case 'a': // Abgekürzter Wochentagsname + nstr = (char *)__time[aSun + tm->tm_wday]; + break; + + case 'A': // Wochentagsname + nstr = (char *)__time[Sun + tm->tm_wday]; + break; + + case 'b': // Abgekürzter Montatsname + case 'h': + nstr = (char *)__time[aJan + tm->tm_mon]; + break; + + + case 'B': // Monatsname + nstr = (char *)__time[Jan + tm->tm_mon]; + + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'd': // Tagesnummer + //p = itoa(tm->tm_mday, nstr, 2); + break; + + case 'D': + nstr = "%m/%d/%y"; + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'e': + itoa(tm->tm_mday, nstr, 2); + if (tm->tm_mday < 10) { + nstr[0] = ' '; + } + + break; + + case 'H': // 24-Stunden + itoa(tm->tm_hour, nstr, 2); + break; + + case 'I': // 12-Stunden + if ((i = tm->tm_hour % 12) == 0) + i = 12; + itoa(i, nstr, 2); + break; + + case 'j': // Julianisches Datum + itoa(tm->tm_yday + 1, nstr, 3); + break; + + case 'm': // Monats-Nummer + itoa(tm->tm_mon + 1, nstr, 2); + break; + + case 'M': // Minute + itoa(tm->tm_min, nstr, 2); + break; + + case 'n': // Newline + nstr = "\n"; + break; + + case 'p': // AM oder PM + if (tm->tm_hour >= 12) + nstr = (char *)__time[PM]; + else + nstr = (char *)__time[AM]; + break; + + case 'r': + if (tm->tm_hour >= 12) + nstr = "%I:%M:%S PM"; + else + nstr = "%I:%M:%S AM"; + + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'R': + nstr = "%H:%M"; + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'S': // Sekunden + //p = itoa(tm->tm_sec, nstr, 2); + break; + + case 't': // Tabulator + nstr = "\t"; + break; + + case 'T': + nstr = "%H:%M:%S"; + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { + return 0; + } + + str += n; + size += n; + break; + + case 'U': // Tagesnummer des Jahres, bei Sonntag als 1. Tag + itoa((tm->tm_yday - tm->tm_wday + 7)/7, nstr, 2); + break; + + case 'w': // Wochentagsnummer + itoa(tm->tm_wday, nstr, 1); + break; + + case 'W': // Tagesnummer des Jahres, bei Montag als 1. Tag + if ((i = 8 - tm->tm_wday) == 8) { + i = 1; + } + itoa((tm->tm_yday + i)/7, nstr, 2); + break; + + + case 'y': // Jahr in Form von "xx" + itoa(tm->tm_year, nstr, 2); + break; + + case 'Y': // Jahr in Form von "xxxx" + itoa(1900 + tm->tm_year, nstr, 4); + break; + + default: + dflcase[1] = *(datestr - 1); + nstr = (char *)dflcase; + break; + + continue; + } + + n = strlen(nstr); + + if ((size += n) >= maxs) { + return 0; + } + + strcpy(str, nstr); + str += n; + } + + *str = '\0'; + return size; +} + + + -- 1.6.0.4 ----- End forwarded message ----- -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From alexanderkluth at gmx.de Wed Aug 12 12:23:26 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Wed, 12 Aug 2009 12:23:26 +0200 Subject: [tyndur-devel] [PATCH] strftime() In-Reply-To: <2> References: <2> Message-ID: <1250072606-31332-1-git-send-email-alexanderkluth@gmx.de> * Monats- und Tagesnamen eingedeutscht Signed-off-by: Alexander Hartmut Kluth --- src/modules/lib/stdlibc/time.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c index 70b4902..ca1d8f8 100644 --- a/src/modules/lib/stdlibc/time.c +++ b/src/modules/lib/stdlibc/time.c @@ -56,13 +56,13 @@ enum { LAST }; -static const char * __time[] = { - "Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec", - "January", "February", "March","April", - "May","June", "July", "August", "September", - "October", "November", "December", - "Sun","Mon", "Tue", "Wed","Thu", "Fri","Sat", - "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday", +static const char *__time[] = { + "Jan","Feb","Mär","Apr","Mai","Jun","Jul", "Aug", "Sep","Okt", "Nov", "Dez", + "Januar", "Februar", "März","April", + "Mai","Juni", "Juli", "August", "September", + "Oktober", "November", "Dezember", + "So","Mo", "Di", "Mi","Do", "Fr","Sa", + "Sonntag","Montag","Dienstag","Mittwoch", "Donnerstag","Freitag","Samstag", "%H:%M:%S","%m/%d/%y", "%a %b %d %H:%M:%S %Y", "AM", "PM", "%a %b %e %T %Z %Y", NULL }; -- 1.6.0.4 From m.nemo at gmx.net Wed Aug 12 14:05:58 2009 From: m.nemo at gmx.net (Andreas Freimuth) Date: Wed, 12 Aug 2009 14:05:58 +0200 Subject: [tyndur-devel] [PATCH] strftime() In-Reply-To: <20090812075513.GB1631@thales.kaufmann.lan> References: <20090812075513.GB1631@thales.kaufmann.lan> Message-ID: <4A82B026.2010008@gmx.net> Du verwendst glaub ich irgendwie itoa falsch. Laut Standard ist das: char* itoa(value,dest,base); du übergibst ihm Wilde dest-pointer und als Base, die Anzahl der Zeichen die er daraus machen soll. Außerdem hast du manchmal drin und whitespace am zeilenende (besonders in leerzeilen). Das mochte der taljeth bei meinem patch gar nicht. Ansonsten hab ich hoffentlich alles wichtige Kommentiert: > ----- Forwarded message from alexanderkluth at gmx.de ----- > > Date: Wed, 12 Aug 2009 05:23:04 +0200 > From: alexanderkluth at gmx.de > To: tyndur-devel at tyndur.org > Subject: [tyndur-devel] [PATCH] strftime() > > From: Alexander Hartmut Kluth > > + strftime() hinzugefügt > + enum's und nen const-Array hinzugefügt, die das Leben leichter machen > > Signed-off-by: Alexander Hartmut Kluth > --- > src/modules/include/time.h | 2 + > src/modules/lib/stdlibc/time.c | 233 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 235 insertions(+), 0 deletions(-) > > diff --git a/src/modules/include/time.h b/src/modules/include/time.h > index 4ee4b2e..b6c928e 100644 > --- a/src/modules/include/time.h > +++ b/src/modules/include/time.h > @@ -46,6 +46,8 @@ struct tm { > > time_t time(time_t* t); > > +size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm); > + > #ifndef CONFIG_LIBC_NO_STUBS > /// Datum und Uhrzeit in einen String umwandeln > char* ctime(const time_t* time_ptr); > diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c > index 76e82d0..70b4902 100644 > --- a/src/modules/lib/stdlibc/time.c > +++ b/src/modules/lib/stdlibc/time.c > @@ -46,6 +46,27 @@ static char* asctime_buf = "Wed Jun 42 13:37:42 1337\n"; > static char* ctime_string = "Wed Jun 42 13:37:42 1337\n"; > #endif > > +enum { > + aJan, aFeb, aMar, aApr, aMay, aJun, aJul, aAug, aSep, aOct, aNov, aDec, > + Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, > + aSun, aMon, aTue, aWed, aThu, aFri, aSat, > + Sun, Mon, Tue, Wed, Thu, Fri, Sat, > + Local_time, Local_date, DFL_FMT, > + AM, PM, DATE_FMT, > + LAST > +}; > + > +static const char * __time[] = { > + "Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec", > + "January", "February", "March","April", > + "May","June", "July", "August", "September", > + "October", "November", "December", > + "Sun","Mon", "Tue", "Wed","Thu", "Fri","Sat", > + "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday", > + "%H:%M:%S","%m/%d/%y", "%a %b %d %H:%M:%S %Y", > + "AM", "PM", "%a %b %e %T %Z %Y", NULL > +}; > + > /** > * Unix-Timestamp aus der aktuellen Zeit generieren. > * > @@ -128,3 +149,215 @@ time_t mktime(struct tm* time_ptr) > > #endif > > +/** > + * Erzeugt einen String anhand eines Datumsformats aus einer bestimmten > + * Anzahl Zeichen. > + * > + * TODO: %z für Zeitzone, %c und %C für lokalisierte Datums- und Zeitformat, > + * %x und %X für lokalisiertes Datums-, bzw. Zeitformat > + * > + * @param str Pointer auf einen String > + * @param maxs Maximal zu erzeugende Anzahl an Zeichen > + * @param datestr Pointer auf den Datumsformatstring > + * @param tm Struktur auf aktuelle Datums- und Zeitangaben > + * > + * @return 0 bei Misserfolg, ansonsten Anzahl erzeugter Zeichen > + **/ > +size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm) > +{ > + char i, c; > + size_t size = 0, n; > + char *nstr; > + char dflcase[] = "%?"; > + > + // TODO: Aktuelle Zeit ermitteln > + if (datestr == NULL) { > + nstr = ""; Und sonst passiert hier nichts? Da gibts doch gleich vier zeilen tiefer nen Pagefault, oder nicht? > + } > + > + // Datumsformatstring parsen > + while ((c = *datestr++) != '\0') { > + if (c != '%') { > + if (++size >= maxs) { > + return 0; > + } > + > + *str++ = c; > + continue; > + } > + > + switch (*datestr++) { > + case '%': > + nstr = "%"; > + break; > + > + case 'a': // Abgekürzter Wochentagsname > + nstr = (char *)__time[aSun + tm->tm_wday]; > + break; > + > + case 'A': // Wochentagsname > + nstr = (char *)__time[Sun + tm->tm_wday]; > + break; > + > + case 'b': // Abgekürzter Montatsname > + case 'h': Whitespace ^^ > + nstr = (char *)__time[aJan + tm->tm_mon]; > + break; > + > + > + case 'B': // Monatsname > + nstr = (char *)__time[Jan + tm->tm_mon]; > + > + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { > + return 0; > + } Warum noch mal mit strftime ausgeben, bevor das von strcpy erledigt wird? > + > + str += n; > + size += n; > + break; > + > + case 'd': // Tagesnummer > + //p = itoa(tm->tm_mday, nstr, 2); Warum nicht? > + break; > + > + case 'D': > + nstr = "%m/%d/%y"; > + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { > + return 0; > + } > + > + str += n; > + size += n; > + break; > + > + case 'e': > + itoa(tm->tm_mday, nstr, 2); > + if (tm->tm_mday < 10) { > + nstr[0] = ' '; > + } > + > + break; > + > + case 'H': // 24-Stunden > + itoa(tm->tm_hour, nstr, 2); > + break; > + > + case 'I': // 12-Stunden > + if ((i = tm->tm_hour % 12) == 0) > + i = 12; > + itoa(i, nstr, 2); > + break; > + > + case 'j': // Julianisches Datum > + itoa(tm->tm_yday + 1, nstr, 3); > + break; white space > + > + case 'm': // Monats-Nummer > + itoa(tm->tm_mon + 1, nstr, 2); > + break; > + > + case 'M': // Minute > + itoa(tm->tm_min, nstr, 2); > + break; > + > + case 'n': // Newline > + nstr = "\n"; > + break; > + > + case 'p': // AM oder PM > + if (tm->tm_hour >= 12) > + nstr = (char *)__time[PM]; > + else > + nstr = (char *)__time[AM]; > + break; > + > + case 'r': > + if (tm->tm_hour >= 12) > + nstr = "%I:%M:%S PM"; > + else > + nstr = "%I:%M:%S AM"; > + > + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { > + return 0; > + } Jetzt ist nstr nicht "" und wird unten mit strcpy ausgegeben, oder nicht? > + > + str += n; > + size += n; > + break; > + > + case 'R': > + nstr = "%H:%M"; > + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { > + return 0; > + } Hier wieder > + > + str += n; > + size += n; > + break; > + > + case 'S': // Sekunden > + //p = itoa(tm->tm_sec, nstr, 2); Und warum, das auch nicht? > + break; > + > + case 't': // Tabulator > + nstr = "\t"; > + break; > + > + case 'T': > + nstr = "%H:%M:%S"; > + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { > + return 0; > + } > + > + str += n; > + size += n; > + break; > + > + case 'U': // Tagesnummer des Jahres, bei Sonntag als 1. Tag > + itoa((tm->tm_yday - tm->tm_wday + 7)/7, nstr, 2); > + break; > + > + case 'w': // Wochentagsnummer > + itoa(tm->tm_wday, nstr, 1); > + break; > + > + case 'W': // Tagesnummer des Jahres, bei Montag als 1. Tag > + if ((i = 8 - tm->tm_wday) == 8) { > + i = 1; > + } > + itoa((tm->tm_yday + i)/7, nstr, 2); > + break; > + > + > + case 'y': // Jahr in Form von "xx" > + itoa(tm->tm_year, nstr, 2); > + break; > + > + case 'Y': // Jahr in Form von "xxxx" > + itoa(1900 + tm->tm_year, nstr, 4); > + break; > + > + default: > + dflcase[1] = *(datestr - 1); > + nstr = (char *)dflcase; > + break; > + > + continue; Das continue ist hier irgendwie fehl am Platz(so mit dem break direkt davor) > + } > + > + n = strlen(nstr); > + > + if ((size += n) >= maxs) { > + return 0; > + } > + > + strcpy(str, nstr); > + str += n; > + } > + > + *str = '\0'; > + return size; > +} > + > + > + -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 899 bytes Beschreibung: OpenPGP digital signature URL : From kevin at tyndur.org Wed Aug 12 21:27:09 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 12 Aug 2009 21:27:09 +0200 Subject: [tyndur-devel] [PATCH] signal.h In-Reply-To: <1250058842-24300-1-git-send-email-alexanderkluth@gmx.de> References: <1> <1250058842-24300-1-git-send-email-alexanderkluth@gmx.de> Message-ID: <20090812191309.GA10057@silvanus> On Wed, Aug 12, 2009 at 08:34:02AM +0200, Alexander Hartmut Kluth wrote: > + Neue Signale hinzugefügt > > Signed-off-by: Alexander Hartmut Kluth > --- > src/modules/include/signal.h | 20 ++++++++++++++++++-- > 1 files changed, 18 insertions(+), 2 deletions(-) > > diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h > index d10bc2e..28eae8c 100644 > --- a/src/modules/include/signal.h > +++ b/src/modules/include/signal.h > @@ -87,11 +87,27 @@ typedef uint32_t sig_atomic_t; > /// Ende des frei verwendbaren Bereichs > #define SIGRTMAX 63 > > -// Hier sollte noch viel mehr kommen > +/// Prozess stoppen > +#define SIGTSTP 64 > + > +/// Prozess gestoppt > +#define SIGSTOP 65 > + > +/// Prozess forgesetzt > +#define SIGCONT 66 > + > +/// Terminal-Größe verändert > +#define SIGWINCH 67 > + > +/// Child-Prozess beendet > +#define SIGCHLD 71 > + > +/// Keine Notifikation geben, wenn Child-Prozess gestoppt wird (POSIX?) > +#define SA_NOCLDSTOP 73 Könnte man nicht erstmal die Signale zu Ende bringen und dann SA_* einbauen? Ich würde mir das als vollständige (siehe man sigaction) Definition von allen SA_* bei den sigaction-Definitionen wünschen, also z.B. direkt nach dem enum, der SIG_BLOCK definiert. Gibt es einen Grund, dass du 68 bis 70 auslässt? > > /// Nur fuer interne Verwendung. Muss immer 1 groesser sein als die groesste > /// Signalnummer und teilbar durch 8 > -#define _SIGNO_MAX 64 > +#define _SIGNO_MAX 72 > > > > -- > 1.6.0.4 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From kevin at tyndur.org Wed Aug 12 21:35:08 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 12 Aug 2009 21:35:08 +0200 Subject: [tyndur-devel] [PATCH] pwd.h & sys/socket.h In-Reply-To: <1250059515-15371-1-git-send-email-alexanderkluth@gmx.de> References: <1> <1250059515-15371-1-git-send-email-alexanderkluth@gmx.de> Message-ID: <20090812193507.GB10057@silvanus> On Wed, Aug 12, 2009 at 08:45:15AM +0200, Alexander Hartmut Kluth wrote: > Paar Sachen hinzugefügt > > + pwd.h: char* pw_gecos in struct passwd > + sys/socket.h: PF_INET und IPPROTO_IP Zwei Themengebiete => zwei Patches Ich kann ihn dieses Mal auch so nehmen, aber für die Zukunft bitte beachten. > > Signed-off-by: Alexander Hartmut Kluth > --- > src/modules/include/pwd.h | 2 ++ > src/modules/include/sys/socket.h | 4 +++- > 2 files changed, 5 insertions(+), 1 deletions(-) > > diff --git a/src/modules/include/pwd.h b/src/modules/include/pwd.h > index b6e441b..a2aea98 100644 > --- a/src/modules/include/pwd.h > +++ b/src/modules/include/pwd.h > @@ -43,6 +43,8 @@ struct passwd { > char* pw_dir; > /** Login-Shell */ > char* pw_shell; > + > + char* pw_gecos; Da fehlt ein /** Echter Name des Benutzer */ > }; > > > diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h > index a8446f6..263d181 100644 > --- a/src/modules/include/sys/socket.h > +++ b/src/modules/include/sys/socket.h > @@ -34,6 +34,8 @@ > typedef int socklen_t; > typedef unsigned int sa_family_t; > > +const int IPPROTO_IP = 0; > + > /** > * Beschreibt die Adresse einer Gegenstelle fuer einen Socket. > * > @@ -61,7 +63,7 @@ enum { > /// Adressfamilien > enum { > /// IPv4 > - AF_INET, > + AF_INET, PF_INET > }; Ich glaube, das wäre besser ein #define PF_INET AF_INET. From kevin at tyndur.org Wed Aug 12 21:54:30 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 12 Aug 2009 21:54:30 +0200 Subject: [tyndur-devel] [PATCH] strftime() In-Reply-To: <4A82B026.2010008@gmx.net> References: <20090812075513.GB1631@thales.kaufmann.lan> <4A82B026.2010008@gmx.net> Message-ID: <20090812195430.GC10057@silvanus> On Wed, Aug 12, 2009 at 02:05:58PM +0200, Andreas Freimuth wrote: > Du verwendst glaub ich irgendwie itoa falsch. > Laut Standard ist das: char* itoa(value,dest,base); > du übergibst ihm Wilde dest-pointer und als Base, die Anzahl der Zeichen > die er daraus machen soll. itoa ist broken by design, weil es keine Stringlänge nimmt. Die bessere Alternative ist snprintf. > > Außerdem hast du manchmal drin und whitespace am zeilenende > (besonders in leerzeilen). Das mochte der taljeth bei meinem patch gar > nicht. Genau. ;-) Falls einer von euch vim benutzt, schaut euch mal im Wiki die Seite http://lowlevel.brainsware.org/wiki/index.php/Benutzer:FreakyPenguin an, da gibt es eine schöne Konfigurationsdatei, mit der Whitespace-Fehler sofort mit roter Hintergrundfarbe markiert werden. From kevin at tyndur.org Wed Aug 12 22:58:28 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 12 Aug 2009 22:58:28 +0200 Subject: [tyndur-devel] [PATCH] libc: gmtime() und localtime() In-Reply-To: <4A81FAAC.3020609@gmx.net> References: <4A81C20C.7080109@gmx.net> <20090811193900.GC9759@silvanus> <4A81D27D.6000906@gmx.net> <4A81FAAC.3020609@gmx.net> Message-ID: <20090812205828.GD10057@silvanus> On Wed, Aug 12, 2009 at 01:11:40AM +0200, Andreas Freimuth wrote: > Ich habe es tatsächlich geschaft noch einen neuen Fehler einzubauen. > > -- > Andreas Freimuth > > + libc: gmtime() und localtime() > localtime geht noch fest von UTC+1 aus > > Signed-off-by: Andreas Freimuth Danke, ist drin. From alexanderkluth at gmx.de Thu Aug 13 20:46:30 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Thu, 13 Aug 2009 20:46:30 +0200 Subject: [tyndur-devel] [PATCH] socket.h Message-ID: <1250189190-15300-1-git-send-email-alexanderkluth@gmx.de> * #define PF_INET AF_INET * const int IPPROTO_IP war doch nicht so schlau, nun ist's ein define Signed-off-by: Alexander Hartmut Kluth --- src/modules/include/sys/socket.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index 263d181..5146348 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -34,7 +34,8 @@ typedef int socklen_t; typedef unsigned int sa_family_t; -const int IPPROTO_IP = 0; +#define IPPROTO_IP 0 +#define PF_INET AF_INET /** * Beschreibt die Adresse einer Gegenstelle fuer einen Socket. @@ -63,7 +64,7 @@ enum { /// Adressfamilien enum { /// IPv4 - AF_INET, PF_INET + AF_INET }; /// Protokolle fuer IP -- 1.6.0.4 From kevin at tyndur.org Thu Aug 13 20:56:15 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 13 Aug 2009 20:56:15 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: symlink() Message-ID: <1250189775-11736-1-git-send-email-kevin@tyndur.org> + libc: POSIX: symlink() Signed-off-by: Kevin Wolf --- src/modules/include/unistd.h | 10 ++++++++++ src/modules/lib/posix/link.c | 13 +++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index 24b06b9..cc62037 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -141,6 +141,16 @@ unsigned int sleep(unsigned int seconds); /// Datei umbenennen oder verschieben int rename(const char* path_old, const char* path_new); +/** + * Einen symbolischen Link anlegen + * + * @param oldpath Ziel des Links + * @param newpath Hier wird der Link erstellt + * + * @return 0 bei Erfolg; im Fehlerfall -1 und errno wird gesetzt + */ +int symlink(const char* oldpath, const char* newpath); + /// Gibt die aktuelle Benutzer-ID zurueck uid_t getuid(void); diff --git a/src/modules/lib/posix/link.c b/src/modules/lib/posix/link.c index 76b30e7..d11439a 100644 --- a/src/modules/lib/posix/link.c +++ b/src/modules/lib/posix/link.c @@ -29,6 +29,7 @@ #include #include #include +#include /** * Einen Hardlink erstellen. @@ -45,6 +46,18 @@ int link(const char* oldpath, const char* newpath) return -1; } +/** + * Einen symbolischen Link anlegen + * + * @param oldpath Ziel des Links + * @param newpath Hier wird der Link erstellt + * + * @return 0 bei Erfolg; im Fehlerfall -1 und errno wird gesetzt + */ +int symlink(const char* oldpath, const char* newpath) +{ + return io_create_link(oldpath, newpath, 0); +} /** * Liest den Zielpfad eines symbolischen Links aus. -- 1.6.0.2 From kevin at tyndur.org Thu Aug 13 21:19:56 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 13 Aug 2009 21:19:56 +0200 Subject: [tyndur-devel] [PATCH] socket.h In-Reply-To: <1250189190-15300-1-git-send-email-alexanderkluth@gmx.de> References: <1250189190-15300-1-git-send-email-alexanderkluth@gmx.de> Message-ID: <20090813191946.GA11814@silvanus> On Thu, Aug 13, 2009 at 08:46:30PM +0200, Alexander Hartmut Kluth wrote: > * #define PF_INET AF_INET > * const int IPPROTO_IP war doch nicht so schlau, nun ist's ein define > > Signed-off-by: Alexander Hartmut Kluth Danke, ich hab das jetzt irgendwie reingewurschtelt. Aber ich wäre dir dankbar, wenn du nicht immer neue Korrekturpatches draufpacken würdest, wenn an einem noch nicht eingecheckten Patch was verbessert werden muss, sondern wenn du den ganzen Patch nochmal neu schickst. Mit git commit --amend und git rebase -i sollte das kein Problem sein. Letztendlich hat mich das Zusammenpicken der Mails, das Mergen der Patches und die Korrektur des Ergebnisses wahrscheinlich mehr Zeit gekostet als wenn ich den Patch selber geschrieben hätte. From alexanderkluth at gmx.de Thu Aug 13 21:37:40 2009 From: alexanderkluth at gmx.de (Alexander Kluth) Date: Thu, 13 Aug 2009 21:37:40 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: symlink() In-Reply-To: <1250189775-11736-1-git-send-email-kevin@tyndur.org> References: <1250189775-11736-1-git-send-email-kevin@tyndur.org> Message-ID: <1250192260.28568.1.camel@akluth-workstation> Am Donnerstag, den 13.08.2009, 20:56 +0200 schrieb Kevin Wolf: > + libc: POSIX: symlink() > > Signed-off-by: Kevin Wolf Acked-by: Alexander Kluth From alexanderkluth at gmx.de Thu Aug 13 22:56:35 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Thu, 13 Aug 2009 22:56:35 +0200 Subject: [tyndur-devel] [PATCH] strftime() Message-ID: <1250196995-20706-1-git-send-email-alexanderkluth@gmx.de> * itoa durch snprintf ersetzt * Dank vim nun alles tyndur-Konform Signed-off-by: Alexander Hartmut Kluth --- src/modules/lib/stdlibc/time.c | 119 ++++++++++++++++++++-------------------- 1 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c index ca1d8f8..43a7a06 100644 --- a/src/modules/lib/stdlibc/time.c +++ b/src/modules/lib/stdlibc/time.c @@ -75,14 +75,14 @@ static const char *__time[] = { time_t time(time_t* t) { time_t result = 0; - + FILE* time_file = fopen("cmos:/unix_time", "r"); if (time_file == NULL) { printf("time():Konnte 'cmos:/unix_time' nicht oeffnen. Ist das "); printf("cmos-Modul geladen?\n"); return 0; } - + fread(&result, sizeof(time_t), 1, time_file); fclose(time_file); @@ -163,7 +163,8 @@ time_t mktime(struct tm* time_ptr) * * @return 0 bei Misserfolg, ansonsten Anzahl erzeugter Zeichen **/ -size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm) +size_t strftime(char *str, size_t maxs, const char *datestr, +const struct tm *tm) { char i, c; size_t size = 0, n; @@ -181,160 +182,160 @@ size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm if (++size >= maxs) { return 0; } - + *str++ = c; continue; } switch (*datestr++) { - case '%': + case '%': nstr = "%"; break; - + case 'a': // Abgekürzter Wochentagsname nstr = (char *)__time[aSun + tm->tm_wday]; break; - + case 'A': // Wochentagsname nstr = (char *)__time[Sun + tm->tm_wday]; break; - + case 'b': // Abgekürzter Montatsname case 'h': nstr = (char *)__time[aJan + tm->tm_mon]; break; - - + + case 'B': // Monatsname nstr = (char *)__time[Jan + tm->tm_mon]; - + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { return 0; } - + str += n; size += n; break; - + case 'd': // Tagesnummer - //p = itoa(tm->tm_mday, nstr, 2); + snprintf(nstr, 2, "%i", tm->tm_mday); break; - + case 'D': nstr = "%m/%d/%y"; if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { return 0; } - + str += n; size += n; break; - + case 'e': - itoa(tm->tm_mday, nstr, 2); + snprintf(nstr, 2, "%i", tm->tm_mday); if (tm->tm_mday < 10) { nstr[0] = ' '; } break; - + case 'H': // 24-Stunden - itoa(tm->tm_hour, nstr, 2); - break; - + snprintf(nstr, 2, "%i", tm->tm_hour); + break; + case 'I': // 12-Stunden if ((i = tm->tm_hour % 12) == 0) i = 12; - itoa(i, nstr, 2); + snprintf(nstr, 2, "%i", i); break; - + case 'j': // Julianisches Datum - itoa(tm->tm_yday + 1, nstr, 3); - break; - + snprintf(nstr, 3, "%i", tm->tm_yday + 1); + break; + case 'm': // Monats-Nummer - itoa(tm->tm_mon + 1, nstr, 2); + snprintf(nstr, 2, "%i", tm->tm_mmon + 2); break; - + case 'M': // Minute - itoa(tm->tm_min, nstr, 2); + snprintf(nstr, 2, "%i", tm->tm_min); break; - - case 'n': // Newline + + case 'n': // Newline nstr = "\n"; break; - - case 'p': // AM oder PM + + case 'p': // AM oder PM if (tm->tm_hour >= 12) nstr = (char *)__time[PM]; else nstr = (char *)__time[AM]; break; - + case 'r': if (tm->tm_hour >= 12) nstr = "%I:%M:%S PM"; else nstr = "%I:%M:%S AM"; - + if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { return 0; } - + str += n; size += n; break; - + case 'R': nstr = "%H:%M"; if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { return 0; } - + str += n; size += n; break; - - case 'S': // Sekunden + + case 'S': // Sekunden //p = itoa(tm->tm_sec, nstr, 2); break; - + case 't': // Tabulator nstr = "\t"; break; - + case 'T': nstr = "%H:%M:%S"; if ((n = strftime(str, maxs-size, nstr, tm)) == 0) { return 0; } - + str += n; size += n; break; - + case 'U': // Tagesnummer des Jahres, bei Sonntag als 1. Tag - itoa((tm->tm_yday - tm->tm_wday + 7)/7, nstr, 2); + snprintf(nstr, 2, "%i", (tm->tm_yday - tm->tm_wday + 7)/7); break; - + case 'w': // Wochentagsnummer - itoa(tm->tm_wday, nstr, 1); + snprintf(nstr, 2, "%i", tm->tm_wday); break; - + case 'W': // Tagesnummer des Jahres, bei Montag als 1. Tag if ((i = 8 - tm->tm_wday) == 8) { i = 1; } - itoa((tm->tm_yday + i)/7, nstr, 2); + snprintf(nstr, 2, "%i", (tm->tm_yday + i)/7); break; - - + + case 'y': // Jahr in Form von "xx" - itoa(tm->tm_year, nstr, 2); + snprintf(nstr, 2, "%i", tm->tm_year); break; - + case 'Y': // Jahr in Form von "xxxx" - itoa(1900 + tm->tm_year, nstr, 4); + snprintf(nstr, 4, "%i", 1900 + tm->tm_year); break; default: @@ -344,17 +345,17 @@ size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm continue; } - + n = strlen(nstr); - + if ((size += n) >= maxs) { return 0; } - + strcpy(str, nstr); str += n; } - + *str = '\0'; return size; } -- 1.6.0.4 From kevin at tyndur.org Fri Aug 14 20:43:34 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 14 Aug 2009 20:43:34 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: Mehr arpa/inet.h Message-ID: <1250275414-25054-1-git-send-email-kevin@tyndur.org> + libc: POSIX: inet_ntop() und inet_pton() ! libc: POSIX: inet_ntoa() und inet_aton() gehoeren nach arpa/inet.h und nicht nach netinet/in.h. Da letzteres ersteres includet, besteht auch keine Gefahr, dass das Verschieben lbuilds ungluecklich macht. Signed-off-by: Kevin Wolf --- src/modules/include/arpa/inet.h | 44 +++++++++++++++++++++++++++ src/modules/include/netinet/in.h | 21 ++++--------- src/modules/lib/posix/net.c | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 14 deletions(-) diff --git a/src/modules/include/arpa/inet.h b/src/modules/include/arpa/inet.h index 23610a9..8224bf0 100644 --- a/src/modules/include/arpa/inet.h +++ b/src/modules/include/arpa/inet.h @@ -29,10 +29,54 @@ #ifndef _ARPA_INET_H_ #define _ARPA_INET_H_ +#include + unsigned long int htonl(unsigned long int hostlong); unsigned short int htons(unsigned short int hostshort); unsigned long int ntohl(unsigned long int netlong); unsigned short int ntohs(unsigned short int netshort); +/** + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen + * 32-Bit-Wert um. + * + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg + */ +int inet_aton(const char* ip_string, struct in_addr* ip); + +/** + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. + */ +char* inet_ntoa(struct in_addr ip); + +/** + * Wandelt einen String, der eine Adresse (IPv4 or IPv6) enthaelt in ihre + * binaere Darstellung um. + * + * @param family Adressfamilie, fuer die umgewandelt werden soll (z.B. AF_INET) + * @param src Adresse als String + * @param dst Ziel fuer die binaere Darstellung (z.B. struct in_addr*) + * + * @return 1 bei Erfolg, 0 wenn die Adresse ungueltig ist. Bei sonstigen + * Fehlern -1 und errno wird gesetzt. + */ +int inet_pton(int family, const char* src, void* dst); + +/** + * Wandelt eine Adresse (IPv4 oder IPv6) in einen String um. Der Ausgabepuffer + * wird vom Aufrufer uebergeben. + * + * @param family Adressfamilie, zu der src gehoert (z.B. AF_INET) + * @param src Adressstruktur, die umgewandelt werden soll (z.B. struct + * in_addr*) + * @param dst Ausgabepuffer + * @param size Laenge des Ausgabepuffers + * + * @return Pointer auf den Ausgabepuffer; im Fehlerfall NULL und errno wird + * gesetzt + */ +const char *inet_ntop(int family, const void* src, char* dst, socklen_t size); + #endif diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index a620b88..8e95fce 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -31,7 +31,9 @@ #include #include -#include + +/// Laenge einer IP-Adresse als String +#define INET_ADDRSTRLEN 16 typedef uint32_t in_addr_t; struct in_addr { @@ -45,19 +47,10 @@ struct sockaddr_in { uint32_t sin_port; }; -/** - * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen - * 32-Bit-Wert um. - * - * @return 0 im Fehlerfall; ungleich 0 bei Erfolg - */ -int inet_aton(const char* ip_string, struct in_addr* ip); - -/** - * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem - * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. - */ -char* inet_ntoa(struct in_addr ip); +// arpa/inet.h braucht die Definitionen von oben. Eigentlich muesste das hier +// gar nicht eingebunden werden, aber manche Programme erwarten Definitionen +// von dort hier. +#include #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index f747da6..3a89ef4 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -33,6 +33,7 @@ #include #include #include +#include int h_errno; @@ -118,6 +119,65 @@ char* inet_ntoa(struct in_addr ip) return buf; } +/** + * Wandelt einen String, der eine Adresse (IPv4 or IPv6) enthaelt in ihre + * binaere Darstellung um. + * + * @param family Adressfamilie, fuer die umgewandelt werden soll (z.B. AF_INET) + * @param src Adresse als String + * @param dst Ziel fuer die binaere Darstellung (z.B. struct in_addr*) + * + * @return 1 bei Erfolg, 0 wenn die Adresse ungueltig ist. Bei sonstigen + * Fehlern -1 und errno wird gesetzt. + */ +int inet_pton(int family, const char* src, void* dst) +{ + struct in_addr* addr = dst; + + if (family != AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + + addr->s_addr = string_to_ip((char*) src); + return (addr->s_addr != 0); +} + +/** + * Wandelt eine Adresse (IPv4 oder IPv6) in einen String um. Der Ausgabepuffer + * wird vom Aufrufer uebergeben. + * + * @param family Adressfamilie, zu der src gehoert (z.B. AF_INET) + * @param src Adressstruktur, die umgewandelt werden soll (z.B. struct + * in_addr*) + * @param dst Ausgabepuffer + * @param size Laenge des Ausgabepuffers + * + * @return Pointer auf den Ausgabepuffer; im Fehlerfall NULL und errno wird + * gesetzt + */ +const char *inet_ntop(int family, const void* src, char* dst, socklen_t size) +{ + const struct in_addr* addr = src; + char* res; + + if (family != AF_INET) { + errno = EAFNOSUPPORT; + return NULL; + } + + res = ip_to_string(addr->s_addr); + if (size < strlen(res) + 1) { + free(res); + errno = ENOSPC; + return NULL; + } + + strncpy(dst, res, size); + free(res); + + return dst; +} struct hostent* gethostbyname(const char* name) { -- 1.6.0.2 From m.nemo at gmx.net Fri Aug 14 20:51:24 2009 From: m.nemo at gmx.net (Andreas Freimuth) Date: Fri, 14 Aug 2009 20:51:24 +0200 Subject: [tyndur-devel] [PATCH] strftime() In-Reply-To: <1250196995-20706-1-git-send-email-alexanderkluth@gmx.de> References: <1250196995-20706-1-git-send-email-alexanderkluth@gmx.de> Message-ID: <4A85B22C.7080109@gmx.net> -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : patch.diff Dateityp : text/x-diff Dateigröße : 7689 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 899 bytes Beschreibung: OpenPGP digital signature URL : From kevin at tyndur.org Fri Aug 14 21:09:51 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 14 Aug 2009 21:09:51 +0200 Subject: [tyndur-devel] [PATCH] strftime() In-Reply-To: <4A85B22C.7080109@gmx.net> References: <1250196995-20706-1-git-send-email-alexanderkluth@gmx.de> <4A85B22C.7080109@gmx.net> Message-ID: <20090814190951.GA7256@silvanus> On Fri, Aug 14, 2009 at 08:51:24PM +0200, Andreas Freimuth wrote: > libc: strftime() > > + strftime() hinzugef??gt > + enum's und nen const-Array hinzugef??gt, die das Leben leichter machen > > Signed-off-by: Alexander Hartmut Kluth > Signed-off-by: Andreas Freimuth Danke. Ein paar Umlaute waren noch kaputt, die habe ich gefixt und den Patch eingecheckt. From toni at tyndur.org Fri Aug 14 22:02:55 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 14 Aug 2009 22:02:55 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: POSIX: alarm(0) In-Reply-To: <1250012138-17824-2-git-send-email-kevin@tyndur.org> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> <1250012138-17824-2-git-send-email-kevin@tyndur.org> Message-ID: <20090814200254.GA11072@einstein.kaufmann.lan> On Tue, Aug 11 19:35, Kevin Wolf wrote: > ! libc: POSIX: alarm(0) bricht nur laufende Timer ab, aber erstellt > keinen neuen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 14 22:41:08 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 14 Aug 2009 22:41:08 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: POSIX: herror() und hstrerror() In-Reply-To: <1250012138-17824-3-git-send-email-kevin@tyndur.org> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> <1250012138-17824-3-git-send-email-kevin@tyndur.org> Message-ID: <20090814204108.GB11072@einstein.kaufmann.lan> On Tue, Aug 11 19:35, Kevin Wolf wrote: > + libc: POSIX: herror() und hstrerror(). Diese Funktionen zu haben > überzeugen git davon, dass er kein -lresolv benutzen sollte. > > Signed-off-by: Kevin Wolf > --- > src/modules/include/netdb.h | 14 +++++++++++++- > src/modules/lib/posix/net.c | 34 ++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+), 1 deletions(-) > > diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h > index 88cd98c..feb0ba2 100644 > --- a/src/modules/include/netdb.h > +++ b/src/modules/include/netdb.h > @@ -78,7 +78,7 @@ struct protoent* getprotobyname(const char* name); > /** Fehlerstatus fuer gethostbyaddr() und gethostbyname() */ > extern int h_errno; > > -/** Werte fuer h_error */ > +/** Werte fuer h_errno */ > enum { > HOST_NOT_FOUND, > NO_DATA, > @@ -86,5 +86,17 @@ enum { > TRY_AGAIN, > }; > > +/** > + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck > + */ > +const char* hstrerror(int error); > + > +/** > + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder > + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. > + */ > +void herror(const char* str); > + > + > #endif > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > index 44b45b5..f747da6 100644 > --- a/src/modules/lib/posix/net.c > +++ b/src/modules/lib/posix/net.c > @@ -57,6 +57,40 @@ unsigned short int ntohs(unsigned short int netshort) > } > > /** > + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck > + */ > +const char* hstrerror(int error) > +{ > + static const char* errors[] = { > + [HOST_NOT_FOUND] = "Unbekannter Rechner", > + [NO_DATA] = "Der gesuchte Name hat keine IP-Adresse", > + [NO_RECOVERY] = "Ein DNS-Fehler ist aufgetreten", > + [TRY_AGAIN] = "Zeitweiliger DNS-Fehler; erneut versuchen", > + }; Hm sowas wie "Fehler: Erfolg" ist hier nicht vorgesehen? > + > + if ((error < HOST_NOT_FOUND) || (error > TRY_AGAIN)) { > + return NULL; > + } > + > + return errors[error]; > +} > + > +/** > + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder > + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. > + */ > +void herror(const char* str) > +{ > + if (str && *str) { > + fprintf(stderr, "%s: %s\n", str, hstrerror(h_errno)); Das finde ich dann auch ein bisschen 0xd00f, wenn das rot wird.... bei einem Fehler der noch nicht in hstrerror implementiert ist, oder so. Die alternative wäre natürlich printf fixen. *g* > + } else { > + fprintf(stderr, "%s\n", hstrerror(h_errno)); > + } > +} > + > + > + > +/** > * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen > * 32-Bit-Wert um. > * -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Fri Aug 14 23:01:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 14 Aug 2009 23:01:23 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: POSIX: herror() und hstrerror() In-Reply-To: <20090814204108.GB11072@einstein.kaufmann.lan> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> <1250012138-17824-3-git-send-email-kevin@tyndur.org> <20090814204108.GB11072@einstein.kaufmann.lan> Message-ID: <20090814210122.GB7256@silvanus> On Fri, Aug 14, 2009 at 10:41:08PM +0200, Antoine Kaufmann wrote: > On Tue, Aug 11 19:35, Kevin Wolf wrote: > > + libc: POSIX: herror() und hstrerror(). Diese Funktionen zu haben > > überzeugen git davon, dass er kein -lresolv benutzen sollte. > > > > Signed-off-by: Kevin Wolf > > --- > > src/modules/include/netdb.h | 14 +++++++++++++- > > src/modules/lib/posix/net.c | 34 ++++++++++++++++++++++++++++++++++ > > 2 files changed, 47 insertions(+), 1 deletions(-) > > > > diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h > > index 88cd98c..feb0ba2 100644 > > --- a/src/modules/include/netdb.h > > +++ b/src/modules/include/netdb.h > > @@ -78,7 +78,7 @@ struct protoent* getprotobyname(const char* name); > > /** Fehlerstatus fuer gethostbyaddr() und gethostbyname() */ > > extern int h_errno; > > > > -/** Werte fuer h_error */ > > +/** Werte fuer h_errno */ > > enum { > > HOST_NOT_FOUND, > > NO_DATA, > > @@ -86,5 +86,17 @@ enum { > > TRY_AGAIN, > > }; > > > > +/** > > + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck > > + */ > > +const char* hstrerror(int error); > > + > > +/** > > + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder > > + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. > > + */ > > +void herror(const char* str); > > + > > + > > #endif > > > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > > index 44b45b5..f747da6 100644 > > --- a/src/modules/lib/posix/net.c > > +++ b/src/modules/lib/posix/net.c > > @@ -57,6 +57,40 @@ unsigned short int ntohs(unsigned short int netshort) > > } > > > > /** > > + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck > > + */ > > +const char* hstrerror(int error) > > +{ > > + static const char* errors[] = { > > + [HOST_NOT_FOUND] = "Unbekannter Rechner", > > + [NO_DATA] = "Der gesuchte Name hat keine IP-Adresse", > > + [NO_RECOVERY] = "Ein DNS-Fehler ist aufgetreten", > > + [TRY_AGAIN] = "Zeitweiliger DNS-Fehler; erneut versuchen", > > + }; > > Hm sowas wie "Fehler: Erfolg" ist hier nicht vorgesehen? man netdb.h Scheint sowas nicht zu geben, nein. Das ist die vollständige Aufzählung. > > > + > > + if ((error < HOST_NOT_FOUND) || (error > TRY_AGAIN)) { > > + return NULL; > > + } > > + > > + return errors[error]; > > +} > > + > > +/** > > + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder > > + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. > > + */ > > +void herror(const char* str) > > +{ > > + if (str && *str) { > > + fprintf(stderr, "%s: %s\n", str, hstrerror(h_errno)); > > Das finde ich dann auch ein bisschen 0xd00f, wenn das rot wird.... bei > einem Fehler der noch nicht in hstrerror implementiert ist, oder so. Die > alternative wäre natürlich printf fixen. *g* Naja, wenn NULL zurueckkommt, ist sowieso was kaputt. Und printf geht unter Linux wie folgt: kevin at silvanus:/tmp> cat test.c #include int main(void) { printf("%s\n", NULL); return 0; } kevin at silvanus:/tmp> gcc test.c -o test kevin at silvanus:/tmp> ./test Speicherzugriffsfehler kevin at silvanus:/tmp> From toni at tyndur.org Fri Aug 14 23:37:48 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 14 Aug 2009 23:37:48 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: POSIX: herror() und hstrerror() In-Reply-To: <20090814210122.GB7256@silvanus> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> <1250012138-17824-3-git-send-email-kevin@tyndur.org> <20090814204108.GB11072@einstein.kaufmann.lan> <20090814210122.GB7256@silvanus> Message-ID: <20090814213748.GD11072@einstein.kaufmann.lan> On Fri, Aug 14 23:01, Kevin Wolf wrote: > On Fri, Aug 14, 2009 at 10:41:08PM +0200, Antoine Kaufmann wrote: > > On Tue, Aug 11 19:35, Kevin Wolf wrote: > > > + libc: POSIX: herror() und hstrerror(). Diese Funktionen zu haben > > > überzeugen git davon, dass er kein -lresolv benutzen sollte. > > > > > > Signed-off-by: Kevin Wolf > > > --- > > > src/modules/include/netdb.h | 14 +++++++++++++- > > > src/modules/lib/posix/net.c | 34 ++++++++++++++++++++++++++++++++++ > > > 2 files changed, 47 insertions(+), 1 deletions(-) > > > > > > diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h > > > index 88cd98c..feb0ba2 100644 > > > --- a/src/modules/include/netdb.h > > > +++ b/src/modules/include/netdb.h > > > @@ -78,7 +78,7 @@ struct protoent* getprotobyname(const char* name); > > > /** Fehlerstatus fuer gethostbyaddr() und gethostbyname() */ > > > extern int h_errno; > > > > > > -/** Werte fuer h_error */ > > > +/** Werte fuer h_errno */ > > > enum { > > > HOST_NOT_FOUND, > > > NO_DATA, > > > @@ -86,5 +86,17 @@ enum { > > > TRY_AGAIN, > > > }; > > > > > > +/** > > > + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck > > > + */ > > > +const char* hstrerror(int error); > > > + > > > +/** > > > + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder > > > + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. > > > + */ > > > +void herror(const char* str); > > > + > > > + > > > #endif > > > > > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > > > index 44b45b5..f747da6 100644 > > > --- a/src/modules/lib/posix/net.c > > > +++ b/src/modules/lib/posix/net.c > > > @@ -57,6 +57,40 @@ unsigned short int ntohs(unsigned short int netshort) > > > } > > > > > > /** > > > + * Gibt den Fehlerstring fuer einen gegebenen Wert von h_errno zurueck > > > + */ > > > +const char* hstrerror(int error) > > > +{ > > > + static const char* errors[] = { > > > + [HOST_NOT_FOUND] = "Unbekannter Rechner", > > > + [NO_DATA] = "Der gesuchte Name hat keine IP-Adresse", > > > + [NO_RECOVERY] = "Ein DNS-Fehler ist aufgetreten", > > > + [TRY_AGAIN] = "Zeitweiliger DNS-Fehler; erneut versuchen", > > > + }; > > > > Hm sowas wie "Fehler: Erfolg" ist hier nicht vorgesehen? > > man netdb.h > > Scheint sowas nicht zu geben, nein. Das ist die vollständige Aufzählung. Kaputte Sache sowas ;-) > > > > > > + > > > + if ((error < HOST_NOT_FOUND) || (error > TRY_AGAIN)) { > > > + return NULL; > > > + } > > > + > > > + return errors[error]; > > > +} > > > + > > > +/** > > > + * Gibt str gefolgt vom String fuer h_errno auf stderr aus. Wenn str NULL oder > > > + * ein leerer String ist, wird nur der Fehlerstring ausgegeben. > > > + */ > > > +void herror(const char* str) > > > +{ > > > + if (str && *str) { > > > + fprintf(stderr, "%s: %s\n", str, hstrerror(h_errno)); > > > > Das finde ich dann auch ein bisschen 0xd00f, wenn das rot wird.... bei > > einem Fehler der noch nicht in hstrerror implementiert ist, oder so. Die > > alternative wäre natürlich printf fixen. *g* > > Naja, wenn NULL zurueckkommt, ist sowieso was kaputt. Und printf geht > unter Linux wie folgt: > > kevin at silvanus:/tmp> cat test.c > #include > > int main(void) > { > printf("%s\n", NULL); > return 0; > } > kevin at silvanus:/tmp> gcc test.c -o test > kevin at silvanus:/tmp> ./test > Speicherzugriffsfehler > kevin at silvanus:/tmp> Nicht unbedingt, wie wir gesehen haben. ;-) Aber jo, pack halt rein. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Fri Aug 14 23:46:21 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 14 Aug 2009 23:46:21 +0200 Subject: [tyndur-devel] [PATCH 3/3] libc: POSIX: libgen.h In-Reply-To: <1250012138-17824-4-git-send-email-kevin@tyndur.org> References: <1250012138-17824-1-git-send-email-kevin@tyndur.org> <1250012138-17824-4-git-send-email-kevin@tyndur.org> Message-ID: <20090814214621.GE11072@einstein.kaufmann.lan> On Tue, Aug 11 19:35, Kevin Wolf wrote: > + libc: POSIX: libgen.h mit dirname() und basename() hinzugefuegt > > Signed-off-by: Kevin Wolf Sieht vernünftig aus. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From matthew at theiselins.net Sat Aug 15 13:45:14 2009 From: matthew at theiselins.net (Matthew Iselin) Date: Sat, 15 Aug 2009 21:45:14 +1000 Subject: [tyndur-devel] [PATCH] CDI NE2K driver Message-ID: <1250336714-5885-1-git-send-email-matthew@theiselins.net> This patch adds a CDI driver for the NE2K (PCI) NIC. Signed-off-by: Matthew Iselin --- src/modules/cdi/ne2k/Makefile.all | 6 + src/modules/cdi/ne2k/include/ethernet.h | 43 ++++ src/modules/cdi/ne2k/include/ne2k.h | 105 +++++++++ src/modules/cdi/ne2k/main.c | 118 ++++++++++ src/modules/cdi/ne2k/ne2k.c | 355 +++++++++++++++++++++++++++++++ 5 files changed, 627 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/ne2k/Makefile.all create mode 100644 src/modules/cdi/ne2k/include/ethernet.h create mode 100644 src/modules/cdi/ne2k/include/ne2k.h create mode 100644 src/modules/cdi/ne2k/main.c create mode 100644 src/modules/cdi/ne2k/ne2k.c diff --git a/src/modules/cdi/ne2k/Makefile.all b/src/modules/cdi/ne2k/Makefile.all new file mode 100644 index 0000000..250d3c3 --- /dev/null +++ b/src/modules/cdi/ne2k/Makefile.all @@ -0,0 +1,6 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/modules/ne2k" +$LOST_TOOLS_LD -Ttext=0x40000000 -one2k.mod *.o --start-group $2 --end-group +$LOST_TOOLS_STRIP -s ne2k.mod -o $1/modules/ne2k diff --git a/src/modules/cdi/ne2k/include/ethernet.h b/src/modules/cdi/ne2k/include/ethernet.h new file mode 100644 index 0000000..a8159d1 --- /dev/null +++ b/src/modules/cdi/ne2k/include/ethernet.h @@ -0,0 +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. + * + * 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 _ETHERNET_H_ +#define _ETHERNET_H_ + +#include + +#define ETH_TYPE_IP 0x0008 +#define ETH_TYPE_ARP 0x0608 + +struct eth_packet_header { + uint64_t dest : 48; + uint64_t src : 48; + uint16_t type; +} __attribute__ ((packed)); + +#endif diff --git a/src/modules/cdi/ne2k/include/ne2k.h b/src/modules/cdi/ne2k/include/ne2k.h new file mode 100644 index 0000000..a3c78e3 --- /dev/null +++ b/src/modules/cdi/ne2k/include/ne2k.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Matthew Iselin. + * + * 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 _NE2K_H_ +#define _NE2K_H_ + +#include + +#include "cdi.h" +#include "cdi/net.h" +#include "cdi/pci.h" + +#define NE_CMD 0 +#define NE_PSTART 1 +#define NE_PSTOP 2 +#define NE_BNDRY 3 + +#define NE_TSR 4 // R +#define NE_TPSR 4 // W + +#define NE_TBCR0 5 +#define NE_TBCR1 6 + +#define NE_ISR 7 + +#define NE_RSAR0 8 +#define NE_RSAR1 9 +#define NE_RBCR0 10 +#define NE_RBCR1 11 + +#define NE_RCR 12 +#define NE_TCR 13 +#define NE_DCR 14 +#define NE_IMR 15 + +// Register page 1 +#define NE_PAR 1 // PAR0..5 +#define NE_CURR 7 +#define NE_MAR 8 + +// Packet ring buffer offsets +#define PAGE_TX 0x40 +#define PAGE_RX 0x50 +#define PAGE_STOP 0x80 + +#define NE_RESET 0x1F +#define NE_DATA 0x10 + +#define PHYS(netcard, field) \ + ((uintptr_t) netcard->phys + offsetof(struct rtl8139_device, field)) + +#define RX_BUFFER_SIZE 0x2000 +#define TX_BUFFER_SIZE 0x1000 + +typedef struct { + void* virt; + uintptr_t phys; +} cdi_dma_mem_ptr_t; + +struct ne2k_device { + struct cdi_net_device net; + struct cdi_pci_device* pci; + + void* phys; + uint16_t port_base; + + uint8_t next_packet; + + int tx_in_progress; + + cdi_list_t pending_sends; +}; + +void ne2k_init_device(struct cdi_device* device); +void ne2k_remove_device(struct cdi_device* device); + +void ne2k_send_packet + (struct cdi_net_device* device, void* data, size_t size); + +#endif diff --git a/src/modules/cdi/ne2k/main.c b/src/modules/cdi/ne2k/main.c new file mode 100644 index 0000000..66ec9a8 --- /dev/null +++ b/src/modules/cdi/ne2k/main.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Matthew Iselin. + * + * 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. + */ + +#include + +#include "cdi/net.h" +#include "cdi/pci.h" +#include "cdi/misc.h" + +#include "ne2k.h" + +struct module_options { + uint32_t ip; +}; + +static struct { + struct cdi_net_driver net; +} driver; + +static const char* driver_name = "ne2k"; + +static int ne2k_driver_init(int argc, char* argv[]); +static void ne2k_driver_destroy(struct cdi_driver* driver); + +#ifdef CDI_STANDALONE +int main(int argc, char* argv[]) +#else +int init_ne2k(int argc, char* argv[]) +#endif +{ + cdi_init(); + + ne2k_driver_init(argc, argv); + cdi_driver_register((struct cdi_driver*) &driver); + + cdi_run_drivers(); + + return 0; +} + +static int ne2k_driver_init(int argc, char* argv[]) +{ + // TODO Auf pci-Service warten + // TODO Auf tcpip-Service warten + + // Konstruktor der Vaterklasse + cdi_net_driver_init((struct cdi_net_driver*) &driver); + + // Namen setzen + driver.net.drv.name = driver_name; + + // Funktionspointer initialisieren + driver.net.drv.destroy = ne2k_driver_destroy; + driver.net.drv.init_device = ne2k_init_device; + driver.net.drv.remove_device = ne2k_remove_device; + + // Passende PCI-Geraete suchen + cdi_list_t pci_devices = cdi_list_create(); + cdi_pci_get_all_devices(pci_devices); + + struct cdi_pci_device* dev; + int i; + for (i = 0; (dev = cdi_list_get(pci_devices, i)); i++) { + if ((dev->vendor_id == 0x10ec) && (dev->device_id == 0x8029)) { + void* phys_device; + struct ne2k_device* device; + + cdi_alloc_phys_mem(sizeof(*device), + (void**) &device, &phys_device); + memset(device, 0, sizeof(*device)); + + device->phys = phys_device; + device->pci = dev; + cdi_list_push(driver.net.drv.devices, device); + } else { + cdi_pci_device_destroy(dev); + } + } + + cdi_list_destroy(pci_devices); + + return 0; +} + +/** + * Deinitialisiert die Datenstrukturen fuer den ne2k-Treiber + */ +static void ne2k_driver_destroy(struct cdi_driver* driver) +{ + cdi_net_driver_destroy((struct cdi_net_driver*) driver); + + // TODO Alle Karten deinitialisieren +} diff --git a/src/modules/cdi/ne2k/ne2k.c b/src/modules/cdi/ne2k/ne2k.c new file mode 100644 index 0000000..2e54f28 --- /dev/null +++ b/src/modules/cdi/ne2k/ne2k.c @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Matthew Iselin. + * + * 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. + */ + +#include +#include +#include + +#include "cdi/net.h" +#include "cdi/pci.h" +#include "cdi/io.h" +#include "cdi/misc.h" + +#include "ne2k.h" +#include "ethernet.h" + +//Hier koennen die Debug-Nachrichten aktiviert werden +// #define DEBUG_MSG(s) printf("[ne2k] debug: %s() '%s'\n", __FUNCTION__, s) +#define DEBUG_MSG(s) // + +static void ne2k_handle_interrupt(struct cdi_device* device); +static void receive_ok_handler(struct ne2k_device* netcard); +static void transmit_ok_handler(struct ne2k_device* netcard); + +static inline void write_register_byte(struct ne2k_device* netcard, uint8_t reg, uint8_t value) +{ + cdi_outb(netcard->port_base + reg, value); +} + +static inline void write_register_word(struct ne2k_device* netcard, uint8_t reg, uint16_t value) +{ + cdi_outw(netcard->port_base + reg, value); +} + +static inline void write_register_dword(struct ne2k_device* netcard, uint8_t reg, uint32_t value) +{ + cdi_outl(netcard->port_base + reg, value); +} + +static inline uint8_t read_register_byte(struct ne2k_device* netcard, uint8_t reg) +{ + return cdi_inb(netcard->port_base + reg); +} + +static inline uint16_t read_register_word(struct ne2k_device* netcard, uint8_t reg) +{ + return cdi_inw(netcard->port_base + reg); +} + +static inline uint32_t read_register_dword(struct ne2k_device* netcard, uint8_t reg) +{ + return cdi_inl(netcard->port_base + reg); +} + +void ne2k_init_device(struct cdi_device* device) +{ + struct ne2k_device* netcard = (struct ne2k_device*) device; + netcard->net.send_packet = ne2k_send_packet; + + // PCI-bezogenes Zeug initialisieren + DEBUG_MSG("Interrupthandler und Ports registrieren"); + cdi_register_irq(netcard->pci->irq, ne2k_handle_interrupt, device); + cdi_pci_alloc_ioports(netcard->pci); + + cdi_list_t reslist = netcard->pci->resources; + struct cdi_pci_resource* res; + int i; + for (i = 0; (res = cdi_list_get(reslist, i)); i++) { + if (res->type == CDI_PCI_IOPORTS) { + netcard->port_base = res->start; + } + } + + // Reset the card + DEBUG_MSG("Resetting the card"); + write_register_byte(netcard, NE_CMD, 0x21); + + // Enable 16-bit transfer, turn on monitor mode to avoid receiving packets + // and turn on loopback just in case. Receive logic is not ready yet. + write_register_byte(netcard, NE_DCR, 0x09); + write_register_byte(netcard, NE_RCR, 0x20); + write_register_byte(netcard, NE_TCR, 0x02); + + // Disable card interrupts + write_register_byte(netcard, NE_ISR, 0xFF); + write_register_byte(netcard, NE_IMR, 0); + + // Read the MAC address from PROM + write_register_byte(netcard, NE_RSAR0, 0); + write_register_byte(netcard, NE_RSAR1, 0); + + write_register_byte(netcard, NE_RBCR0, 32); + write_register_byte(netcard, NE_RBCR1, 0); + + write_register_byte(netcard, NE_CMD, 0x0A); + + uint16_t prom[16]; + uint8_t mac[6]; + for(i = 0; i < 16; i++) { + prom[i] = read_register_word(netcard, NE_DATA); + } + + // Set the MAC address for the system use + for(i = 0; i < 6; i++) { + mac[i] = (uint8_t) (prom[i] & 0xFF); + } + netcard->net.mac = (*(uint32_t*) (&mac[0])) | ((uint64_t) ((*(uint32_t*) (&mac[4])) & 0xFFFF) << 32); + + // Setup the packet ring buffer + write_register_byte(netcard, NE_CMD, 0x61); + netcard->next_packet = PAGE_RX + 1; + write_register_byte(netcard, NE_CURR, netcard->next_packet); + + write_register_byte(netcard, NE_CMD, 0x21); + + write_register_byte(netcard, NE_PSTART, PAGE_RX); + write_register_byte(netcard, NE_BNDRY, PAGE_RX); + write_register_byte(netcard, NE_PSTOP, PAGE_STOP); + + // Accept broadcast and runt packets + write_register_byte(netcard, NE_RCR, 0x06); + write_register_byte(netcard, NE_TCR, 0); + + // Clear pending interrupts, enable them all, and begin card operation + write_register_byte(netcard, NE_ISR, 0xFF); + write_register_byte(netcard, NE_IMR, 0x3F); + write_register_byte(netcard, NE_CMD, 0x22); + + netcard->pending_sends = cdi_list_create(); + + cdi_net_device_init((struct cdi_net_device*) device); + DEBUG_MSG("Fertig initialisiert"); +} + +void ne2k_remove_device(struct cdi_device* device) +{ +} + +void ne2k_send_packet + (struct cdi_net_device* device, void* data, size_t size) +{ + struct ne2k_device* netcard = (struct ne2k_device*) device; + + if (size > 0x700) { + // Spezialfall - keine Lust + printf("ne2k: size ist boese\n"); + return; + } + + if (!__sync_lock_test_and_set(&netcard->tx_in_progress, 1)) { + netcard->tx_in_progress = 1; + } else { + DEBUG_MSG("Tx-Buffer ist schon besetzt"); + + void* pending = malloc(size + sizeof(uint32_t)); + cdi_list_insert(netcard->pending_sends, + cdi_list_size(netcard->pending_sends), pending); + *((uint32_t*) pending) = size; + pending += sizeof(uint32_t); + memcpy(pending, data, size); + + return; + } + + // Send the length/address for this write + write_register_byte(netcard, NE_RSAR0, 0); + write_register_byte(netcard, NE_RSAR1, PAGE_TX); + + write_register_byte(netcard, NE_RBCR0, (size > 64) ? (size & 0xff) : 64); + write_register_byte(netcard, NE_RBCR1, size >> 8); + + write_register_byte(netcard, NE_CMD, 0x12); + + // Write to the NIC + uint16_t *p = (uint16_t*) data; + size_t i; + for(i = 0; (i + 1) < size; i += 2) { + write_register_word(netcard, NE_DATA, p[i/2]); + } + + // Handle odd bytes + if(size & 1) { + write_register_byte(netcard, NE_DATA, p[i/2]); + i++; + } + + // Pad to 64 bytes, if needed + for(; i < 64; i += 2) { + write_register_word(netcard, NE_DATA, 0); + } + + // Await the transfer completion and then transmit + // FIXME: Should wait upon a mutex or something which is unlocked when + // the IRQ fires. + while(!(read_register_byte(netcard, NE_ISR) & 0x40)); + write_register_byte(netcard, NE_ISR, 0x40); + + write_register_byte(netcard, NE_TBCR0, (size > 64) ? (size & 0xff) : 64); + write_register_byte(netcard, NE_TBCR1, size >> 8); + + write_register_byte(netcard, NE_TPSR, PAGE_TX); + + write_register_byte(netcard, NE_CMD, 0x26); +} + +static void receive_ok_handler(struct ne2k_device* netcard) +{ + DEBUG_MSG("ROK"); + + write_register_byte(netcard, NE_ISR, 0x1); + + write_register_byte(netcard, NE_CMD, 0x61); + uint8_t current = read_register_byte(netcard, NE_CURR); + write_register_byte(netcard, NE_CMD, 0x21); + + while (netcard->next_packet != current) + { + write_register_byte(netcard, NE_RSAR0, 0); + write_register_byte(netcard, NE_RSAR1, netcard->next_packet); + + // 4 bytes - 2 for status, 2 for length + write_register_byte(netcard, NE_RBCR0, 4); + write_register_byte(netcard, NE_RBCR1, 0); + + write_register_byte(netcard, NE_CMD, 0x0A); + + uint16_t status = read_register_word(netcard, NE_DATA); + uint16_t length = read_register_word(netcard, NE_DATA); + + if(!length) { + break; + } + + // Remove status and length bytes + length -= 3; + + if (length >= sizeof(struct eth_packet_header)) + { + // Verify status + while(!(read_register_byte(netcard, NE_ISR) & 0x40)); + write_register_byte(netcard, NE_ISR, 0x40); + + // Read the packet + write_register_byte(netcard, NE_RSAR0, 4); + write_register_byte(netcard, NE_RSAR1, netcard->next_packet); + write_register_byte(netcard, NE_RBCR0, length & 0xFF); + write_register_byte(netcard, NE_RBCR1, (length >> 8) & 0xFF); + + write_register_byte(netcard, NE_CMD, 0x0A); + + uint16_t data[(length / 2) + 1]; + int i, words = (length / 2); + for(i = 0; i < words; ++i) { + data[i] = read_register_word(netcard, NE_DATA); + } + if(length & 1) { + data[i] = read_register_word(netcard, NE_DATA) & 0xFF; + } + + // Verify status + while(!(read_register_byte(netcard, NE_ISR) & 0x40)); + write_register_byte(netcard, NE_ISR, 0x40); + + netcard->next_packet = status >> 8; + write_register_byte(netcard, NE_BNDRY, (netcard->next_packet == PAGE_RX) ? (PAGE_STOP - 1) : (netcard->next_packet - 1)); + + cdi_net_receive( + (struct cdi_net_device*) netcard, + (uint8_t*) data, + length); + } + } +} + +static void transmit_ok_handler(struct ne2k_device* netcard) +{ + DEBUG_MSG("TOK"); + netcard->tx_in_progress = 0; +} + +static void ne2k_handle_interrupt(struct cdi_device* device) +{ + DEBUG_MSG(""); + + struct ne2k_device* netcard = (struct ne2k_device*) device; + uint32_t isr = read_register_word(netcard, NE_ISR); + + // Packet received? + if(isr & 0x05) { + DEBUG_MSG("ne2k: received packet"); + if(!(isr & 0x04)) { + write_register_byte(netcard, NE_IMR, 0x3A); + isr &= ~1; + receive_ok_handler(netcard); + write_register_byte(netcard, NE_IMR, 0x3F); + } + else { + DEBUG_MSG("ne2k: receive failed"); + } + } + + // Packet transmitted? + if(isr & 0x0A) { + if(!(isr & 0x8)) { + transmit_ok_handler(netcard); + } + } + + // Overflows + if(isr & 0x10) { + DEBUG_MSG("ne2K: receive buffer overflow"); + } + if(isr & 0x20) { + DEBUG_MSG("ne2K: counter overflow"); + } + + write_register_byte(netcard, NE_ISR, isr); + + // Falls noch Pakete zu senden waren, die nicht gesendet werden + // konnten, weil die Karte beschaeftigt war, das jetzt nachholen + void* pending = cdi_list_pop(netcard->pending_sends); + if (pending) { + uint32_t size = *((uint32_t*) pending); + pending += sizeof(uint32_t); + DEBUG_MSG("Sende Paket aus der pending-Queue"); + ne2k_send_packet((struct cdi_net_device*) device, pending, size); + free(pending - sizeof(uint32_t)); + } + + DEBUG_MSG("interrupt returns"); +} -- 1.5.6.3 From kevin at tyndur.org Sat Aug 15 14:41:30 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 15 Aug 2009 14:41:30 +0200 Subject: [tyndur-devel] [PATCH] CDI NE2K driver In-Reply-To: <1250336714-5885-1-git-send-email-matthew@theiselins.net> References: <1250336714-5885-1-git-send-email-matthew@theiselins.net> Message-ID: <20090815124129.GA5256@silvanus> On Sat, Aug 15, 2009 at 09:45:14PM +1000, Matthew Iselin wrote: > This patch adds a CDI driver for the NE2K (PCI) NIC. > > Signed-off-by: Matthew Iselin Thanks, committed to both tyndur and CDI. From patrick at tyndur.org Sat Aug 15 22:20:52 2009 From: patrick at tyndur.org (Patrick Kaufmann) Date: Sat, 15 Aug 2009 22:20:52 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_rm_folgende_flags_hinzugef?= =?utf-8?q?=C3=BCgt=3A_recursive=2C_verbose=2C_interactive?= Message-ID: <1250367652-10439-1-git-send-email-patrick@tyndur.org> --- src/modules/c/shell/cmds/rm.c | 191 ++++++++++++++++++++++++++++++++++++++--- 1 files changed, 180 insertions(+), 11 deletions(-) diff --git a/src/modules/c/shell/cmds/rm.c b/src/modules/c/shell/cmds/rm.c index a9d160f..19a7cc7 100644 --- a/src/modules/c/shell/cmds/rm.c +++ b/src/modules/c/shell/cmds/rm.c @@ -39,8 +39,13 @@ #include "unistd.h" #include "dir.h" #include +#include +#include +#include +#include void rm_display_usage(void); +int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive); #ifdef CONFIG_SHELL_BUILTIN_ONLY int shell_command_rm(int argc, char* argv[], const char* args) @@ -48,25 +53,189 @@ void rm_display_usage(void); int main(int argc, char* argv[]) #endif { - if (argc != 2) { - rm_display_usage(); - return -1; + static const struct option long_options[] = + { + { "recursive", no_argument, 0, 'r' }, + { "help", no_argument, 0, 'h' }, + { "verbose", no_argument, 0, 'v' }, + { "interactive", optional_argument, 0, 'i' }, + { "interactive", optional_argument, 0, 'I' }, + { 0, 0, 0, 0 } + }; + + int result = 0; + bool verbose = 0; + bool recursive = 0; + int directory = 0; + int interactive = 0; + char* src_path = NULL; + + list_t* sources = list_create(); + + optind = 0; + opterr = 0; + + while (optind < argc) { + result = getopt_long(argc, argv, "vriIh", long_options, NULL); + if (result == -1) { + break; + } + switch (result) { + case 'r': + recursive = 1; + break; + case 'v': + verbose = 1; + break; + case 'i': + if ((optarg != NULL)) { + if (strcmp("always", optarg)) { + interactive = 2; + } + if (strcmp("once", optarg)) { + interactive = 1; + } + } else { + interactive = 1; + } + break; + case 'I': + if ((optarg != NULL)) { + if (strcmp("always", optarg)) { + interactive = 2; + } + if (strcmp("once", optarg)) { + interactive = 1; + } + } else { + interactive = 2; + } + break; + case 'h': + rm_display_usage(); + return EXIT_SUCCESS; + case '?': + printf("rm: Unbekannter Parameter: '%c'\n", optopt); + return EXIT_FAILURE; + default: + break; + } } - - int result = io_remove_link(argv[1]); - - if (result != 0) { - puts("Fehler beim Loeschen des Links"); + + if (!(optind < argc)) { + printf("Probiere \'rm --help\' fuer mehr Informationen\n"); return EXIT_FAILURE; } + while (optind < argc) { + char* p = strdup(argv[optind++]); + int len = strlen(p); + if (p[len - 1] == '/') { + p[len - 1] = 0; + } + list_push(sources, p); + } + + while ((src_path = list_pop(sources))) { + + directory = is_directory(src_path); + if (directory) { + if (!recursive) { + printf("rm: \'%s/\' ist ein Ordner: Uebersprungen\n", + src_path); + result = -1; + } else { + result += rm_recursive(src_path, TRUE, verbose, interactive); + } + } else { + result += rm_recursive(src_path, FALSE, verbose, interactive); + } + } + list_destroy(sources); + + if (result != 0) { + return EXIT_FAILURE; + } return EXIT_SUCCESS; } void rm_display_usage() { - puts("\nAufruf: rm "); - puts("\nHardlink an loeschen. Falls es sich um den Letzten " - "handelt, wird die Datei/das Verzeichnis geloescht."); + puts("Aufruf: rm \n"); + puts("Hardlink an loeschen. Falls es sich um den Letzten " + "handelt, wird die Datei/das Verzeichnis geloescht.\n" + "Optionen:\n" + " -r --recursive Verzeichnis rekursiv löschen\n" + " -v --verbose Statusmeldungen anzeigen\n" + " -i --interactive " + "Jedesmal fragen ob gelöscht werden soll\n" + " -I --interactive " + "Einmal fragen ob gelöscht werden soll\n" + " -h --help diese Hilfe anzeigen\n"); +} + +int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive) +{ + int result = 0; + char* path = NULL; + io_resource_t* dir_res; + char c; + struct stat buf; + if ((stat(src_path, &buf))) { + printf("rm: \'%s\' ist inexistent\n", src_path); + return -1; + } + + + switch (interactive) { + case 1: // interactive_option = "always" + printf("rm: \'%s\' loeschen? \n", src_path); + fflush(stdout); + while ((c = getchar()) == EOF); + if (c != 'y') { + printf("rm: \'%s\' übersprungen\n", src_path); + return -1; // Fehlschlag + } + break; + case 2: // interactive_option = "once" + printf("rm: \'%s\' loeschen? \n", src_path); + fflush(stdout); + while ((c = getchar()) == EOF); + if (c != 'y') { + printf("rm: \'%s\' übersprungen\n", src_path); + return -1; + } + interactive = 0; + break; + default: // interactive_option = NULL + break; + } + if (verbose) { + printf("removed \'%s\'\n", src_path); + } + if (recurse && (dir_res = directory_open(src_path))) { + io_direntry_t* direntry; + list_t* fn_list = list_create(); + + while ((direntry = directory_read(dir_res))) { + asprintf(&path, "%s/%s", src_path, direntry->name); + list_push(fn_list, path); + free(direntry); + } + directory_close(dir_res); + + while ((path = list_pop(fn_list))) { + rm_recursive(path, recurse, verbose, interactive); + free(path); + } + list_destroy(fn_list); + io_remove_link(src_path); + } else { + result = io_remove_link(src_path); + if (result != 0) { + printf("rm: \'%s/\' konnte nicht geloescht werden \n", src_path); + } + } + return result; } -- 1.6.3.3 From patrick at tyndur.org Sat Aug 15 23:00:29 2009 From: patrick at tyndur.org (Patrick Kaufmann) Date: Sat, 15 Aug 2009 23:00:29 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_rm_folgende_flags_hinzu?= =?iso-8859-1?q?gef=FCgt=3A_recursive=2C_verbose=2C_interactive?= In-Reply-To: <1250367652-10439-1-git-send-email-patrick@tyndur.org> References: <1250367652-10439-1-git-send-email-patrick@tyndur.org> Message-ID: <20090815210029.GA10604@pauli.kaufmann.lan> Signed-off-by: Patrick Kaufmann On Sat, Aug 15 22:20, Patrick Kaufmann wrote: > --- > src/modules/c/shell/cmds/rm.c | 191 ++++++++++++++++++++++++++++++++++++++--- > 1 files changed, 180 insertions(+), 11 deletions(-) > > diff --git a/src/modules/c/shell/cmds/rm.c b/src/modules/c/shell/cmds/rm.c > index a9d160f..19a7cc7 100644 > --- a/src/modules/c/shell/cmds/rm.c > +++ b/src/modules/c/shell/cmds/rm.c > @@ -39,8 +39,13 @@ > #include "unistd.h" > #include "dir.h" > #include > +#include > +#include > +#include > +#include > > void rm_display_usage(void); > +int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive); > > #ifdef CONFIG_SHELL_BUILTIN_ONLY > int shell_command_rm(int argc, char* argv[], const char* args) > @@ -48,25 +53,189 @@ void rm_display_usage(void); > int main(int argc, char* argv[]) > #endif > { > - if (argc != 2) { > - rm_display_usage(); > - return -1; > + static const struct option long_options[] = > + { > + { "recursive", no_argument, 0, 'r' }, > + { "help", no_argument, 0, 'h' }, > + { "verbose", no_argument, 0, 'v' }, > + { "interactive", optional_argument, 0, 'i' }, > + { "interactive", optional_argument, 0, 'I' }, > + { 0, 0, 0, 0 } > + }; > + > + int result = 0; > + bool verbose = 0; > + bool recursive = 0; > + int directory = 0; > + int interactive = 0; > + char* src_path = NULL; > + > + list_t* sources = list_create(); > + > + optind = 0; > + opterr = 0; > + > + while (optind < argc) { > + result = getopt_long(argc, argv, "vriIh", long_options, NULL); > + if (result == -1) { > + break; > + } > + switch (result) { > + case 'r': > + recursive = 1; > + break; > + case 'v': > + verbose = 1; > + break; > + case 'i': > + if ((optarg != NULL)) { > + if (strcmp("always", optarg)) { > + interactive = 2; > + } > + if (strcmp("once", optarg)) { > + interactive = 1; > + } > + } else { > + interactive = 1; > + } > + break; > + case 'I': > + if ((optarg != NULL)) { > + if (strcmp("always", optarg)) { > + interactive = 2; > + } > + if (strcmp("once", optarg)) { > + interactive = 1; > + } > + } else { > + interactive = 2; > + } > + break; > + case 'h': > + rm_display_usage(); > + return EXIT_SUCCESS; > + case '?': > + printf("rm: Unbekannter Parameter: '%c'\n", optopt); > + return EXIT_FAILURE; > + default: > + break; > + } > } > - > - int result = io_remove_link(argv[1]); > - > - if (result != 0) { > - puts("Fehler beim Loeschen des Links"); > + > + if (!(optind < argc)) { > + printf("Probiere \'rm --help\' fuer mehr Informationen\n"); > return EXIT_FAILURE; > } > + while (optind < argc) { > + char* p = strdup(argv[optind++]); > + int len = strlen(p); > + if (p[len - 1] == '/') { > + p[len - 1] = 0; > + } > + list_push(sources, p); > + } > + > + while ((src_path = list_pop(sources))) { > + > + directory = is_directory(src_path); > + if (directory) { > + if (!recursive) { > + printf("rm: \'%s/\' ist ein Ordner: Uebersprungen\n", > + src_path); > + result = -1; > + } else { > + result += rm_recursive(src_path, TRUE, verbose, interactive); > + } > + } else { > + result += rm_recursive(src_path, FALSE, verbose, interactive); > + } > + } > + list_destroy(sources); > > + > + if (result != 0) { > + return EXIT_FAILURE; > + } > return EXIT_SUCCESS; > } > > void rm_display_usage() > { > - puts("\nAufruf: rm "); > - puts("\nHardlink an loeschen. Falls es sich um den Letzten " > - "handelt, wird die Datei/das Verzeichnis geloescht."); > + puts("Aufruf: rm \n"); > + puts("Hardlink an loeschen. Falls es sich um den Letzten " > + "handelt, wird die Datei/das Verzeichnis geloescht.\n" > + "Optionen:\n" > + " -r --recursive Verzeichnis rekursiv löschen\n" > + " -v --verbose Statusmeldungen anzeigen\n" > + " -i --interactive " > + "Jedesmal fragen ob gelöscht werden soll\n" > + " -I --interactive " > + "Einmal fragen ob gelöscht werden soll\n" > + " -h --help diese Hilfe anzeigen\n"); > +} > + > +int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive) > +{ > + int result = 0; > + char* path = NULL; > + io_resource_t* dir_res; > + char c; > + struct stat buf; > + if ((stat(src_path, &buf))) { > + printf("rm: \'%s\' ist inexistent\n", src_path); > + return -1; > + } > + > + > + switch (interactive) { > + case 1: // interactive_option = "always" > + printf("rm: \'%s\' loeschen? \n", src_path); > + fflush(stdout); > + while ((c = getchar()) == EOF); > + if (c != 'y') { > + printf("rm: \'%s\' übersprungen\n", src_path); > + return -1; // Fehlschlag > + } > + break; > + case 2: // interactive_option = "once" > + printf("rm: \'%s\' loeschen? \n", src_path); > + fflush(stdout); > + while ((c = getchar()) == EOF); > + if (c != 'y') { > + printf("rm: \'%s\' übersprungen\n", src_path); > + return -1; > + } > + interactive = 0; > + break; > + default: // interactive_option = NULL > + break; > + } > + if (verbose) { > + printf("removed \'%s\'\n", src_path); > + } > + if (recurse && (dir_res = directory_open(src_path))) { > + io_direntry_t* direntry; > + list_t* fn_list = list_create(); > + > + while ((direntry = directory_read(dir_res))) { > + asprintf(&path, "%s/%s", src_path, direntry->name); > + list_push(fn_list, path); > + free(direntry); > + } > + directory_close(dir_res); > + > + while ((path = list_pop(fn_list))) { > + rm_recursive(path, recurse, verbose, interactive); > + free(path); > + } > + list_destroy(fn_list); > + io_remove_link(src_path); > + } else { > + result = io_remove_link(src_path); > + if (result != 0) { > + printf("rm: \'%s/\' konnte nicht geloescht werden \n", src_path); > + } > + } > + return result; > } > > -- > 1.6.3.3 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From kevin at tyndur.org Sun Aug 16 09:27:52 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 09:27:52 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_rm_folgende_flags_hinzu?= =?iso-8859-1?q?gef=FCgt=3A_recursive=2C_verbose=2C_interactive?= In-Reply-To: <1250367652-10439-1-git-send-email-patrick@tyndur.org> References: <1250367652-10439-1-git-send-email-patrick@tyndur.org> Message-ID: <20090816072752.GA4840@silvanus> On Sat, Aug 15, 2009 at 10:20:52PM +0200, Patrick Kaufmann wrote: > --- > src/modules/c/shell/cmds/rm.c | 191 ++++++++++++++++++++++++++++++++++++++--- > 1 files changed, 180 insertions(+), 11 deletions(-) > > diff --git a/src/modules/c/shell/cmds/rm.c b/src/modules/c/shell/cmds/rm.c > index a9d160f..19a7cc7 100644 > --- a/src/modules/c/shell/cmds/rm.c > +++ b/src/modules/c/shell/cmds/rm.c > @@ -39,8 +39,13 @@ > #include "unistd.h" > #include "dir.h" > #include > +#include > +#include > +#include > +#include > > void rm_display_usage(void); > +int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive); > > #ifdef CONFIG_SHELL_BUILTIN_ONLY > int shell_command_rm(int argc, char* argv[], const char* args) > @@ -48,25 +53,189 @@ void rm_display_usage(void); > int main(int argc, char* argv[]) > #endif > { > - if (argc != 2) { > - rm_display_usage(); > - return -1; > + static const struct option long_options[] = > + { > + { "recursive", no_argument, 0, 'r' }, > + { "help", no_argument, 0, 'h' }, > + { "verbose", no_argument, 0, 'v' }, > + { "interactive", optional_argument, 0, 'i' }, > + { "interactive", optional_argument, 0, 'I' }, Ist es sinnvoll, zweimal --interactive anzugeben? Ich würde erwarten, dass er dann sowieso immer nur das erste nimmt. > + { 0, 0, 0, 0 } > + }; > + > + int result = 0; > + bool verbose = 0; > + bool recursive = 0; > + int directory = 0; > + int interactive = 0; > + char* src_path = NULL; > + > + list_t* sources = list_create(); > + > + optind = 0; > + opterr = 0; > + > + while (optind < argc) { > + result = getopt_long(argc, argv, "vriIh", long_options, NULL); > + if (result == -1) { > + break; > + } > + switch (result) { > + case 'r': > + recursive = 1; > + break; > + case 'v': > + verbose = 1; > + break; > + case 'i': > + if ((optarg != NULL)) { > + if (strcmp("always", optarg)) { > + interactive = 2; > + } > + if (strcmp("once", optarg)) { > + interactive = 1; > + } > + } else { > + interactive = 1; > + } > + break; > + case 'I': > + if ((optarg != NULL)) { > + if (strcmp("always", optarg)) { > + interactive = 2; > + } > + if (strcmp("once", optarg)) { > + interactive = 1; > + } > + } else { > + interactive = 2; > + } > + break; Dann könnte man sich nämlich hier einen if-Block sparen. > + case 'h': > + rm_display_usage(); > + return EXIT_SUCCESS; > + case '?': > + printf("rm: Unbekannter Parameter: '%c'\n", optopt); > + return EXIT_FAILURE; > + default: > + break; > + } > } > - > - int result = io_remove_link(argv[1]); > - > - if (result != 0) { > - puts("Fehler beim Loeschen des Links"); > + > + if (!(optind < argc)) { Wäre das als >= nicht lesbarer? > + printf("Probiere \'rm --help\' fuer mehr Informationen\n"); > return EXIT_FAILURE; > } > + while (optind < argc) { > + char* p = strdup(argv[optind++]); > + int len = strlen(p); > + if (p[len - 1] == '/') { > + p[len - 1] = 0; > + } > + list_push(sources, p); > + } > + > + while ((src_path = list_pop(sources))) { > + > + directory = is_directory(src_path); > + if (directory) { > + if (!recursive) { > + printf("rm: \'%s/\' ist ein Ordner: Uebersprungen\n", Verzeichnis heißt das Wort ;-) > + src_path); > + result = -1; > + } else { > + result += rm_recursive(src_path, TRUE, verbose, interactive); > + } > + } else { > + result += rm_recursive(src_path, FALSE, verbose, interactive); > + } > + } > + list_destroy(sources); > > + > + if (result != 0) { > + return EXIT_FAILURE; > + } > return EXIT_SUCCESS; > } > > void rm_display_usage() > { > - puts("\nAufruf: rm "); > - puts("\nHardlink an loeschen. Falls es sich um den Letzten " > - "handelt, wird die Datei/das Verzeichnis geloescht."); > + puts("Aufruf: rm \n"); > + puts("Hardlink an loeschen. Falls es sich um den Letzten " > + "handelt, wird die Datei/das Verzeichnis geloescht.\n" > + "Optionen:\n" > + " -r --recursive Verzeichnis rekursiv löschen\n" > + " -v --verbose Statusmeldungen anzeigen\n" > + " -i --interactive " > + "Jedesmal fragen ob gelöscht werden soll\n" > + " -I --interactive " > + "Einmal fragen ob gelöscht werden soll\n" > + " -h --help diese Hilfe anzeigen\n"); > +} > + > +int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive) > +{ > + int result = 0; > + char* path = NULL; > + io_resource_t* dir_res; > + char c; > + struct stat buf; > + if ((stat(src_path, &buf))) { > + printf("rm: \'%s\' ist inexistent\n", src_path); > + return -1; > + } > + > + > + switch (interactive) { > + case 1: // interactive_option = "always" Dieser Kommentar am Zeilenende zeigt eigentlich deutlich, dass man hier besser eine Konstante INTERACTIVE_ALWAYS statt einer magischen 1 benutzt hätte. > + printf("rm: \'%s\' loeschen? \n", src_path); > + fflush(stdout); > + while ((c = getchar()) == EOF); > + if (c != 'y') { > + printf("rm: \'%s\' übersprungen\n", src_path); > + return -1; // Fehlschlag > + } > + break; > + case 2: // interactive_option = "once" > + printf("rm: \'%s\' loeschen? \n", src_path); > + fflush(stdout); > + while ((c = getchar()) == EOF); > + if (c != 'y') { > + printf("rm: \'%s\' übersprungen\n", src_path); > + return -1; > + } > + interactive = 0; > + break; > + default: // interactive_option = NULL > + break; > + } > + if (verbose) { > + printf("removed \'%s\'\n", src_path); Ups, falsche Sprache. From toni at tyndur.org Sun Aug 16 12:30:35 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 16 Aug 2009 12:30:35 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: Mehr arpa/inet.h In-Reply-To: <1250275414-25054-1-git-send-email-kevin@tyndur.org> References: <1250275414-25054-1-git-send-email-kevin@tyndur.org> Message-ID: <20090816103035.GA9727@einstein.kaufmann.lan> On Fri, Aug 14 20:43, Kevin Wolf wrote: > + libc: POSIX: inet_ntop() und inet_pton() > ! libc: POSIX: inet_ntoa() und inet_aton() gehoeren nach arpa/inet.h und > nicht nach netinet/in.h. Da letzteres ersteres includet, besteht auch > keine Gefahr, dass das Verschieben lbuilds ungluecklich macht. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Aug 16 14:58:24 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 16 Aug 2009 14:58:24 +0200 Subject: [tyndur-devel] [PATCH] libm: Rundungsfunktionen In-Reply-To: <1249910192-22291-1-git-send-email-kevin@tyndur.org> References: <1249910192-22291-1-git-send-email-kevin@tyndur.org> Message-ID: <20090816125824.GA13553@einstein.kaufmann.lan> On Mon, Aug 10 15:16, Kevin Wolf wrote: > + libm: floor, ceil, round, trunc, nearbyint, fesetround, fegetround > > Signed-off-by: Kevin Wolf > --- > src/modules/include/math.h | 25 ++++ > src/modules/lib/stdlibc/math/round.c | 212 ++++++++++++++++++++++++++++++++++ > 2 files changed, 237 insertions(+), 0 deletions(-) > create mode 100644 src/modules/lib/stdlibc/math/round.c > > diff --git a/src/modules/include/math.h b/src/modules/include/math.h > index 49083ab..138fff3 100644 > --- a/src/modules/include/math.h > +++ b/src/modules/include/math.h > @@ -49,6 +49,12 @@ > #define M_SQRT2 1.41421356237309504880 > #define M_SQRT1_2 0.70710678118654752440 > > +enum { > + FE_TONEAREST, > + FE_UPWARD, > + FE_DOWNWARD, > + FE_TOWARDZERO, > +}; Das gehört laut meinem C-Standard nach fenv.h > > > double tan(double); > @@ -94,5 +100,24 @@ double acos(double); > float acosf(float); > long double acosl(long double); > > + > +double floor(double x); > +float floorf(float x); > +long double floorl(long double x); > +double ceil(double x); > +float ceilf(float x); > +long double ceill(long double x); > +double trunc(double x); > +float truncf(float x); > +long double truncl(long double x); > +double round(double x); > +float roundf(float x); > +long double roundl(long double x); > +int fegetround(void); > +int fesetround(int rounding_mode); Die beiden genau so. > +double nearbyint(double x); > +float nearbyintf(float x); > +long double nearbyintl(long double x); > + > #endif > > diff --git a/src/modules/lib/stdlibc/math/round.c b/src/modules/lib/stdlibc/math/round.c > new file mode 100644 > index 0000000..b4fd618 > --- /dev/null > +++ b/src/modules/lib/stdlibc/math/round.c > @@ -0,0 +1,212 @@ > +/* > + * Copyright (c) 2009 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. > + * > + * 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. > + */ > + > +#include > +#include > +#include > + > +#define ROUND_NEAR "$0x000" > +#define ROUND_DOWN "$0x400" > +#define ROUND_UP "$0x800" > +#define ROUND_TRUNC "$0xc00" > + > +static int rounding_mode = FE_TONEAREST; > + > +/* > + * Achtung: > + * > + * Die folgenden Funktionen basieren auf der Annahme, dass das RC-Feld im FPU > + * Control Word normalerweise immer auf 0 gesetzt ist, also der neue Wert durch > + * ein einfaches or eingetragen werden kann. > + */ > + > +long double floorl(long double x) > +{ > + long double res; > + uint16_t control_word; > + > + asm( > + // Rundungsmodus setzen > + "fnstcw %2;" > + "mov %2, %%eax;" > + "orl " ROUND_DOWN ", %2;" > + "fldcw %2;" > + > + // Zahl auf dem Stack runden > + "frndint;" > + > + // Wieder den Standardrundungsmodus setzen > + "mov %%eax, %2;" > + "fldcw %2;" > + : "=t" (res) : "0" (x), "m" (control_word) : "eax"); > + > + return res; > +} > + > +double floor(double x) > +{ > + return floorl(x); > +} > + > +float floorf(float x) > +{ > + return floorl(x); > +} > + > + > +long double ceill(long double x) > +{ > + long double res; > + uint16_t control_word; > + > + asm( > + // Rundungsmodus setzen > + "fnstcw %2;" > + "mov %2, %%eax;" > + "orl " ROUND_UP ", %2;" > + "fldcw %2;" > + > + // Zahl auf dem Stack runden > + "frndint;" > + > + // Wieder den Standardrundungsmodus setzen > + "mov %%eax, %2;" > + "fldcw %2;" > + : "=t" (res) : "0" (x), "m" (control_word) : "eax"); > + Hm könnte man floorl, ceill und truncl nicht alle in eine Funktion mit einem Parameter fuer den Rundungsmodus packen, von mir aus auch static inline? > + return res; > +} > + > +double ceil(double x) > +{ > + return ceill(x); > +} > + > +float ceilf(float x) > +{ > + return ceill(x); > +} > + > +long double truncl(long double x) > +{ > + long double res; > + uint16_t control_word; > + > + asm( > + // Rundungsmodus setzen > + "fnstcw %2;" > + "mov %2, %%eax;" > + "orl " ROUND_TRUNC ", %2;" > + "fldcw %2;" > + > + // Zahl auf dem Stack runden > + "frndint;" > + > + // Wieder den Standardrundungsmodus setzen > + "mov %%eax, %2;" > + "fldcw %2;" > + : "=t" (res) : "0" (x), "m" (control_word) : "eax"); > + > + return res; > +} > + > +double trunc(double x) > +{ > + return truncl(x); > +} > + > +float truncf(float x) > +{ > + return truncl(x); > +} > + > +long double roundl(long double x) > +{ > + long double res; > + > + asm("frndint" : "=t" (res) : "0" (x)); > + > + return res; > +} > + > +double round(double x) > +{ > + return roundl(x); > +} > + > +float roundf(float x) > +{ > + return roundl(x); > +} > + > +long double nearbyintl(long double x) > +{ > + switch (rounding_mode) { > + case FE_TONEAREST: > + return roundl(x); > + case FE_TOWARDZERO: > + return truncl(x); > + case FE_DOWNWARD: > + return floorl(x); > + case FE_UPWARD: > + return ceill(x); > + } > + > + abort(); > + return x; > +} > + > +double nearbyint(double x) > +{ > + return nearbyintl(x); > +} > + > +float nearbyintf(float x) > +{ > + return nearbyintl(x); > +} > + > +int fegetround(void) > +{ > + return rounding_mode; > +} > + > +int fesetround(int mode) > +{ > + switch(mode) { > + case FE_TONEAREST: > + case FE_TOWARDZERO: > + case FE_DOWNWARD: > + case FE_UPWARD: > + rounding_mode = mode; > + return 0; > + > + default: > + return -1; > + } > +} > -- > 1.6.0.2 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sun Aug 16 22:22:06 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:06 +0200 Subject: [tyndur-devel] [PATCH 0/6] POSIX fuer coreutils Message-ID: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Eine Patchserie, die coreutils ein wenig kompilierbarer macht. Kevin Wolf (6): libc: MIN/MAX-Makros fuer stdint.h libc: POSIX: gethostname() nicht static inline libc: Mehr Konstanten libc: POSIX: fcntl libc: POSIX: getpagesize() libc: POSIX: waitpid mit WNOHANG src/include/arch/i386/stdint.h | 87 +++++++++++++++++++++++++++++++++++ src/include/errno.h | 5 ++ src/modules/include/fcntl.h | 20 ++++++++- src/modules/include/sys/socket.h | 6 ++ src/modules/include/sys/wait.h | 2 + src/modules/include/unistd.h | 10 ++-- src/modules/lib/posix/misc.c | 20 ++++++++ src/modules/lib/posix/posix_files.c | 83 +++++++++++++++++++++++++++++++++- src/modules/lib/posix/wait.c | 10 +++- 9 files changed, 233 insertions(+), 10 deletions(-) From kevin at tyndur.org Sun Aug 16 22:22:07 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:07 +0200 Subject: [tyndur-devel] [PATCH 1/6] libc: MIN/MAX-Makros fuer stdint.h In-Reply-To: <1250454132-11413-1-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Message-ID: <1250454132-11413-2-git-send-email-kevin@tyndur.org> + libc: MIN/MAX-Makros fuer alle moeglichen Integer-Datentypen, die es in stdint.h geben sollte + libc: (U)INTxx_C-Markos fuer Integerkonstanten Signed-off-by: Kevin Wolf --- src/include/arch/i386/stdint.h | 87 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-) diff --git a/src/include/arch/i386/stdint.h b/src/include/arch/i386/stdint.h index 4f94b39..9262887 100644 --- a/src/include/arch/i386/stdint.h +++ b/src/include/arch/i386/stdint.h @@ -29,6 +29,24 @@ #ifndef _STDINT_H_ #define _STDINT_H_ +#include + +#define INT8_MIN -128 +#define INT8_MAX 127 +#define UINT8_MAX 255 + +#define INT16_MIN -32768 +#define INT16_MAX 32767 +#define UINT16_MAX 65535 + +#define INT32_MIN ((int32_t) -0x80000000) +#define INT32_MAX 0x7FFFFFFF +#define UINT32_MAX ((uint32_t) -1) + +#define INT64_MIN ((int64_t) -0x8000000000000000LL) +#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL +#define UINT64_MAX ((uint64_t) -1ULL) + typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; @@ -40,6 +58,22 @@ typedef unsigned int uint32_t; typedef unsigned long long uint64_t; +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#define INT_LEAST16_MIN INT32_MIN +#define INT_LEAST16_MAX INT32_MAX +#define UINT_LEAST16_MAX UINT32_MAX + +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST64_MAX UINT64_MAX + typedef int8_t int_least8_t; typedef int32_t int_least16_t; typedef int32_t int_least32_t; @@ -51,6 +85,22 @@ typedef uint32_t uint_least32_t; typedef uint64_t uint_least64_t; +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST8_MAX INT8_MAX +#define UINT_FAST8_MAX UINT8_MAX + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST16_MAX INT32_MAX +#define UINT_FAST16_MAX UINT32_MAX + +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST64_MAX UINT64_MAX + typedef int8_t int_fast8_t; typedef int32_t int_fast16_t; typedef int32_t int_fast32_t; @@ -62,10 +112,47 @@ typedef uint32_t uint_fast32_t; typedef uint64_t uint_fast64_t; +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + typedef unsigned int uintptr_t; typedef long int intptr_t; typedef int64_t intmax_t; typedef uint64_t uintmax_t; +/* MIN/MAX fuer Typen aus anderen Headern */ + +#define PTRDIFF_MIN INT_MIN +#define PTRDIFF_MAX INT_MAX + +#define WCHAR_MIN INT32_MIN +#define WCHAR_MAX INT32_MAX + +#define WINT_MIN WCHAR_MIN +#define WINT_MAX WCHAR_MAX + +#define SIG_ATOMIC_MIN 0 +#define SIG_ATOMIC_MAX UINT32_MAX + +#define SIZE_MAX ((__SIZE_TYPE__) -1) + + +/* Makros fuer Integerkonstanten */ + +#define INT8_C(x) ((int_least8_t) x) +#define INT16_C(x) ((int_least16_t) x) +#define INT32_C(x) ((int_least32_t) x) +#define INT64_C(x) ((int_least64_t) x ## LL) + +#define UINT8_C(x) ((uint_least8_t) x) +#define UINT16_C(x) ((uint_least16_t) x) +#define UINT32_C(x) ((uint_least32_t) x) +#define UINT64_C(x) ((uint_least64_t) x ## ULL) + #endif -- 1.6.0.2 From kevin at tyndur.org Sun Aug 16 22:22:08 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:08 +0200 Subject: [tyndur-devel] [PATCH 2/6] libc: POSIX: gethostname() nicht static inline In-Reply-To: <1250454132-11413-1-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Message-ID: <1250454132-11413-3-git-send-email-kevin@tyndur.org> ! libc: Es wird erwartet, dass man gegen gethostname auch tatsaechlich linken kann, ohne den Header einzubinden. Ein Hoch auf configure. Signed-off-by: Kevin Wolf --- src/modules/include/unistd.h | 7 +------ src/modules/lib/posix/misc.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index cc62037..cf74c31 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -164,12 +164,7 @@ gid_t getgid(void); gid_t getegid(void); /// Gibt den Hostnamen dieses Rechners zurueck -#include -static inline int gethostname(char* buf, size_t len) -{ - strncpy(buf, "tyndur", len); - return 0; -} +int gethostname(char* buf, size_t len); #endif diff --git a/src/modules/lib/posix/misc.c b/src/modules/lib/posix/misc.c index 457b31c..5ed21ad 100644 --- a/src/modules/lib/posix/misc.c +++ b/src/modules/lib/posix/misc.c @@ -29,6 +29,7 @@ #include #include #include +#include #ifndef CONFIG_LIBC_NO_STUBS /** @@ -56,5 +57,15 @@ int pipe(int mode[2]) errno = ENFILE; return -1; } + +/** + * Gibt den Hostnamen dieses Rechners zurueck + */ +int gethostname(char* buf, size_t len) +{ + strncpy(buf, "tyndur", len); + return 0; +} + #endif -- 1.6.0.2 From kevin at tyndur.org Sun Aug 16 22:22:09 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:09 +0200 Subject: [tyndur-devel] [PATCH 3/6] libc: Mehr Konstanten In-Reply-To: <1250454132-11413-1-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Message-ID: <1250454132-11413-4-git-send-email-kevin@tyndur.org> + libc: errno.h: Mehr Fehlerkonstanten + libc: POSIX: SOCK_DGRAM und SOCK_RAW Signed-off-by: Kevin Wolf --- src/include/errno.h | 5 +++++ src/modules/include/sys/socket.h | 6 ++++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/src/include/errno.h b/src/include/errno.h index 5067ea4..14c3722 100644 --- a/src/include/errno.h +++ b/src/include/errno.h @@ -76,6 +76,11 @@ #define EFBIG 42 #define EDEADLK 43 #define EADDRNOTAVAIL 44 +#define ENOSYS 45 +#define ENAMETOOLONG 46 +#define ESPIPE 47 +#define EMLINK 48 +#define ENOTEMPTY 49 extern int errno; diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index 44abb40..90c7e15 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -58,6 +58,12 @@ struct sockaddr_storage { enum { /// Verbindungsoriertierter Socket (z.B. TCP) SOCK_STREAM, + + /// Datagramm-Socket (z.B. UDP) + SOCK_DGRAM, + + /// Rohdaten (direkt IP-Pakete) + SOCK_RAW, }; /// Adressfamilien -- 1.6.0.2 From kevin at tyndur.org Sun Aug 16 22:22:10 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:10 +0200 Subject: [tyndur-devel] [PATCH 4/6] libc: POSIX: fcntl In-Reply-To: <1250454132-11413-1-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Message-ID: <1250454132-11413-5-git-send-email-kevin@tyndur.org> + libc: POSIX: Ungefaehr ganz genau jedes Programm braucht diese Funktion, implementieren wir halt mal irgendwas, was so aehnlich aussieht. Flags, die gesetzt werden, koennen wieder abgeholt werden, aber haben ansonsten keine Auswirkungen. - libc: O_BINARY ist kein POSIX, wir unterscheiden nicht zwischen Text- und Binaerdateien und das Gegenstueck O_TEXT fehlt auch. Signed-off-by: Kevin Wolf --- src/modules/include/fcntl.h | 20 ++++++++- src/modules/lib/posix/posix_files.c | 83 ++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/modules/include/fcntl.h b/src/modules/include/fcntl.h index dee23f5..f8211ab 100644 --- a/src/modules/include/fcntl.h +++ b/src/modules/include/fcntl.h @@ -36,7 +36,22 @@ #define O_CREAT 16 #define O_EXCL 32 #define O_TRUNC 64 -#define O_BINARY 128 + +#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) + +enum { + /// Liest die Flags des Filedeskriptors + F_GETFD, + + /// Setzt die Flags ds Filedeskriptors + F_SETFD, + + /// Liest die Flags einer Datei + F_GETFL, + + /// Setzt die Flags einer Datei + F_SETFL, +}; /// Emulierter Unix-Syscall zum oeffnen von Dateien int open(const char* filename, int flags, ...); @@ -44,5 +59,8 @@ int open(const char* filename, int flags, ...); /// Emulierter Unix-Syscall zum erstellen von Dateien int creat(const char *pathname, mode_t mode); +/// Fuehrt unterschiedliche Aktionen (F_*) auf Dateien aus +int fcntl(int fd, int cmd, ...); + #endif //ifndef _FCNTL_H_ diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c index d8c17e6..4c1cf90 100644 --- a/src/modules/lib/posix/posix_files.c +++ b/src/modules/lib/posix/posix_files.c @@ -38,6 +38,9 @@ struct fd_list_element { FILE* io_res; int fd; + + int fd_flags; + int file_flags; }; /// Liste mit den Dateideskriptoren @@ -104,6 +107,8 @@ int fileno(FILE* io_res) fdl_element->io_res = io_res; fdl_element->fd = next_fd++; + fdl_element->fd_flags = 0; + fdl_element->file_flags = 0; } return fdl_element->fd; @@ -149,6 +154,77 @@ FILE* fdopen(int fd, const char* mode) } /** + * Fuehrt unterschiedliche Aktionen (F_*) auf Dateien aus + */ +int fcntl(int fd, int cmd, ...) +{ + // Liste mit den Dateideskriptoren durchsuchen + struct fd_list_element* fdl_element = NULL; + int i = 0; + while ((fdl_element = list_get_element_at(fd_list, i))) { + if (fdl_element->fd == fd) { + break; + } + i++; + } + + if (fdl_element == NULL) { + errno = EBADF; + return -1; + } + + // Aktion durchfuehren + switch (cmd) { + case F_GETFD: + return fdl_element->fd_flags; + + case F_GETFL: + return fdl_element->file_flags; + + case F_SETFD: + { + va_list ap; + int arg; + + va_start(ap, cmd); + arg = va_arg(ap, int); + va_end(ap); + + if (arg != fdl_element->fd_flags) { + fprintf(stderr, "Warnung: S_SETFD ändert Flags (%#x => %#x) " + "ohne Effekt\n", fdl_element->fd_flags, arg); + } + + fdl_element->fd_flags = arg; + return 0; + } + + case F_SETFL: + { + va_list ap; + int arg; + + va_start(ap, cmd); + arg = va_arg(ap, int); + va_end(ap); + + // Wenn die Flags bisher 0 sind, ist es open, das aendert. In + // diesem Fall wollen wir keine Warnung. + if ((arg != fdl_element->file_flags) && fdl_element->file_flags) { + fprintf(stderr, "Warnung: S_SETFL ändert Flags (%#x => %#x) " + "ohne Effekt\n", fdl_element->file_flags, arg); + } + + fdl_element->file_flags = arg; + return 0; + } + } + + errno = EINVAL; + return -1; +} + +/** * Eine Datei als Unix-Dateideskriptor oeffnen * * @param filename Dateiname @@ -161,6 +237,7 @@ int open(const char* filename, int flags, ...) { char fopen_flags[4]; size_t flags_size = 0; + int fd; // Wenn O_CREAT und O_EXCL gleichzeitig gesetzt ist, muessen wir abbrechen // wenn die Datei existiert. @@ -217,7 +294,11 @@ int open(const char* filename, int flags, ...) errno = ENOENT; return -1; } - return fileno(file); + + fd = fileno(file); + fcntl(fd, F_SETFL, flags); + + return fd; } /** -- 1.6.0.2 From kevin at tyndur.org Sun Aug 16 22:22:11 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:11 +0200 Subject: [tyndur-devel] [PATCH 5/6] libc: POSIX: getpagesize() In-Reply-To: <1250454132-11413-1-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Message-ID: <1250454132-11413-6-git-send-email-kevin@tyndur.org> + libc: POSIX: getpagesize() Signed-off-by: Kevin Wolf --- src/modules/include/unistd.h | 3 +++ src/modules/lib/posix/misc.c | 9 +++++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index cf74c31..97999ac 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -119,6 +119,9 @@ ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); /// Timer setzen nach dem ein SIGALARM gesendet werden soll long alarm(long seconds); +/// Gibt die Groesse einer Page zurueck +int getpagesize(void); + #ifndef CONFIG_LIBC_NO_STUBS /// Prozess klonen pid_t fork(void); diff --git a/src/modules/lib/posix/misc.c b/src/modules/lib/posix/misc.c index 5ed21ad..4a8496c 100644 --- a/src/modules/lib/posix/misc.c +++ b/src/modules/lib/posix/misc.c @@ -30,6 +30,15 @@ #include #include #include +#include + +/** + * Gibt die Groesse einer Page zurueck + */ +int getpagesize(void) +{ + return PAGE_SIZE; +} #ifndef CONFIG_LIBC_NO_STUBS /** -- 1.6.0.2 From kevin at tyndur.org Sun Aug 16 22:22:12 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 16 Aug 2009 22:22:12 +0200 Subject: [tyndur-devel] [PATCH 6/6] libc: POSIX: waitpid mit WNOHANG In-Reply-To: <1250454132-11413-1-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> Message-ID: <1250454132-11413-7-git-send-email-kevin@tyndur.org> + libc: POSIX: WNOHANG fuer wait implementiert + libc: Warnung bei waitpid mit pid = -1 ausgeben (ist nicht implementiert) Signed-off-by: Kevin Wolf --- src/modules/include/sys/wait.h | 2 ++ src/modules/lib/posix/wait.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/include/sys/wait.h b/src/modules/include/sys/wait.h index 2a8a914..7831650 100644 --- a/src/modules/include/sys/wait.h +++ b/src/modules/include/sys/wait.h @@ -35,6 +35,8 @@ #define WEXITSTATUS(status) (status) +#define WNOHANG 1 + pid_t wait(int* status); pid_t waitpid(pid_t pid, int* status, int options); diff --git a/src/modules/lib/posix/wait.c b/src/modules/lib/posix/wait.c index 13521a0..be562eb 100644 --- a/src/modules/lib/posix/wait.c +++ b/src/modules/lib/posix/wait.c @@ -33,6 +33,7 @@ #include #include #include +#include struct wait_child { pid_t pid; @@ -159,8 +160,12 @@ pid_t waitpid(pid_t pid, int* status, int options) } // Warten bis der Prozess terminiert - while (wait_child->running && (get_parent_pid(pid) != 0)) { - yield(); + if ((options & WNOHANG) == 0) { + while (wait_child->running && (get_parent_pid(pid) != 0)) { + yield(); + } + } else if (wait_child->running) { + return 0; } if (status != NULL) { @@ -170,6 +175,7 @@ pid_t waitpid(pid_t pid, int* status, int options) return pid; } else { // Irgend ein Prozess (FIXME) + printf("waitpid(-1)\n"); errno = ECHILD; return -1; } -- 1.6.0.2 From hartmut at tyndur.org Mon Aug 17 02:50:03 2009 From: hartmut at tyndur.org (hartmut at tyndur.org) Date: Mon, 17 Aug 2009 02:50:03 +0200 Subject: [tyndur-devel] [PATCH] libc: wctype_t, iswctype, btowc Message-ID: <1250470203-23625-1-git-send-email-hartmut@tyndur.org> From: Alexander Hartmut Kluth wctype_t und Konsorten implementiert + Typ wctype_t hinzugefuegt + Funktion iswctype hinzugefuegt + Funktion btowc als Stub hinzugefuegt Signed-off-by: Alexander Hartmut Kluth --- src/include/wctype.h | 7 +++ src/modules/include/wchar.h | 7 +++ src/modules/lib/stdlibc/wctype.c | 77 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 0 deletions(-) diff --git a/src/include/wctype.h b/src/include/wctype.h index f273a71..30e47c6 100644 --- a/src/include/wctype.h +++ b/src/include/wctype.h @@ -120,6 +120,12 @@ int iswprint(wint_t wc); int iswcntrl(wint_t wc); +int iswgraph(wint_t c); + + +int iswxdigit(wint_t c); + + /** * Breites Zeichen in einen Grossbuchstaben umwandeln, falls es sich um einen * Kleinbuchstaben handelt. Sonst wird das Zeichen unveraendert zurueckgegeben. @@ -139,5 +145,6 @@ wint_t towupper(wint_t wc); */ wint_t towlower(wint_t wc); + #endif /* ndef WCTYPE_H */ diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h index 3870f9d..d39c632 100644 --- a/src/modules/include/wchar.h +++ b/src/modules/include/wchar.h @@ -40,6 +40,13 @@ */ typedef wchar_t wint_t; + +/** + * wctype_t ist ein Funktionspointer + */ +typedef int (*wctype_t)(wint_t); + + /** * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir mit * UTF-8 nicht. diff --git a/src/modules/lib/stdlibc/wctype.c b/src/modules/lib/stdlibc/wctype.c index b3c174c..b3c689c 100644 --- a/src/modules/lib/stdlibc/wctype.c +++ b/src/modules/lib/stdlibc/wctype.c @@ -27,6 +27,81 @@ */ #include +#include + + +struct { const char* name; wctype_t func; } types[] = { + { "alnum", iswalnum }, + { "alpha", iswalpha }, + { "blank", iswblank }, + { "cntrl", iswcntrl }, + { "digit", iswdigit }, + { "graph", iswgraph }, + { "lower", iswlower }, + { "print", iswprint }, + { "punct", iswpunct }, + { "space", iswspace }, + { "upper", iswupper }, + { "xdigit", iswxdigit }, +}; + + +/** + * Erstellt ein wctype-Objekt + * + * @param type Typ des zu erstellenden Objekts + * + * @return Das Objekt, ansonsten (wctype_t)0 + */ +wctype_t wctype(const char* name) +{ + int i; + + for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) + { + if (!strcmp(name,types[i].name)) { + return types[i].func; + } + } + + return (wctype_t)0; +} + + +/** + * Prüft, ob der als Parameter übergebene Typ auch vom Typ + * wctype_t ist + * + * @param wc Übergebener Typ + * @param type Typklasse + * + * @return 0, wenn die Klasse nicht vorhanden ist, ansonsten den + * Funktionspointer + */ +int iswctype(wint_t wc, wctype_t type) +{ + return type(wc); +} + + +/// TODO +wint_t btowc(wint_t c) +{ + return 0; +} + + +int iswgraph(wint_t c) +{ + return 0; +} + + +int iswxdigit(wint_t c) +{ + return 0; +} + /** * Testet ob es sich bei einem breiten Zeichen um ein grosses alphabetisches @@ -170,3 +245,5 @@ wint_t towlower(wint_t wc) return iswupper(wc) ? wc + (L'a' - L'A') : wc; } + + -- 1.6.0.4 From matthew at theiselins.net Mon Aug 17 12:31:44 2009 From: matthew at theiselins.net (Matthew Iselin) Date: Mon, 17 Aug 2009 20:31:44 +1000 Subject: [tyndur-devel] [PATCH] CDI CMOS code added, floppy driver updated accordingly Message-ID: <1250505104-5765-1-git-send-email-matthew@theiselins.net> From: Matthew Iselin Signed-off-by: Matthew Iselin --- src/modules/cdi/floppy/device.c | 24 +++++++++++++++++----- src/modules/cdi/include/cdi/cmos.h | 38 ++++++++++++++++++++++++++++++++++++ src/modules/cdi/lib/cmos.c | 31 +++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/modules/cdi/floppy/device.c create mode 100755 src/modules/cdi/include/cdi/cmos.h create mode 100644 src/modules/cdi/lib/cmos.c diff --git a/src/modules/cdi/floppy/device.c b/src/modules/cdi/floppy/device.c old mode 100644 new mode 100755 index c88a875..de66090 --- a/src/modules/cdi/floppy/device.c +++ b/src/modules/cdi/floppy/device.c @@ -34,6 +34,7 @@ #include "cdi/misc.h" #include "cdi/io.h" #include "cdi/dma.h" +#include "cdi/cmos.h" #include "device.h" @@ -473,7 +474,7 @@ static int floppy_drive_sector_read(struct floppy_device* device, uint32_t lba, uint8_t sector; uint8_t cylinder; uint8_t head; - uint8_t status; + uint8_t status = 0; uint8_t data; struct cdi_dma_handle dma_handle; @@ -540,7 +541,7 @@ static int floppy_drive_sector_read(struct floppy_device* device, uint32_t lba, // IRQ bestaetigen floppy_drive_int_sense(device); floppy_reset_irqcnt(device); - floppy_read_data(device, buffer + bytes_done++); + floppy_read_data(device, (uint8_t*) buffer + bytes_done++); } } @@ -600,7 +601,7 @@ static int floppy_drive_sector_write(struct floppy_device* device, uint32_t lba, uint8_t sector; uint8_t cylinder; uint8_t head; - uint8_t status; + uint8_t status = 0; uint8_t data; struct cdi_dma_handle dma_handle; @@ -701,7 +702,18 @@ static int floppy_drive_sector_write(struct floppy_device* device, uint32_t lba, */ int floppy_device_probe(struct floppy_device* device) { - return 1; + // Read floppy presence from CMOS + uint8_t t = cdi_cmos_read(0x10); + + // Each nibble contains information about the device type + if(device->id == 0) { + return (t >> 4); + } + else if(device->id == 1){ + return (t & 0xF); + } + + return 0; } /** @@ -818,7 +830,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert for (j = 0; (j < 5) && (result != 0); j++) { result = floppy_drive_sector_read(device, (uint32_t) block + i, - buffer + i * dev->block_size); + (char*) buffer + i * dev->block_size); } } @@ -843,7 +855,7 @@ int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert for (j = 0; (j < 5) && (result != 0); j++) { result = floppy_drive_sector_write(device, (uint32_t) block + i, - buffer + i * dev->block_size); + (char*) buffer + i * dev->block_size); } } diff --git a/src/modules/cdi/include/cdi/cmos.h b/src/modules/cdi/include/cdi/cmos.h new file mode 100755 index 0000000..c16547c --- /dev/null +++ b/src/modules/cdi/include/cdi/cmos.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008 Matthew Iselin + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef _CDI_CMOS_H_ +#define _CDI_CMOS_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Performs CMOS reads + * @param index Index within CMOS RAM to read from. + * @return Result of reading CMOS RAM at specified index. + */ +uint8_t cdi_cmos_read(uint8_t index); + +/** + * Performs CMOS writes + * @param index Index within CMOS RAM to write to. + * @param value Value to write to the CMOS + */ +void cdi_cmos_write(uint8_t index, uint8_t value); + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif diff --git a/src/modules/cdi/lib/cmos.c b/src/modules/cdi/lib/cmos.c new file mode 100644 index 0000000..eee3fad --- /dev/null +++ b/src/modules/cdi/lib/cmos.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008 Matthew Iselin + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include + +/** + * Performs CMOS reads + * @param index Index within CMOS RAM to read from. + * @return Result of reading CMOS RAM at specified index. + */ +uint8_t cdi_cmos_read(uint8_t index) { + return 0; +} + +/** + * Performs CMOS writes + * @param index Index within CMOS RAM to write to. + * @param value Value to write to the CMOS + */ +void cdi_cmos_write(uint8_t index, uint8_t value) { +} + -- 1.5.6.3 From kevin at tyndur.org Mon Aug 17 20:06:47 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 17 Aug 2009 20:06:47 +0200 Subject: [tyndur-devel] [PATCH] libc: wctype_t, iswctype, btowc In-Reply-To: <1250470203-23625-1-git-send-email-hartmut@tyndur.org> References: <1250470203-23625-1-git-send-email-hartmut@tyndur.org> Message-ID: <20090817180647.GA4368@silvanus> On Mon, Aug 17, 2009 at 02:50:03AM +0200, hartmut at tyndur.org wrote: > From: Alexander Hartmut Kluth > > wctype_t und Konsorten implementiert > > + Typ wctype_t hinzugefuegt > + Funktion iswctype hinzugefuegt > + Funktion btowc als Stub hinzugefuegt > > Signed-off-by: Alexander Hartmut Kluth > --- > src/include/wctype.h | 7 +++ > src/modules/include/wchar.h | 7 +++ > src/modules/lib/stdlibc/wctype.c | 77 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 91 insertions(+), 0 deletions(-) > > diff --git a/src/include/wctype.h b/src/include/wctype.h > index f273a71..30e47c6 100644 > --- a/src/include/wctype.h > +++ b/src/include/wctype.h > @@ -120,6 +120,12 @@ int iswprint(wint_t wc); > int iswcntrl(wint_t wc); > > > +int iswgraph(wint_t c); > + > + > +int iswxdigit(wint_t c); Ich habe den Eindruck, da fehlen Kommentare. > + > + > /** > * Breites Zeichen in einen Grossbuchstaben umwandeln, falls es sich um einen > * Kleinbuchstaben handelt. Sonst wird das Zeichen unveraendert zurueckgegeben. > @@ -139,5 +145,6 @@ wint_t towupper(wint_t wc); > */ > wint_t towlower(wint_t wc); > > + > #endif /* ndef WCTYPE_H */ > Eine zusätzliche Leerzeile ist besonders nützlich ;-) > diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h > index 3870f9d..d39c632 100644 > --- a/src/modules/include/wchar.h > +++ b/src/modules/include/wchar.h > @@ -40,6 +40,13 @@ > */ > typedef wchar_t wint_t; > > + > +/** > + * wctype_t ist ein Funktionspointer Das sehe ich. Aber wofür benutzt man diesen Typ? > + */ > +typedef int (*wctype_t)(wint_t); > + > + > /** > * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir mit > * UTF-8 nicht. > diff --git a/src/modules/lib/stdlibc/wctype.c b/src/modules/lib/stdlibc/wctype.c > index b3c174c..b3c689c 100644 > --- a/src/modules/lib/stdlibc/wctype.c > +++ b/src/modules/lib/stdlibc/wctype.c > @@ -27,6 +27,81 @@ > */ > > #include > +#include > + > + > +struct { const char* name; wctype_t func; } types[] = { > + { "alnum", iswalnum }, > + { "alpha", iswalpha }, > + { "blank", iswblank }, > + { "cntrl", iswcntrl }, > + { "digit", iswdigit }, > + { "graph", iswgraph }, > + { "lower", iswlower }, > + { "print", iswprint }, > + { "punct", iswpunct }, > + { "space", iswspace }, > + { "upper", iswupper }, > + { "xdigit", iswxdigit }, > +}; Sollte static sein. > + > + > +/** > + * Erstellt ein wctype-Objekt > + * > + * @param type Typ des zu erstellenden Objekts > + * > + * @return Das Objekt, ansonsten (wctype_t)0 > + */ > +wctype_t wctype(const char* name) > +{ > + int i; > + > + for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) > + { > + if (!strcmp(name,types[i].name)) { > + return types[i].func; > + } > + } > + > + return (wctype_t)0; > +} > + > + > +/** > + * Pr??ft, ob der als Parameter ??bergebene Typ auch vom Typ Irgendwas macht regelmäßig deine Umlaute kaputt. > + * wctype_t ist > + * > + * @param wc ??bergebener Typ > + * @param type Typklasse > + * > + * @return 0, wenn die Klasse nicht vorhanden ist, ansonsten den > + * Funktionspointer > + */ > +int iswctype(wint_t wc, wctype_t type) > +{ > + return type(wc); > +} > + > + > +/// TODO > +wint_t btowc(wint_t c) > +{ > + return 0; > +} Hm, wofür ist die Funktion gut? Sie ist hier als Stub vorhanden, kommt aber nichtmal in der Headerdatei vor. > + > + > +int iswgraph(wint_t c) > +{ > + return 0; > +} > + > + > +int iswxdigit(wint_t c) > +{ > + return 0; > +} > + Ich glaube ja ehrlichgesagt nicht, dass die Funktionen so schwer zu implementieren sind, dass man sie als Stubs lassen muss. Aber wenn sie schon Stubs bleiben, sollten sie in ein #ifndef CONFIG_LIBC_NO_STUBS From kevin at tyndur.org Fri Aug 21 22:06:28 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 21 Aug 2009 22:06:28 +0200 Subject: [tyndur-devel] [PATCH 0/2] Header aufraeumen Message-ID: <1250885190-13041-1-git-send-email-kevin@tyndur.org> string.h wurde bislang in vielen Programmen automatisch eingebunden, ohne dass diese es je verlangt haetten. Das ist eigentlich falsch und verleitet bei neuen Programmen dazu, sie nicht portabel zu schreiben. Kevin Wolf (2): libc: stdlib.h braucht keine string.h libc: stdio.h braucht keine string.h src/include/stdlib.h | 1 - src/kernel/src/io.c | 4 ++- src/kernel/src/task.c | 5 ++- src/lib/collections/tree.c | 1 + src/lib/sort.c | 3 +- src/lib/string/multibyte.c | 1 + src/modules/c/getterm/main.c | 1 + src/modules/c/shell/cmds/bench.c | 1 + src/modules/c/shell/cmds/dbg_st.c | 1 + src/modules/c/shell/cmds/kill.c | 1 + src/modules/c/shell/cmds/pipe.c | 9 +++--- src/modules/c/shell/cmds/sleep.c | 1 + src/modules/c/shell/cmds/symlink.c | 11 ++++--- src/modules/cdi/lib/fs/lostio_if.c | 1 + src/modules/file/client.c | 1 + src/modules/file/server.c | 1 + src/modules/include/stdio.h | 1 - src/modules/init/init.c | 1 + src/modules/kbc/keyboard.c | 1 + src/modules/lib/gui/gui.c | 1 + src/modules/lib/lostio/handler.c | 1 + src/modules/lib/network.c | 1 + src/modules/lib/posix/posix_dir.c | 1 + src/modules/lib/posix/signal.c | 1 + src/modules/lib/posix/socket.c | 1 + src/modules/lib/posix/stat.c | 1 + src/modules/lib/readline.c | 1 + src/modules/lib/stdlibc/exit.c | 1 + src/modules/lib/stdlibc/fprintf.c | 3 +- src/modules/lib/stdlibc/printf.c | 8 +++-- src/modules/lib/stdlibc/time.c | 1 + src/modules/lib/video/bitmap.c | 5 ++- src/modules/lib/video/video.c | 1 + src/modules/pci/pci.c | 1 + src/modules/rpcbench/rpcbench.c | 48 +++++++++++++++++++++++++++++++---- src/modules/servmgr/servio.c | 1 + src/modules/tcpip/checksum.c | 13 +++++---- src/modules/tcpip/ip.c | 1 + src/modules/tcpip/main.c | 1 + src/modules/tcpip/tcp.c | 1 + src/modules/testlib/test_printf.c | 1 + src/modules/testlib/test_tree.c | 1 + src/modules/vterm/lostio.c | 1 + src/modules/vterm/vt100.c | 1 + 44 files changed, 110 insertions(+), 33 deletions(-) From kevin at tyndur.org Fri Aug 21 22:06:29 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 21 Aug 2009 22:06:29 +0200 Subject: [tyndur-devel] [PATCH 1/2] libc: stdlib.h braucht keine string.h In-Reply-To: <1250885190-13041-1-git-send-email-kevin@tyndur.org> References: <1250885190-13041-1-git-send-email-kevin@tyndur.org> Message-ID: <1250885190-13041-2-git-send-email-kevin@tyndur.org> ! libc: Es gibt keinen Grund, warum stdlib.h ausgerechnet string.h includen sollte. Signed-off-by: Kevin Wolf --- src/include/stdlib.h | 1 - src/kernel/src/io.c | 4 +++- src/kernel/src/task.c | 5 +++-- src/lib/collections/tree.c | 1 + src/lib/sort.c | 3 ++- src/lib/string/multibyte.c | 1 + src/modules/lib/video/bitmap.c | 5 +++-- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 3abf331..f5f446e 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -30,7 +30,6 @@ #define _STDLIB_H_ #include -#include "string.h" #include #define EXIT_SUCCESS 0 diff --git a/src/kernel/src/io.c b/src/kernel/src/io.c index e655491..c46bfef 100644 --- a/src/kernel/src/io.c +++ b/src/kernel/src/io.c @@ -33,10 +33,12 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + #include "types.h" #include "tasks.h" #include "tss.h" -#include "stdlib.h" #include "kernel.h" /* Gesetztes Bit: Port wird benutzt */ diff --git a/src/kernel/src/task.c b/src/kernel/src/task.c index a86abab..fce02cd 100644 --- a/src/kernel/src/task.c +++ b/src/kernel/src/task.c @@ -33,8 +33,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "types.h" -#include "stdlib.h" +#include +#include +#include #include "vmm.h" #include "kmm.h" diff --git a/src/lib/collections/tree.c b/src/lib/collections/tree.c index d565fa8..6bb3c63 100644 --- a/src/lib/collections/tree.c +++ b/src/lib/collections/tree.c @@ -28,6 +28,7 @@ #include #include +#include #ifdef DEBUG_TREE #include diff --git a/src/lib/sort.c b/src/lib/sort.c index f882ac9..bb813c4 100644 --- a/src/lib/sort.c +++ b/src/lib/sort.c @@ -26,7 +26,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stdlib.h" +#include +#include void qsort(void *base, size_t num, size_t size, int (*comparator)(const void *, const void *)) { diff --git a/src/lib/string/multibyte.c b/src/lib/string/multibyte.c index a791d5f..ef00f7f 100644 --- a/src/lib/string/multibyte.c +++ b/src/lib/string/multibyte.c @@ -27,6 +27,7 @@ */ #include +#include /** diff --git a/src/modules/lib/video/bitmap.c b/src/modules/lib/video/bitmap.c index 676858e..1471b9c 100644 --- a/src/modules/lib/video/bitmap.c +++ b/src/modules/lib/video/bitmap.c @@ -26,11 +26,12 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + #include "video/bitmap.h" #include "video/color.h" -#include "stdlib.h" - void copy_shifted(byte *dest, byte *src, byte shift, dword length) { //TODO: Kann weiter optimiert werden (größere Datentypen) -- 1.6.0.2 From kevin at tyndur.org Fri Aug 21 22:06:30 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 21 Aug 2009 22:06:30 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: stdio.h braucht keine string.h In-Reply-To: <1250885190-13041-1-git-send-email-kevin@tyndur.org> References: <1250885190-13041-1-git-send-email-kevin@tyndur.org> Message-ID: <1250885190-13041-3-git-send-email-kevin@tyndur.org> ! libc: Genausowenig gibt es einen vernuenftigen Grund, warum stdio.h die string.h nachziehe sollte. Signed-off-by: Kevin Wolf --- src/modules/c/getterm/main.c | 1 + src/modules/c/shell/cmds/bench.c | 1 + src/modules/c/shell/cmds/dbg_st.c | 1 + src/modules/c/shell/cmds/kill.c | 1 + src/modules/c/shell/cmds/pipe.c | 9 +++--- src/modules/c/shell/cmds/sleep.c | 1 + src/modules/c/shell/cmds/symlink.c | 11 ++++--- src/modules/cdi/lib/fs/lostio_if.c | 1 + src/modules/file/client.c | 1 + src/modules/file/server.c | 1 + src/modules/include/stdio.h | 1 - src/modules/init/init.c | 1 + src/modules/kbc/keyboard.c | 1 + src/modules/lib/gui/gui.c | 1 + src/modules/lib/lostio/handler.c | 1 + src/modules/lib/network.c | 1 + src/modules/lib/posix/posix_dir.c | 1 + src/modules/lib/posix/signal.c | 1 + src/modules/lib/posix/socket.c | 1 + src/modules/lib/posix/stat.c | 1 + src/modules/lib/readline.c | 1 + src/modules/lib/stdlibc/exit.c | 1 + src/modules/lib/stdlibc/fprintf.c | 3 +- src/modules/lib/stdlibc/printf.c | 8 +++-- src/modules/lib/stdlibc/time.c | 1 + src/modules/lib/video/video.c | 1 + src/modules/pci/pci.c | 1 + src/modules/rpcbench/rpcbench.c | 48 +++++++++++++++++++++++++++++++---- src/modules/servmgr/servio.c | 1 + src/modules/tcpip/checksum.c | 13 +++++---- src/modules/tcpip/ip.c | 1 + src/modules/tcpip/main.c | 1 + src/modules/tcpip/tcp.c | 1 + src/modules/testlib/test_printf.c | 1 + src/modules/testlib/test_tree.c | 1 + src/modules/vterm/lostio.c | 1 + src/modules/vterm/vt100.c | 1 + 37 files changed, 97 insertions(+), 26 deletions(-) diff --git a/src/modules/c/getterm/main.c b/src/modules/c/getterm/main.c index e8de4af..4218f30 100644 --- a/src/modules/c/getterm/main.c +++ b/src/modules/c/getterm/main.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include diff --git a/src/modules/c/shell/cmds/bench.c b/src/modules/c/shell/cmds/bench.c index 0752dbc..6f134ed 100644 --- a/src/modules/c/shell/cmds/bench.c +++ b/src/modules/c/shell/cmds/bench.c @@ -37,6 +37,7 @@ #include #include #include +#include #define MAX_BLOCK_SIZE 524288 diff --git a/src/modules/c/shell/cmds/dbg_st.c b/src/modules/c/shell/cmds/dbg_st.c index 53e2246..d5ea7ba 100644 --- a/src/modules/c/shell/cmds/dbg_st.c +++ b/src/modules/c/shell/cmds/dbg_st.c @@ -40,6 +40,7 @@ #include #include #include +#include void dbg_st_display_usage(void); diff --git a/src/modules/c/shell/cmds/kill.c b/src/modules/c/shell/cmds/kill.c index 97e5258..48f60d8 100644 --- a/src/modules/c/shell/cmds/kill.c +++ b/src/modules/c/shell/cmds/kill.c @@ -35,6 +35,7 @@ #include #include +#include #include #include diff --git a/src/modules/c/shell/cmds/pipe.c b/src/modules/c/shell/cmds/pipe.c index 4c1162a..698cbf0 100644 --- a/src/modules/c/shell/cmds/pipe.c +++ b/src/modules/c/shell/cmds/pipe.c @@ -33,10 +33,11 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "types.h" -#include "stdlib.h" -#include "stdio.h" -#include "unistd.h" +#include +#include +#include +#include +#include #include void pipe_display_usage(void); diff --git a/src/modules/c/shell/cmds/sleep.c b/src/modules/c/shell/cmds/sleep.c index 7b88141..04087d4 100644 --- a/src/modules/c/shell/cmds/sleep.c +++ b/src/modules/c/shell/cmds/sleep.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include diff --git a/src/modules/c/shell/cmds/symlink.c b/src/modules/c/shell/cmds/symlink.c index 01e40a6..c1dcc43 100644 --- a/src/modules/c/shell/cmds/symlink.c +++ b/src/modules/c/shell/cmds/symlink.c @@ -33,11 +33,12 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "types.h" -#include "stdlib.h" -#include "stdio.h" -#include "unistd.h" -#include "io.h" +#include +#include +#include +#include +#include +#include #include void symlink_display_usage(void); diff --git a/src/modules/cdi/lib/fs/lostio_if.c b/src/modules/cdi/lib/fs/lostio_if.c index 36e3a11..f12881c 100644 --- a/src/modules/cdi/lib/fs/lostio_if.c +++ b/src/modules/cdi/lib/fs/lostio_if.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "cdi/fs.h" diff --git a/src/modules/file/client.c b/src/modules/file/client.c index 26569b4..f15e416 100644 --- a/src/modules/file/client.c +++ b/src/modules/file/client.c @@ -35,6 +35,7 @@ #include #include +#include #include #include diff --git a/src/modules/file/server.c b/src/modules/file/server.c index 1531c0b..2b1e728 100644 --- a/src/modules/file/server.c +++ b/src/modules/file/server.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/src/modules/include/stdio.h b/src/modules/include/stdio.h index ca29d26..b3375f2 100644 --- a/src/modules/include/stdio.h +++ b/src/modules/include/stdio.h @@ -29,7 +29,6 @@ #ifndef _STDIO_H_ #define _STDIO_H_ -#include #include #include #include diff --git a/src/modules/init/init.c b/src/modules/init/init.c index 03d6b98..8a7c30d 100644 --- a/src/modules/init/init.c +++ b/src/modules/init/init.c @@ -40,6 +40,7 @@ #include "collections.h" #include "stdlib.h" #include "stdio.h" +#include #include "elf32.h" #include "elf_common.h" #include "io.h" diff --git a/src/modules/kbc/keyboard.c b/src/modules/kbc/keyboard.c index 62eb658..2303228 100644 --- a/src/modules/kbc/keyboard.c +++ b/src/modules/kbc/keyboard.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/src/modules/lib/gui/gui.c b/src/modules/lib/gui/gui.c index 875454e..7ff6f15 100644 --- a/src/modules/lib/gui/gui.c +++ b/src/modules/lib/gui/gui.c @@ -38,6 +38,7 @@ #include "init.h" #include "stdlib.h" #include +#include FILE *gui_control = 0; int gui_command_data[10]; diff --git a/src/modules/lib/lostio/handler.c b/src/modules/lib/lostio/handler.c index 2f067d7..7f27df9 100644 --- a/src/modules/lib/lostio/handler.c +++ b/src/modules/lib/lostio/handler.c @@ -38,6 +38,7 @@ #include "io.h" #include "stdio.h" #include "stdlib.h" +#include ///Handler zum oeffnen einer Datei diff --git a/src/modules/lib/network.c b/src/modules/lib/network.c index ac32ef4..ec1bee3 100644 --- a/src/modules/lib/network.c +++ b/src/modules/lib/network.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/src/modules/lib/posix/posix_dir.c b/src/modules/lib/posix/posix_dir.c index 5a3f912..5e2cc8e 100644 --- a/src/modules/lib/posix/posix_dir.c +++ b/src/modules/lib/posix/posix_dir.c @@ -30,6 +30,7 @@ #include "dirent.h" #include "stdlib.h" #include "dir.h" +#include /** * Öffnet ein Verzeichnis zum Auslesen der Verzeichniseinträge diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c index ef95739..3f2ad0d 100644 --- a/src/modules/lib/posix/signal.c +++ b/src/modules/lib/posix/signal.c @@ -35,6 +35,7 @@ #include #include #include +#include /// Array mit Pointern auf die Signal-Handler static struct sigaction sigactions[_SIGNO_MAX]; diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c index 0616c2b..462c41c 100644 --- a/src/modules/lib/posix/socket.c +++ b/src/modules/lib/posix/socket.c @@ -33,6 +33,7 @@ #include #include +#include #include #include diff --git a/src/modules/lib/posix/stat.c b/src/modules/lib/posix/stat.c index 9033c76..6a22fe4 100644 --- a/src/modules/lib/posix/stat.c +++ b/src/modules/lib/posix/stat.c @@ -28,6 +28,7 @@ #include #include +#include #include #include diff --git a/src/modules/lib/readline.c b/src/modules/lib/readline.c index 3f3c401..30d7115 100644 --- a/src/modules/lib/readline.c +++ b/src/modules/lib/readline.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/src/modules/lib/stdlibc/exit.c b/src/modules/lib/stdlibc/exit.c index cb1a42b..b5a5396 100644 --- a/src/modules/lib/stdlibc/exit.c +++ b/src/modules/lib/stdlibc/exit.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/modules/lib/stdlibc/fprintf.c b/src/modules/lib/stdlibc/fprintf.c index add857f..85218e0 100644 --- a/src/modules/lib/stdlibc/fprintf.c +++ b/src/modules/lib/stdlibc/fprintf.c @@ -26,7 +26,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stdio.h" +#include +#include #include "jprintf.h" diff --git a/src/modules/lib/stdlibc/printf.c b/src/modules/lib/stdlibc/printf.c index d454d9f..ec36e7f 100644 --- a/src/modules/lib/stdlibc/printf.c +++ b/src/modules/lib/stdlibc/printf.c @@ -26,9 +26,11 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "jprintf.h" -#include "stdio.h" - +#include +#include + +#include "jprintf.h" + extern int putsn(unsigned int, const char* str); int printf_putc(void * arg, char c) diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c index 509ec05..b05933b 100644 --- a/src/modules/lib/stdlibc/time.c +++ b/src/modules/lib/stdlibc/time.c @@ -28,6 +28,7 @@ #include #include +#include #include static struct tm tm; diff --git a/src/modules/lib/video/video.c b/src/modules/lib/video/video.c index a7689a0..0643dd8 100644 --- a/src/modules/lib/video/video.c +++ b/src/modules/lib/video/video.c @@ -34,6 +34,7 @@ #include "stdlib.h" #include "rpc.h" #include +#include #include "init.h" FILE *video_driver_control = 0; diff --git a/src/modules/pci/pci.c b/src/modules/pci/pci.c index 07c5026..75227fe 100644 --- a/src/modules/pci/pci.c +++ b/src/modules/pci/pci.c @@ -35,6 +35,7 @@ #include #include +#include #include "stdio.h" #include "types.h" #include "ports.h" diff --git a/src/modules/rpcbench/rpcbench.c b/src/modules/rpcbench/rpcbench.c index f5a81c1..4251cc9 100644 --- a/src/modules/rpcbench/rpcbench.c +++ b/src/modules/rpcbench/rpcbench.c @@ -1,9 +1,45 @@ -#include "types.h" -#include "syscall.h" -#include "rpc.h" -#include "stdlib.h" -#include "stdio.h" -#include "init.h" +/* + * Copyright (c) 2007 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. + * 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. + */ + +#include +#include +#include + +#include +#include +#include #define BLOCK_SIZE 512 diff --git a/src/modules/servmgr/servio.c b/src/modules/servmgr/servio.c index 55a3c8c..27156ec 100644 --- a/src/modules/servmgr/servio.c +++ b/src/modules/servmgr/servio.c @@ -35,6 +35,7 @@ #include #include +#include #include #include diff --git a/src/modules/tcpip/checksum.c b/src/modules/tcpip/checksum.c index 248cbdc..ded743c 100644 --- a/src/modules/tcpip/checksum.c +++ b/src/modules/tcpip/checksum.c @@ -33,13 +33,14 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "types.h" -#include "syscall.h" -#include "rpc.h" -#include "stdlib.h" -#include "stdio.h" +#include +#include +#include +#include +#include +#include +#include -#include "network.h" #include "ip.h" #include "tcp.h" diff --git a/src/modules/tcpip/ip.c b/src/modules/tcpip/ip.c index 8a1b975..cad9da9 100644 --- a/src/modules/tcpip/ip.c +++ b/src/modules/tcpip/ip.c @@ -38,6 +38,7 @@ #include "rpc.h" #include "stdlib.h" #include "stdio.h" +#include #include "collections.h" #include "network.h" diff --git a/src/modules/tcpip/main.c b/src/modules/tcpip/main.c index 1a99014..d553bb5 100644 --- a/src/modules/tcpip/main.c +++ b/src/modules/tcpip/main.c @@ -34,6 +34,7 @@ */ #include +#include #include "types.h" #include "syscall.h" #include "rpc.h" diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index 79febba..b8a7f0f 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -41,6 +41,7 @@ #include "collections.h" #include "network.h" #include +#include #include "ip.h" #include "tcp.h" diff --git a/src/modules/testlib/test_printf.c b/src/modules/testlib/test_printf.c index 6d3ddfd..b7b4815 100644 --- a/src/modules/testlib/test_printf.c +++ b/src/modules/testlib/test_printf.c @@ -1,4 +1,5 @@ #include "stdio.h" +#include // toter code. tests.c entsprechend modifizieren. void test_printf(void) diff --git a/src/modules/testlib/test_tree.c b/src/modules/testlib/test_tree.c index 085c3cc..9367704 100644 --- a/src/modules/testlib/test_tree.c +++ b/src/modules/testlib/test_tree.c @@ -3,6 +3,7 @@ #include "test.h" #include "collections.h" #include +#include struct tree { struct tree_item titem; diff --git a/src/modules/vterm/lostio.c b/src/modules/vterm/lostio.c index 428d339..a835d6a 100644 --- a/src/modules/vterm/lostio.c +++ b/src/modules/vterm/lostio.c @@ -34,6 +34,7 @@ */ #include #include +#include #include "vterm.h" #include "lostio.h" /// Handler fuer Lesen aus in diff --git a/src/modules/vterm/vt100.c b/src/modules/vterm/vt100.c index 78644a1..e1176a4 100644 --- a/src/modules/vterm/vt100.c +++ b/src/modules/vterm/vt100.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include "vterm.h" -- 1.6.0.2 From toni at tyndur.org Sat Aug 22 11:40:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 22 Aug 2009 11:40:44 +0200 Subject: [tyndur-devel] [PATCH 1/6] libc: MIN/MAX-Makros fuer stdint.h In-Reply-To: <1250454132-11413-2-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> <1250454132-11413-2-git-send-email-kevin@tyndur.org> Message-ID: <20090822094044.GC5363@einstein.kaufmann.lan> On Sun, Aug 16 22:22, Kevin Wolf wrote: > + libc: MIN/MAX-Makros fuer alle moeglichen Integer-Datentypen, die es > in stdint.h geben sollte > + libc: (U)INTxx_C-Markos fuer Integerkonstanten > > Signed-off-by: Kevin Wolf > --- > src/include/arch/i386/stdint.h | 87 ++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 87 insertions(+), 0 deletions(-) > > diff --git a/src/include/arch/i386/stdint.h b/src/include/arch/i386/stdint.h > index 4f94b39..9262887 100644 > --- a/src/include/arch/i386/stdint.h > +++ b/src/include/arch/i386/stdint.h > @@ -29,6 +29,24 @@ > #ifndef _STDINT_H_ > #define _STDINT_H_ > > +#include Hm bist du sicher, dass stdint.h die limits.h reinziehen darf? Ich habe dazu weder im Standard noch in der Manpage was gefunden... > + > +#define INT8_MIN -128 > +#define INT8_MAX 127 > +#define UINT8_MAX 255 > + > +#define INT16_MIN -32768 > +#define INT16_MAX 32767 > +#define UINT16_MAX 65535 > + > +#define INT32_MIN ((int32_t) -0x80000000) > +#define INT32_MAX 0x7FFFFFFF > +#define UINT32_MAX ((uint32_t) -1) > + > +#define INT64_MIN ((int64_t) -0x8000000000000000LL) > +#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL > +#define UINT64_MAX ((uint64_t) -1ULL) > + > typedef signed char int8_t; > typedef signed short int16_t; > typedef signed int int32_t; > @@ -40,6 +58,22 @@ typedef unsigned int uint32_t; > typedef unsigned long long uint64_t; > > > +#define INT_LEAST8_MIN INT8_MIN > +#define INT_LEAST8_MAX INT8_MAX > +#define UINT_LEAST8_MAX UINT8_MAX > + > +#define INT_LEAST16_MIN INT32_MIN > +#define INT_LEAST16_MAX INT32_MAX > +#define UINT_LEAST16_MAX UINT32_MAX > + > +#define INT_LEAST32_MIN INT32_MIN > +#define INT_LEAST32_MAX INT32_MAX > +#define UINT_LEAST32_MAX UINT32_MAX > + > +#define INT_LEAST64_MIN INT64_MIN > +#define INT_LEAST64_MAX INT64_MAX > +#define UINT_LEAST64_MAX UINT64_MAX > + > typedef int8_t int_least8_t; > typedef int32_t int_least16_t; > typedef int32_t int_least32_t; > @@ -51,6 +85,22 @@ typedef uint32_t uint_least32_t; > typedef uint64_t uint_least64_t; > > > +#define INT_FAST8_MIN INT8_MIN > +#define INT_FAST8_MAX INT8_MAX > +#define UINT_FAST8_MAX UINT8_MAX > + > +#define INT_FAST16_MIN INT32_MIN > +#define INT_FAST16_MAX INT32_MAX > +#define UINT_FAST16_MAX UINT32_MAX > + > +#define INT_FAST32_MIN INT32_MIN > +#define INT_FAST32_MAX INT32_MAX > +#define UINT_FAST32_MAX UINT32_MAX > + > +#define INT_FAST64_MIN INT64_MIN > +#define INT_FAST64_MAX INT64_MAX > +#define UINT_FAST64_MAX UINT64_MAX > + > typedef int8_t int_fast8_t; > typedef int32_t int_fast16_t; > typedef int32_t int_fast32_t; > @@ -62,10 +112,47 @@ typedef uint32_t uint_fast32_t; > typedef uint64_t uint_fast64_t; > > > +#define INTPTR_MIN INT32_MIN > +#define INTPTR_MAX INT32_MAX > +#define UINTPTR_MAX UINT32_MAX > + > +#define INTMAX_MIN INT64_MIN > +#define INTMAX_MAX INT64_MAX > +#define UINTMAX_MAX UINT64_MAX > + > typedef unsigned int uintptr_t; > typedef long int intptr_t; > > typedef int64_t intmax_t; > typedef uint64_t uintmax_t; > > +/* MIN/MAX fuer Typen aus anderen Headern */ > + > +#define PTRDIFF_MIN INT_MIN > +#define PTRDIFF_MAX INT_MAX > + > +#define WCHAR_MIN INT32_MIN > +#define WCHAR_MAX INT32_MAX > + > +#define WINT_MIN WCHAR_MIN > +#define WINT_MAX WCHAR_MAX > + > +#define SIG_ATOMIC_MIN 0 > +#define SIG_ATOMIC_MAX UINT32_MAX > + > +#define SIZE_MAX ((__SIZE_TYPE__) -1) > + > + > +/* Makros fuer Integerkonstanten */ > + > +#define INT8_C(x) ((int_least8_t) x) > +#define INT16_C(x) ((int_least16_t) x) > +#define INT32_C(x) ((int_least32_t) x) > +#define INT64_C(x) ((int_least64_t) x ## LL) > + > +#define UINT8_C(x) ((uint_least8_t) x) > +#define UINT16_C(x) ((uint_least16_t) x) > +#define UINT32_C(x) ((uint_least32_t) x) > +#define UINT64_C(x) ((uint_least64_t) x ## ULL) > + > #endif > Ansonsten sieht das gut aus. Wenn das gefixt ist: Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 22 11:41:28 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 22 Aug 2009 11:41:28 +0200 Subject: [tyndur-devel] [PATCH 2/6] libc: POSIX: gethostname() nicht static inline In-Reply-To: <1250454132-11413-3-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> <1250454132-11413-3-git-send-email-kevin@tyndur.org> Message-ID: <20090822094128.GD5363@einstein.kaufmann.lan> On Sun, Aug 16 22:22, Kevin Wolf wrote: > ! libc: Es wird erwartet, dass man gegen gethostname auch tatsaechlich > linken kann, ohne den Header einzubinden. Ein Hoch auf configure. > > Signed-off-by: Kevin Wolf So macht das Spass ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 22 12:15:19 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 22 Aug 2009 12:15:19 +0200 Subject: [tyndur-devel] [PATCH 3/6] libc: Mehr Konstanten In-Reply-To: <1250454132-11413-4-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> <1250454132-11413-4-git-send-email-kevin@tyndur.org> Message-ID: <20090822101519.GE5363@einstein.kaufmann.lan> On Sun, Aug 16 22:22, Kevin Wolf wrote: > + libc: errno.h: Mehr Fehlerkonstanten > + libc: POSIX: SOCK_DGRAM und SOCK_RAW > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 22 13:02:42 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 22 Aug 2009 13:02:42 +0200 Subject: [tyndur-devel] [PATCH 5/6] libc: POSIX: getpagesize() In-Reply-To: <1250454132-11413-6-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> <1250454132-11413-6-git-send-email-kevin@tyndur.org> Message-ID: <20090822110242.GF5363@einstein.kaufmann.lan> On Sun, Aug 16 22:22, Kevin Wolf wrote: > + libc: POSIX: getpagesize() > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Aug 22 13:04:21 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 22 Aug 2009 13:04:21 +0200 Subject: [tyndur-devel] [PATCH 6/6] libc: POSIX: waitpid mit WNOHANG In-Reply-To: <1250454132-11413-7-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> <1250454132-11413-7-git-send-email-kevin@tyndur.org> Message-ID: <20090822110420.GG5363@einstein.kaufmann.lan> On Sun, Aug 16 22:22, Kevin Wolf wrote: > + libc: POSIX: WNOHANG fuer wait implementiert > + libc: Warnung bei waitpid mit pid = -1 ausgeben (ist nicht > implementiert) > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Aug 22 17:03:36 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 22 Aug 2009 17:03:36 +0200 Subject: [tyndur-devel] [PATCH] doc: uncrustify-Konfigurationsdatei Message-ID: <1250953416-15642-1-git-send-email-kevin@tyndur.org> + doc: Ein Versuch, den tyndur-Codestil als Konfigurationsdatei fuer uncrustify abzubilden. Vermutlich an manchen Stellen noch nicht ganz korrekt. Signed-off-by: Kevin Wolf --- doc/tyndur.cfg | 1218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 1218 insertions(+), 0 deletions(-) create mode 100644 doc/tyndur.cfg diff --git a/doc/tyndur.cfg b/doc/tyndur.cfg new file mode 100644 index 0000000..1eca5cc --- /dev/null +++ b/doc/tyndur.cfg @@ -0,0 +1,1218 @@ +# Uncrustify 0.53 + +# +# General options +# + +# The type of line endings +newlines = lf # auto/lf/crlf/cr + +# The original size of tabs in the input +input_tab_size = 4 # number + +# The size of tabs in the output (only used if align_with_tabs=true) +output_tab_size = 4 # number + +# The ascii value of the string escape char, usually 92 (\) or 94 (^). (Pawn) +string_escape_char = 92 # number + +# Alternate string escape char for Pawn. Only works right before the quote char. +string_escape_char2 = 0 # number + +# +# Indenting +# + +# The number of columns to indent per level. +# Usually 2, 3, 4, or 8. +indent_columns = 4 # number + +# How to use tabs when indenting code +# 0=spaces only +# 1=indent with tabs, align with spaces +# 2=indent and align with tabs +indent_with_tabs = 0 # number + +# Whether to indent strings broken by '\' so that they line up +indent_align_string = false # false/true + +# The number of spaces to indent multi-line XML strings. +# Requires indent_align_string=True +indent_xml_string = 0 # number + +# Spaces to indent '{' from level +indent_brace = 0 # number + +# Whether braces are indented to the body level +indent_braces = false # false/true + +# Disabled indenting function braces if indent_braces is true +indent_braces_no_func = false # false/true + +# Indent based on the size of the brace parent, ie 'if' => 3 spaces, 'for' => 4 spaces, etc. +indent_brace_parent = false # false/true + +# Whether the 'namespace' body is indented +indent_namespace = false # false/true + +# Whether the 'extern "C"' body is indented +indent_extern = false # false/true + +# Whether the 'class' body is indented +indent_class = false # false/true + +# Whether to indent the stuff after a leading class colon +indent_class_colon = false # false/true + +# False=treat 'else\nif' as 'else if' for indenting purposes +# True=indent the 'if' one level +indent_else_if = true # false/true + +# Amount to indent variable declarations after a open brace. neg=relative, pos=absolute +indent_var_def_blk = 0 # number + +# True: indent continued function call parameters one indent level +# False: align parameters under the open paren +indent_func_call_param = true # false/true + +# Same as indent_func_call_param, but for function defs +indent_func_def_param = true # false/true + +# Same as indent_func_call_param, but for function protos +indent_func_proto_param = true # false/true + +# Same as indent_func_call_param, but for class declarations +indent_func_class_param = true # false/true + +# Same as indent_func_call_param, but for class variable constructors +indent_func_ctor_var_param = true # false/true + +# Same as indent_func_call_param, but for templates +indent_template_param = true # false/true + +# Double the indent for indent_func_xxx_param options +indent_func_param_double = false # false/true + +# Indentation column for standalone 'const' function decl/proto qualifier +indent_func_const = 0 # number + +# Indentation column for standalone 'throw' function decl/proto qualifier +indent_func_throw = 0 # number + +# The number of spaces to indent a continued '->' or '.' +# Usually set to 0, 1, or indent_columns. +indent_member = 0 # number + +# Spaces to indent single line ('//') comments on lines before code +indent_sing_line_comments = 0 # number + +# If set, will indent trailing single line ('//') comments relative +# to the code instead of trying to keep the same absolute column +indent_relative_single_line_comments = true # false/true + +# Spaces to indent 'case' from 'switch' +# Usually 0 or indent_columns. +indent_switch_case = 4 # number + +# Spaces to shift the 'case' line, without affecting any other lines +# Usually 0. +indent_case_shift = 0 # number + +# Spaces to indent '{' from 'case'. +# By default, the brace will appear under the 'c' in case. +# Usually set to 0 or indent_columns. +indent_case_brace = 0 # number + +# Whether to indent comments found in first column +indent_col1_comment = false # false/true + +# How to indent goto labels +# >0 : absolute column where 1 is the leftmost column +# <=0 : subtract from brace indent +indent_label = -4 # number + +# Same as indent_label, but for access specifiers that are followed by a colon +indent_access_spec = 0 # number + +# Indent the code after an access specifier by one level. +# If set, this option forces 'indent_access_spec=0' +indent_access_spec_body = true # false/true + +# If an open paren is followed by a newline, indent the next line so that it lines up after the open paren (not recommended) +indent_paren_nl = false # false/true + +# Controls the indent of a close paren after a newline. +# 0: Indent to body level +# 1: Align under the open paren +# 2: Indent to the brace level +indent_paren_close = 2 # number + +# Controls the indent of a comma when inside a paren.If TRUE, aligns under the open paren +indent_comma_paren = false # false/true + +# Controls the indent of a BOOL operator when inside a paren.If TRUE, aligns under the open paren +indent_bool_paren = false # false/true + +# If an open square is followed by a newline, indent the next line so that it lines up after the open square (not recommended) +indent_square_nl = false # false/true + +# Don't change the relative indent of ESQL/C 'EXEC SQL' bodies +indent_preserve_sql = false # false/true + +# Align continued statements at the '='. Default=True +# If FALSE or the '=' is followed by a newline, the next line is indent one tab. +indent_align_assign = true # false/true + +# +# Spacing options +# + +# Add or remove space around arithmetic operator '+', '-', '/', '*', etc +sp_arith = add # ignore/add/remove/force + +# Add or remove space around assignment operator '=', '+=', etc +sp_assign = add # ignore/add/remove/force + +# Add or remove space before assignment operator '=', '+=', etc. Overrides sp_assign. +sp_before_assign = add # ignore/add/remove/force + +# Add or remove space after assignment operator '=', '+=', etc. Overrides sp_assign. +sp_after_assign = add # ignore/add/remove/force + +# Add or remove space around assignment '=' in enum +sp_enum_assign = add # ignore/add/remove/force + +# Add or remove space before assignment '=' in enum. Overrides sp_enum_assign. +sp_enum_before_assign = add # ignore/add/remove/force + +# Add or remove space after assignment '=' in enum. Overrides sp_enum_assign. +sp_enum_after_assign = add # ignore/add/remove/force + +# Add or remove space around preprocessor '##' concatenation operator +sp_pp_concat = add # ignore/add/remove/force + +# Add or remove space after preprocessor '#' stringify operator +sp_pp_stringify = add # ignore/add/remove/force + +# Add or remove space around boolean operators '&&' and '||' +sp_bool = add # ignore/add/remove/force + +# Add or remove space around compare operator '<', '>', '==', etc +sp_compare = add # ignore/add/remove/force + +# Add or remove space inside '(' and ')' +sp_inside_paren = ignore # ignore/add/remove/force + +# Add or remove space between nested parens +sp_paren_paren = ignore # ignore/add/remove/force + +# Whether to balance spaces inside nested parens +sp_balance_nested_parens = false # false/true + +# Add or remove space between ')' and '{' +sp_paren_brace = add # ignore/add/remove/force + +# Add or remove space before pointer star '*' +sp_before_ptr_star = remove # ignore/add/remove/force + +# Add or remove space before pointer star '*' that isn't followed by a variable name +# If set to 'ignore', sp_before_ptr_star is used instead. +sp_before_unnamed_ptr_star = remove # ignore/add/remove/force + +# Add or remove space between pointer stars '*' +sp_between_ptr_star = remove # ignore/add/remove/force + +# Add or remove space after pointer star '*', if followed by a word. +sp_after_ptr_star = add # ignore/add/remove/force + +# Add or remove space after a pointer star '*', if followed by a func proto/def. +sp_after_ptr_star_func = add # ignore/add/remove/force + +# Add or remove space before a pointer star '*', if followed by a func proto/def. +sp_before_ptr_star_func = remove # ignore/add/remove/force + +# Add or remove space before a reference sign '&' +sp_before_byref = add # ignore/add/remove/force + +# Add or remove space before a reference sign '&' that isn't followed by a variable name +# If set to 'ignore', sp_before_byref is used instead. +sp_before_unnamed_byref = ignore # ignore/add/remove/force + +# Add or remove space after reference sign '&', if followed by a word. +sp_after_byref = remove # ignore/add/remove/force + +# Add or remove space after a reference sign '&', if followed by a func proto/def. +sp_after_byref_func = remove # ignore/add/remove/force + +# Add or remove space before a reference sign '&', if followed by a func proto/def. +sp_before_byref_func = add # ignore/add/remove/force + +# Add or remove space between type and word +sp_after_type = force # ignore/add/remove/force + +# Add or remove space in 'template <' vs 'template<'. +# If set to ignore, sp_before_angle is used. +sp_template_angle = ignore # ignore/add/remove/force + +# Add or remove space before '<>' +sp_before_angle = ignore # ignore/add/remove/force + +# Add or remove space inside '<' and '>' +sp_inside_angle = ignore # ignore/add/remove/force + +# Add or remove space after '<>' +sp_after_angle = ignore # ignore/add/remove/force + +# Add or remove space between '<>' and '(' as found in 'new List();' +sp_angle_paren = ignore # ignore/add/remove/force + +# Add or remove space between '<>' and a word as in 'List m;' +sp_angle_word = ignore # ignore/add/remove/force + +# Add or remove space before '(' of 'if', 'for', 'switch', and 'while' +sp_before_sparen = add # ignore/add/remove/force + +# Add or remove space inside if-condition '(' and ')' +sp_inside_sparen = remove # ignore/add/remove/force + +# Add or remove space before if-condition ')'. Overrides sp_inside_sparen. +sp_inside_sparen_close = remove # ignore/add/remove/force + +# Add or remove space after ')' of 'if', 'for', 'switch', and 'while' +sp_after_sparen = add # ignore/add/remove/force + +# Add or remove space between ')' and '{' of 'if', 'for', 'switch', and 'while' +sp_sparen_brace = add # ignore/add/remove/force + +# Add or remove space between 'invariant' and '(' in the D language. +sp_invariant_paren = ignore # ignore/add/remove/force + +# Add or remove space after the ')' in 'invariant (C) c' in the D language. +sp_after_invariant_paren = ignore # ignore/add/remove/force + +# Add or remove space before empty statement ';' on 'if', 'for' and 'while' +sp_special_semi = remove # ignore/add/remove/force + +# Add or remove space before ';' +sp_before_semi = remove # ignore/add/remove/force + +# Add or remove space before ';' in non-empty 'for' statements +sp_before_semi_for = remove # ignore/add/remove/force + +# Add or remove space before a semicolon of an empty part of a for statment. +sp_before_semi_for_empty = ignore # ignore/add/remove/force + +# Add or remove space after the final semicolon of an empty part of a for statment: for ( ; ; ). +sp_after_semi_for_empty = ignore # ignore/add/remove/force + +# Add or remove space before '[' (except '[]') +sp_before_square = remove # ignore/add/remove/force + +# Add or remove space before '[]' +sp_before_squares = remove # ignore/add/remove/force + +# Add or remove space inside '[' and ']' +sp_inside_square = remove # ignore/add/remove/force + +# Add or remove space after ',' +sp_after_comma = add # ignore/add/remove/force + +# Add or remove space before ',' +sp_before_comma = remove # ignore/add/remove/force + +# Add or remove space after class ':' +sp_after_class_colon = add # ignore/add/remove/force + +# Add or remove space before class ':' +sp_before_class_colon = add # ignore/add/remove/force + +# Add or remove space before case ':' +sp_before_case_colon = remove # ignore/add/remove/force + +# Add or remove space between 'operator' and operator sign +sp_after_operator = ignore # ignore/add/remove/force + +# Add or remove space between the operator symbol and the open paren, as in 'operator ++(' +sp_after_operator_sym = ignore # ignore/add/remove/force + +# Add or remove space after C/D cast, ie 'cast(int)a' vs 'cast(int) a' or '(int)a' vs '(int) a' +sp_after_cast = add # ignore/add/remove/force + +# Add or remove spaces inside cast parens +sp_inside_paren_cast = remove # ignore/add/remove/force + +# Add or remove space between the type and open paren in a C++ cast, ie 'int(exp)' vs 'int (exp)' +sp_cpp_cast_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'sizeof' and '(' +sp_sizeof_paren = remove # ignore/add/remove/force + +# Add or remove space after the tag keyword (Pawn) +sp_after_tag = ignore # ignore/add/remove/force + +# Add or remove space inside enum '{' and '}' +sp_inside_braces_enum = ignore # ignore/add/remove/force + +# Add or remove space inside struct/union '{' and '}' +sp_inside_braces_struct = ignore # ignore/add/remove/force + +# Add or remove space inside '{' and '}' +sp_inside_braces = ignore # ignore/add/remove/force + +# Add or remove space inside '{}' +sp_inside_braces_empty = ignore # ignore/add/remove/force + +# Add or remove space between return type and function name +# A minimum of 1 is forced except for pointer return types. +sp_type_func = add # ignore/add/remove/force + +# Add or remove space between function name and '(' on function declaration +sp_func_proto_paren = remove # ignore/add/remove/force + +# Add or remove space between function name and '(' on function definition +sp_func_def_paren = remove # ignore/add/remove/force + +# Add or remove space inside empty function '()' +sp_inside_fparens = remove # ignore/add/remove/force + +# Add or remove space inside function '(' and ')' +sp_inside_fparen = remove # ignore/add/remove/force + +# Add or remove space between ']' and '(' when part of a function call. +sp_square_fparen = remove # ignore/add/remove/force + +# Add or remove space between ')' and '{' of function +sp_fparen_brace = add # ignore/add/remove/force + +# Add or remove space between function name and '(' on function calls +sp_func_call_paren = remove # ignore/add/remove/force + +# Add or remove space between the user function name and '(' on function calls +# You need to set a keyword to be a user function, like this: 'set func_call_user _' in the config file. +sp_func_call_user_paren = ignore # ignore/add/remove/force + +# Add or remove space between a constructor/destructor and the open paren +sp_func_class_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'return' and '(' +sp_return_paren = add # ignore/add/remove/force + +# Add or remove space between '__attribute__' and '(' +sp_attribute_paren = remove # ignore/add/remove/force + +# Add or remove space between 'defined' and '(' in '#if defined (FOO)' +sp_defined_paren = remove # ignore/add/remove/force + +# Add or remove space between 'throw' and '(' in 'throw (something)' +sp_throw_paren = remove # ignore/add/remove/force + +# Add or remove space between macro and value +sp_macro = remove # ignore/add/remove/force + +# Add or remove space between macro function ')' and value +sp_macro_func = remove # ignore/add/remove/force + +# Add or remove space between 'else' and '{' if on the same line +sp_else_brace = add # ignore/add/remove/force + +# Add or remove space between '}' and 'else' if on the same line +sp_brace_else = add # ignore/add/remove/force + +# Add or remove space between '}' and the name of a typedef on the same line +sp_brace_typedef = add # ignore/add/remove/force + +# Add or remove space between 'catch' and '{' if on the same line +sp_catch_brace = add # ignore/add/remove/force + +# Add or remove space between '}' and 'catch' if on the same line +sp_brace_catch = add # ignore/add/remove/force + +# Add or remove space between 'finally' and '{' if on the same line +sp_finally_brace = add # ignore/add/remove/force + +# Add or remove space between '}' and 'finally' if on the same line +sp_brace_finally = add # ignore/add/remove/force + +# Add or remove space between 'try' and '{' if on the same line +sp_try_brace = add # ignore/add/remove/force + +# Add or remove space between get/set and '{' if on the same line +sp_getset_brace = add # ignore/add/remove/force + +# Add or remove space before the '::' operator +sp_before_dc = ignore # ignore/add/remove/force + +# Add or remove space after the '::' operator +sp_after_dc = ignore # ignore/add/remove/force + +# Add or remove around the D named array initializer ':' operator +sp_d_array_colon = ignore # ignore/add/remove/force + +# Add or remove space after the '!' (not) operator. +sp_not = remove # ignore/add/remove/force + +# Add or remove space after the '~' (invert) operator. +sp_inv = remove # ignore/add/remove/force + +# Add or remove space after the '&' (address-of) operator. +# This does not affect the spacing after a '&' that is part of a type. +sp_addr = remove # ignore/add/remove/force + +# Add or remove space around the '.' or '->' operators +sp_member = remove # ignore/add/remove/force + +# Add or remove space after the '*' (dereference) operator. +# This does not affect the spacing after a '*' that is part of a type. +sp_deref = remove # ignore/add/remove/force + +# Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7' +sp_sign = remove # ignore/add/remove/force + +# Add or remove space before or after '++' and '--', as in '(--x)' or 'y++;' +sp_incdec = remove # ignore/add/remove/force + +# Add or remove space before a backslash-newline at the end of a line +sp_before_nl_cont = add # ignore/add/remove/force + +# Add or remove space after the scope '+' or '-', as in '-(void) foo;' or '+(int) bar;' +sp_after_oc_scope = ignore # ignore/add/remove/force + +# Add or remove space after the colon in message specs +# '-(int) f:(int) x;' vs '-(int) f: (int) x;' +sp_after_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space before the colon in message specs +# '-(int) f: (int) x;' vs '-(int) f : (int) x;' +sp_before_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space after the colon in message specs +# '[object setValue:1];' vs '[object setValue: 1];' +sp_after_send_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space before the colon in message specs +# '[object setValue:1];' vs '[object setValue :1];' +sp_before_send_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space after the (type) in message specs +# '-(int) f: (int) x;' vs '-(int) f: (int)x;' +sp_after_oc_type = ignore # ignore/add/remove/force + +# Add or remove space around the ':' in 'b ? t : f' +sp_cond_colon = ignore # ignore/add/remove/force + +# Add or remove space around the '?' in 'b ? t : f' +sp_cond_question = ignore # ignore/add/remove/force + +# Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make sense here. +sp_case_label = ignore # ignore/add/remove/force + +# Control the space around the D '..' operator. +sp_range = ignore # ignore/add/remove/force + +# Control the space after the opening of a C++ comment '// A' vs '//A' +sp_cmt_cpp_start = ignore # ignore/add/remove/force + +# +# Code alignment (not left column spaces/tabs) +# + +# Whether to keep non-indenting tabs +align_keep_tabs = false # false/true + +# Whether to use tabs for alinging +align_with_tabs = false # false/true + +# Whether to bump out to the next tab when aligning +align_on_tabstop = true # false/true + +# Whether to left-align numbers +align_number_left = false # false/true + +# Align variable definitions in prototypes and functions +align_func_params = false # false/true + +# Align parameters in single-line functions that have the same name. +# The function names must already be aligned with each other. +align_same_func_call_params = false # false/true + +# The span for aligning variable definitions (0=don't align) +align_var_def_span = 0 # number + +# How to align the star in variable definitions. +# 0=Part of the type 'void * foo;' +# 1=Part of the variable 'void *foo;' +# 2=Dangling 'void *foo;' +align_var_def_star_style = 0 # number + +# How to align the '&' in variable definitions. +# 0=Part of the type +# 1=Part of the variable +# 2=Dangling +align_var_def_amp_style = 0 # number + +# The threshold for aligning variable definitions (0=no limit) +align_var_def_thresh = 0 # number + +# The gap for aligning variable definitions +align_var_def_gap = 0 # number + +# Whether to align the colon in struct bit fields +align_var_def_colon = true # false/true + +# Whether to align any attribute after the variable name +align_var_def_attribute = false # false/true + +# Whether to align inline struct/enum/union variable definitions +align_var_def_inline = true # false/true + +# The span for aligning on '=' in assignments (0=don't align) +align_assign_span = 0 # number + +# The threshold for aligning on '=' in assignments (0=no limit) +align_assign_thresh = 0 # number + +# The span for aligning on '=' in enums (0=don't align) +align_enum_equ_span = 0 # number + +# The threshold for aligning on '=' in enums (0=no limit) +align_enum_equ_thresh = 0 # number + +# The span for aligning struct/union (0=don't align) +align_var_struct_span = 0 # number + +# The threshold for aligning struct/union member definitions (0=no limit) +align_var_struct_thresh = 0 # number + +# The gap for aligning struct/union member definitions +align_var_struct_gap = 0 # number + +# The span for aligning struct initializer values (0=don't align) +align_struct_init_span = 4 # number + +# The minimum space between the type and the synonym of a typedef +align_typedef_gap = 0 # number + +# The span for aligning single-line typedefs (0=don't align) +align_typedef_span = 0 # number + +# How to align typedef'd functions with other typedefs +# 0: Don't mix them at all +# 1: align the open paren with the types +# 2: align the function type name with the other type names +align_typedef_func = 0 # number + +# Controls the positioning of the '*' in typedefs. Just try it. +# 0: Align on typdef type, ignore '*' +# 1: The '*' is part of type name: typedef int *pint; +# 2: The '*' is part of the type, but dangling: typedef int *pint; +align_typedef_star_style = 0 # number + +# Controls the positioning of the '&' in typedefs. Just try it. +# 0: Align on typdef type, ignore '&' +# 1: The '&' is part of type name: typedef int &pint; +# 2: The '&' is part of the type, but dangling: typedef int &pint; +align_typedef_amp_style = 0 # number + +# The span for aligning comments that end lines (0=don't align) +align_right_cmt_span = 0 # number + +# If aligning comments, mix with comments after '}' and #endif with less than 3 spaces before the comment +align_right_cmt_mix = false # false/true + +# If a trailing comment is more than this number of columns away from the text it follows, +# it will qualify for being aligned. +align_right_cmt_gap = 0 # number + +# Align trailing comment at or beyond column N; 'pulls in' comments as a bonus side effect (0=ignore) +align_right_cmt_at_col = 0 # number + +# The span for aligning function prototypes (0=don't align) +align_func_proto_span = 0 # number + +# Minimum gap between the return type and the function name. +align_func_proto_gap = 0 # number + +# Align function protos on the 'operator' keyword instead of what follows +align_on_operator = false # false/true + +# Whether to mix aligning prototype and variable declarations. +# If true, align_var_def_XXX options are used instead of align_func_proto_XXX options. +align_mix_var_proto = false # false/true + +# Align single-line functions with function prototypes, uses align_func_proto_span +align_single_line_func = false # false/true + +# Aligning the open brace of single-line functions. +# Requires align_single_line_func=true, uses align_func_proto_span +align_single_line_brace = false # false/true + +# Gap for align_single_line_brace. +align_single_line_brace_gap = 0 # number + +# The span for aligning ObjC msg spec (0=don't align) +align_oc_msg_spec_span = 0 # number + +# Whether to align macros wrapped with a backslash and a newline. +# This will not work right if the macro contains a multi-line comment. +align_nl_cont = false # false/true + +# The minimum space between label and value of a preprocessor define +align_pp_define_gap = 0 # number + +# The span for aligning on '#define' bodies (0=don't align) +align_pp_define_span = 4 # number + +# Align lines that start with '<<' with previous '<<'. Default=true +align_left_shift = true # false/true + +# +# Newline adding and removing options +# + +# Whether to collapse empty blocks between '{' and '}' +nl_collapse_empty_body = false # false/true + +# Don't split one-line braced assignments - 'foo_t f = { 1, 2 };' +nl_assign_leave_one_liners = false # false/true + +# Don't split one-line braced statements inside a class xx { } body +nl_class_leave_one_liners = false # false/true + +# Don't split one-line enums: 'enum foo { BAR = 15 };' +nl_enum_leave_one_liners = false # false/true + +# Don't split one-line get or set functions +nl_getset_leave_one_liners = false # false/true + +# Don't split one-line function definitions - 'int foo() { return 0; }' +nl_func_leave_one_liners = false # false/true + +# Don't split one-line if/else statements - 'if(a) b++;' +nl_if_leave_one_liners = false # false/true + +# Add or remove newlines at the start of the file +nl_start_of_file = ignore # ignore/add/remove/force + +# The number of newlines at the start of the file (only used if nl_start_of_file is 'add' or 'force' +nl_start_of_file_min = 0 # number + +# Add or remove newline at the end of the file +nl_end_of_file = ignore # ignore/add/remove/force + +# The number of newlines at the end of the file (only used if nl_end_of_file is 'add' or 'force') +nl_end_of_file_min = 0 # number + +# Add or remove newline between '=' and '{' +nl_assign_brace = remove # ignore/add/remove/force + +# Add or remove newline between '=' and '[' (D only) +nl_assign_square = ignore # ignore/add/remove/force + +# Add or remove newline after '= [' (D only). Will also affect the newline before the ']' +nl_after_square_assign = ignore # ignore/add/remove/force + +# The number of newlines after a block of variable definitions +nl_func_var_def_blk = 1 # number + +# Add or remove newline between a function call's ')' and '{', as in: +# list_for_each(item, &list) { } +nl_fcall_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'enum' and '{' +nl_enum_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'struct and '{' +nl_struct_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'union' and '{' +nl_union_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'if' and '{' +nl_if_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'else' +nl_brace_else = remove # ignore/add/remove/force + +# Add or remove newline between 'else if' and '{' +# If set to ignore, nl_if_brace is used instead +nl_elseif_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'else' and '{' +nl_else_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'else' and 'if' +nl_else_if = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'finally' +nl_brace_finally = remove # ignore/add/remove/force + +# Add or remove newline between 'finally' and '{' +nl_finally_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'try' and '{' +nl_try_brace = remove # ignore/add/remove/force + +# Add or remove newline between get/set and '{' +nl_getset_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'for' and '{' +nl_for_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'catch' and '{' +nl_catch_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'catch' +nl_brace_catch = remove # ignore/add/remove/force + +# Add or remove newline between 'while' and '{' +nl_while_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'do' and '{' +nl_do_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'while' of 'do' statement +nl_brace_while = remove # ignore/add/remove/force + +# Add or remove newline between 'switch' and '{' +nl_switch_brace = remove # ignore/add/remove/force + +# Add a newline between ')' and '{' if the ')' is on a different line than the if/for/etc. +# Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch, and nl_catch_brace. +nl_multi_line_cond = true # false/true + +# Force a newline in a define after the macro name for multi-line defines. +nl_multi_line_define = false # false/true + +# Whether to put a newline before 'case' statement +nl_before_case = true # false/true + +# Add or remove newline between ')' and 'throw' +nl_before_throw = add # ignore/add/remove/force + +# Whether to put a newline after 'case' statement +nl_after_case = true # false/true + +# Newline between namespace and { +nl_namespace_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'template<>' and whatever follows. +nl_template_class = ignore # ignore/add/remove/force + +# Add or remove newline between 'class' and '{' +nl_class_brace = ignore # ignore/add/remove/force + +# Add or remove newline after each ',' in the constructor member initialization +nl_class_init_args = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name in definition +nl_func_type_name = ignore # ignore/add/remove/force + +# Add or remove newline between function scope and name in a definition +# Controls the newline after '::' in 'void A::f() { }' +nl_func_scope_name = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name in a prototype +nl_func_proto_type_name = ignore # ignore/add/remove/force + +# Add or remove newline between a function name and the opening '(' +nl_func_paren = remove # ignore/add/remove/force + +# Add or remove newline after '(' in a function declaration +nl_func_decl_start = remove # ignore/add/remove/force + +# Add or remove newline after each ',' in a function declaration +nl_func_decl_args = remove # ignore/add/remove/force + +# Add or remove newline before the ')' in a function declaration +nl_func_decl_end = remove # ignore/add/remove/force + +# Add or remove newline between function signature and '{' +nl_fdef_brace = add # ignore/add/remove/force + +# Whether to put a newline after 'return' statement +nl_after_return = false # false/true + +# Add or remove a newline between the return keyword and return expression. +nl_return_expr = ignore # ignore/add/remove/force + +# Whether to put a newline after semicolons, except in 'for' statements +nl_after_semicolon = true # false/true + +# Whether to put a newline after brace open. +# This also adds a newline before the matching brace close. +nl_after_brace_open = true # false/true + +# If nl_after_brace_open and nl_after_brace_open_cmt are true, a newline is +# placed between the open brace and a trailing single-line comment. +nl_after_brace_open_cmt = false # false/true + +# Whether to put a newline after a virtual brace open. +# These occur in un-braced if/while/do/for statement bodies. +nl_after_vbrace_open = true # false/true + +# Whether to put a newline after a brace close. +# Does not apply if followed by a necessary ';'. +nl_after_brace_close = false # false/true + +# Whether to alter newlines in '#define' macros +nl_define_macro = false # false/true + +# Whether to not put blanks after '#ifxx', '#elxx', or before '#endif' +nl_squeeze_ifdef = false # false/true + +# Add or remove newline before 'if' +nl_before_if = ignore # ignore/add/remove/force + +# Add or remove newline after 'if' +nl_after_if = add # ignore/add/remove/force + +# Add or remove newline before 'for' +nl_before_for = ignore # ignore/add/remove/force + +# Add or remove newline after 'for' +nl_after_for = add # ignore/add/remove/force + +# Add or remove newline before 'while' +nl_before_while = ignore # ignore/add/remove/force + +# Add or remove newline after 'while' +nl_after_while = add # ignore/add/remove/force + +# Add or remove newline before 'switch' +nl_before_switch = ignore # ignore/add/remove/force + +# Add or remove newline after 'switch' +nl_after_switch = add # ignore/add/remove/force + +# Add or remove newline before 'do' +nl_before_do = ignore # ignore/add/remove/force + +# Add or remove newline after 'do' +nl_after_do = add # ignore/add/remove/force + +# Whether to double-space commented-entries in struct/enum +nl_ds_struct_enum_cmt = false # false/true + +# Whether to double-space before the close brace of a struct/union/enum +nl_ds_struct_enum_close_brace = false # false/true + +# Add or remove a newline around a class colon. +# Related to pos_class_colon, nl_class_init_args, and pos_comma. +nl_class_colon = ignore # ignore/add/remove/force + +# Change simple unbraced if statements into a one-liner +# 'if(b)\n i++;' => 'if(b) i++;' +nl_create_if_one_liner = false # false/true + +# Change simple unbraced for statements into a one-liner +# 'for (i=0;i<5;i++)\n foo(i);' => 'for (i=0;i<5;i++) foo(i);' +nl_create_for_one_liner = false # false/true + +# Change simple unbraced while statements into a one-liner +# 'while (i<5)\n foo(i++);' => 'while (i<5) foo(i++);' +nl_create_while_one_liner = false # false/true + +# +# Positioning options +# + +# The position of arithmetic operators in wrapped expressions +pos_arith = ignore # ignore/lead/trail + +# The position of assignment in wrapped expressions +pos_assign = ignore # ignore/lead/trail + +# The position of boolean operators in wrapped expressions +pos_bool = ignore # ignore/lead/trail + +# The position of the comma in wrapped expressions +pos_comma = ignore # ignore/lead/trail + +# The position of the comma in the constructor initialization list +pos_class_comma = ignore # ignore/lead/trail + +# The position of colons between constructor and member initialization +pos_class_colon = ignore # ignore/lead/trail + +# +# Line Splitting options +# + +# Try to limit code width to N number of columns +code_width = 80 # number + +# Whether to fully split long 'for' statements at semi-colons +ls_for_split_full = false # false/true + +# Whether to fully split long function protos/calls at commas +ls_func_split_full = false # false/true + +# +# Blank line options +# + +# The maximum consecutive newlines +nl_max = 0 # number + +# The number of newlines after a function prototype, if followed by another function prototype +nl_after_func_proto = 0 # number + +# The number of newlines after a function prototype, if not followed by another function prototype +nl_after_func_proto_group = 0 # number + +# The number of newlines after '}' of a multi-line function body +nl_after_func_body = 0 # number + +# The number of newlines after '}' of a single line function body +nl_after_func_body_one_liner = 0 # number + +# The minimum number of newlines before a multi-line comment. +# Doesn't apply if after a brace open or another multi-line comment. +nl_before_block_comment = 0 # number + +# The minimum number of newlines before a single-line C comment. +# Doesn't apply if after a brace open or other single-line C comments. +nl_before_c_comment = 0 # number + +# The minimum number of newlines before a CPP comment. +# Doesn't apply if after a brace open or other CPP comments. +nl_before_cpp_comment = 0 # number + +# Whether to force a newline after a mulit-line comment. +nl_after_multiline_comment = false # false/true + +# The number of newlines before a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. +# Will not change the newline count if after a brace open. +# 0 = No change. +nl_before_access_spec = 0 # number + +# The number of newlines after a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. +# 0 = No change. +nl_after_access_spec = 0 # number + +# The number of newlines between a function def and the function comment. +# 0 = No change. +nl_comment_func_def = 0 # number + +# The number of newlines after a try-catch-finally block that isn't followed by a brace close. +# 0 = No change. +nl_after_try_catch_finally = 0 # number + +# The number of newlines before and after a property, indexer or event decl. +# 0 = No change. +nl_around_cs_property = 0 # number + +# The number of newlines between the get/set/add/remove handlers in C#. +# 0 = No change. +nl_between_get_set = 0 # number + +# Whether to remove blank lines after '{' +eat_blanks_after_open_brace = false # false/true + +# Whether to remove blank lines before '}' +eat_blanks_before_close_brace = false # false/true + +# +# Code modifying options (non-whitespace) +# + +# Add or remove braces on single-line 'do' statement +mod_full_brace_do = add # ignore/add/remove/force + +# Add or remove braces on single-line 'for' statement +mod_full_brace_for = add # ignore/add/remove/force + +# Add or remove braces on single-line function defintions. (Pawn) +mod_full_brace_function = ignore # ignore/add/remove/force + +# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'. +mod_full_brace_if = add # ignore/add/remove/force + +# Don't remove braces around statements that span N newlines +mod_full_brace_nl = 0 # number + +# Add or remove braces on single-line 'while' statement +mod_full_brace_while = add # ignore/add/remove/force + +# Add or remove unnecessary paren on 'return' statement +mod_paren_on_return = ignore # ignore/add/remove/force + +# Whether to change optional semicolons to real semicolons +mod_pawn_semicolon = false # false/true + +# Add parens on 'while' and 'if' statement around bools +mod_full_paren_if_bool = false # false/true + +# Whether to remove superfluous semicolons +mod_remove_extra_semicolon = false # false/true + +# If a function body exceeds the specified number of newlines and doesn't have a comment after +# the close brace, a comment will be added. +mod_add_long_function_closebrace_comment = 0 # number + +# If a switch body exceeds the specified number of newlines and doesn't have a comment after +# the close brace, a comment will be added. +mod_add_long_switch_closebrace_comment = 0 # number + +# If an #ifdef body exceeds the specified number of newlines and doesn't have a comment after +# the #else, a comment will be added. +mod_add_long_ifdef_endif_comment = 0 # number + +# If an #ifdef or #else body exceeds the specified number of newlines and doesn't have a comment after +# the #endif, a comment will be added. +mod_add_long_ifdef_else_comment = 0 # number + +# If TRUE, will sort consecutive single-line 'import' statements [Java, D] +mod_sort_import = false # false/true + +# If TRUE, will sort consecutive single-line 'using' statements [C#] +mod_sort_using = false # false/true + +# If TRUE, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C] +# This is generally a bad idea, as it may break your code. +mod_sort_include = false # false/true + +# If TRUE, it will move a 'break' that appears after a fully braced 'case' before the close brace. +mod_move_case_break = false # false/true + +# If TRUE, it will remove a void 'return;' that appears as the last statement in a function. +mod_remove_empty_return = false # false/true + +# +# Comment modifications +# + +# Try to wrap comments at cmt_width columns +cmt_width = 0 # number + +# If false, disable all multi-line comment changes, including cmt_width and leading chars. +# Default is true. +cmt_indent_multi = true # false/true + +# Whether to group c-comments that look like they are in a block +cmt_c_group = false # false/true + +# Whether to put an empty '/*' on the first line of the combined c-comment +cmt_c_nl_start = false # false/true + +# Whether to put a newline before the closing '*/' of the combined c-comment +cmt_c_nl_end = false # false/true + +# Whether to group cpp-comments that look like they are in a block +cmt_cpp_group = false # false/true + +# Whether to put an empty '/*' on the first line of the combined cpp-comment +cmt_cpp_nl_start = false # false/true + +# Whether to put a newline before the closing '*/' of the combined cpp-comment +cmt_cpp_nl_end = false # false/true + +# Whether to change cpp-comments into c-comments +cmt_cpp_to_c = false # false/true + +# Whether to put a star on subsequent comment lines +cmt_star_cont = false # false/true + +# The number of spaces to insert at the start of subsequent comment lines +cmt_sp_before_star_cont = 0 # number + +# The number of spaces to insert after the star on subsequent comment lines +cmt_sp_after_star_cont = 1 # number + +# For multi-line comments with a '*' lead, remove leading spaces if the first and last lines of +# the comment are the same length. Default=True +cmt_multi_check_last = false # false/true + +# The filename that contains text to insert at the head of a file if the file doesn't start with a C/C++ comment. +# Will substitue $(filename) with the current file's name. +cmt_insert_file_header = "" # string + +# The filename that contains text to insert at the end of a file if the file doesn't end with a C/C++ comment. +# Will substitue $(filename) with the current file's name. +cmt_insert_file_footer = "" # string + +# The filename that contains text to insert before a function implementation if the function isn't preceeded with a C/C++ comment. +# Will substitue $(function) with the function name and $(javaparam) with the javadoc @param and @return stuff. +# Will also substitute $(fclass) with the class name: void CFoo::Bar() { ... } +cmt_insert_func_header = "" # string + +# The filename that contains text to insert before a class if the class isn't preceeded with a C/C++ comment. +# Will substitue $(class) with the class name. +cmt_insert_class_header = "" # string + +# If a preprocessor is encountered when stepping backwards from a function name, then +# this option decides whether the comment should be inserted. +# Affects cmt_insert_func_header and cmt_insert_class_header. +cmt_insert_before_preproc = false # false/true + +# +# Preprocessor options +# + +# Control indent of preprocessors inside #if blocks at brace level 0 +pp_indent = ignore # ignore/add/remove/force + +# Whether to indent #if/#else/#endif at the brace level (true) or from column 1 (false) +pp_indent_at_level = false # false/true + +# If pp_indent_at_level=false, specifies the number of columns to indent per level. Default=1. +pp_indent_count = 1 # number + +# Add or remove space after # based on pp_level of #if blocks +pp_space = ignore # ignore/add/remove/force + +# Sets the number of spaces added with pp_space +pp_space_count = 0 # number + +# The indent for #region and #endregion in C# and '#pragma region' in C/C++ +pp_indent_region = 0 # number + +# Whether to indent the code between #region and #endregion +pp_region_indent_code = false # false/true + +# If pp_indent_at_level=true, sets the indent for #if, #else, and #endif when not at file-level +pp_indent_if = 0 # number + +# Control whether to indent the code between #if, #else and #endif when not at file-level +pp_if_indent_code = false # false/true + +# Whether to indent '#define' at the brace level (true) or from column 1 (false) +pp_define_at_level = false # false/true + +# You can force a token to be a type with the 'type' option. +# Example: +# type myfoo1 myfoo2 +# +# You can create custom macro-based indentation using macro-open, +# macro-else and macro-close. +# Example: +# macro-open BEGIN_TEMPLATE_MESSAGE_MAP +# macro-open BEGIN_MESSAGE_MAP +# macro-close END_MESSAGE_MAP +# +# You can assign any keyword to any type with the set option. +# set func_call_user _ N_ +# +# The full syntax description of all custom definition config entries +# is shown below: +# +# define custom tokens as: +# - embed whitespace in token using '' escape character, or +# put token in quotes +# - these: ' " and ` are recognized as quote delimiters +# +# type token1 token2 token3 ... +# ^ optionally specify multiple tokens on a single line +# define def_token output_token +# ^ output_token is optional, then NULL is assumed +# macro-open token +# macro-close token +# macro-else token +# set id token1 token2 ... +# ^ optionally specify multiple tokens on a single line +# ^ id is one of the names in token_enum.h sans the CT_ prefix, +# e.g. PP_PRAGMA +# +# all tokens are separated by any mix of ',' commas, '=' equal signs +# and whitespace (space, tab) +# -- 1.6.0.2 From hartmut at tyndur.org Mon Aug 24 09:17:18 2009 From: hartmut at tyndur.org (hartmut at tyndur.org) Date: Mon, 24 Aug 2009 09:17:18 +0200 Subject: [tyndur-devel] =?utf-8?b?W1BBVENIXSBQYXRjaCBmw7xyIG11dHQgMS4yLjMu?= =?utf-8?q?4?= Message-ID: <1251098238-17919-1-git-send-email-hartmut@tyndur.org> From: Alexander Hartmut Kluth + lbuilds: Patch für mutt, baut erfolgreich, mutt -h geht auch ;-) Signed-off-by: Alexander Hartmut Kluth --- .../mutt/1.4.2.3/files/mutt_1.4.3.2_tyndur.patch | 619 ++++++++++++++++++++ 1 files changed, 619 insertions(+), 0 deletions(-) create mode 100644 lbuilds/mutt/1.4.2.3/files/mutt_1.4.3.2_tyndur.patch diff --git a/lbuilds/mutt/1.4.2.3/files/mutt_1.4.3.2_tyndur.patch b/lbuilds/mutt/1.4.2.3/files/mutt_1.4.3.2_tyndur.patch new file mode 100644 index 0000000..d512153 --- /dev/null +++ b/lbuilds/mutt/1.4.2.3/files/mutt_1.4.3.2_tyndur.patch @@ -0,0 +1,619 @@ +Index: mutt-1.4.2.3/sendlib.c +=================================================================== +--- mutt-1.4.2.3.orig/sendlib.c 2007-05-23 03:17:54.000000000 +0200 ++++ mutt-1.4.2.3/sendlib.c 2009-08-24 09:03:54.000000000 +0200 +@@ -55,6 +55,11 @@ + #include + #endif + ++void execv(const char*, const char*); ++void setsid(void); ++ ++#define SIGTSTP 1 ++ + extern char RFC822Specials[]; + + static struct sysexits +@@ -1775,6 +1780,7 @@ + sigset_t set; + int fd, st; + pid_t pid, ppid; ++ char *syscmd; + + mutt_block_signals_system (); + +@@ -1801,7 +1807,8 @@ + /* we want the delivery to continue even after the main process dies, + * so we put ourselves into another session right away + */ +- setsid (); ++ // No, we don't want to create a new session in tyndur (yet) ++ //setsid (); + + /* next we close all open files */ + #if defined(OPEN_MAX) +@@ -1844,7 +1851,12 @@ + _exit (S_ERR); + } + +- execv (path, args); ++ syscmd = malloc(256); ++ ++ strcpy(syscmd, path); ++ strcat(syscmd, args); ++ ++ system(syscmd); + _exit (S_ERR); + } + else if (pid == -1) +Index: mutt-1.4.2.3/resize.c +=================================================================== +--- mutt-1.4.2.3.orig/resize.c 2007-05-23 03:17:54.000000000 +0200 ++++ mutt-1.4.2.3/resize.c 2009-08-24 09:03:54.000000000 +0200 +@@ -32,6 +32,11 @@ + # endif + #endif + ++struct winsize ++{ ++ int ws_row, ws_col; ++}; ++ + /* this routine should be called after receiving SIGWINCH */ + void mutt_resize_screen (void) + { +@@ -46,12 +51,12 @@ + SLtt_Screen_Cols = -1; + if ((fd = open ("/dev/tty", O_RDONLY)) != -1) + { +- if (ioctl (fd, TIOCGWINSZ, &w) != -1) ++ /*if (ioctl (fd, TIOCGWINSZ, &w) != -1) + { + SLtt_Screen_Rows = w.ws_row; + SLtt_Screen_Cols = w.ws_col; + } +- close (fd); ++ close (fd);*/ + } + if (SLtt_Screen_Rows <= 0) + { +Index: mutt-1.4.2.3/mutt_tunnel.c +=================================================================== +--- mutt-1.4.2.3.orig/mutt_tunnel.c 2007-05-23 03:17:53.000000000 +0200 ++++ mutt-1.4.2.3/mutt_tunnel.c 2009-08-24 09:03:54.000000000 +0200 +@@ -27,6 +27,8 @@ + #include + #include + #include ++#include ++#include + + /* -- data types -- */ + typedef struct +@@ -89,9 +91,14 @@ + close (STDERR_FILENO); + + /* Don't let the subprocess think it can use the controlling tty */ +- setsid (); ++ //setsid (); + +- execl (EXECSHELL, "sh", "-c", Tunnel, NULL); ++ char *sysstr; ++ ++ strcpy(sysstr, "sh -c"); ++ strncpy(sysstr, Tunnel, 255); ++ ++ system(sysstr); + _exit (127); + } + mutt_unblock_signals_system (1); +@@ -108,8 +115,11 @@ + if (close (pin[1]) < 0 || close (pout[0]) < 0) + mutt_perror ("close"); + +- fcntl (pin[0], F_SETFD, FD_CLOEXEC); +- fcntl (pout[1], F_SETFD, FD_CLOEXEC); ++ // fcntl (pin[0], F_SETFD, FD_CLOEXEC); ++ // fcntl (pout[1], F_SETFD, FD_CLOEXEC); ++ fclose(pin[0]); ++ fclose(pout[1]); ++ + + tunnel->readfd = pin[0]; + tunnel->writefd = pout[1]; +Index: mutt-1.4.2.3/regex.c +=================================================================== +--- mutt-1.4.2.3.orig/regex.c 2007-05-23 03:17:54.000000000 +0200 ++++ mutt-1.4.2.3/regex.c 2009-08-24 09:03:54.000000000 +0200 +@@ -34,6 +34,8 @@ + * tlr, 1999-02-25 + */ + ++#include ++#include + /* The following doesn't mix too well with autoconfiguring + * the use of alloca. So let's disable it for AIX. + */ +@@ -2211,7 +2213,9 @@ + #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) + boolean is_lower = STREQ (str, "lower"); + boolean is_upper = STREQ (str, "upper"); +- wctype_t wt; ++ ++ ++ wchar_t wt; + int ch; + + wt = wctype (str); +Index: mutt-1.4.2.3/mbox.c +=================================================================== +--- mutt-1.4.2.3.orig/mbox.c 2007-05-23 03:17:53.000000000 +0200 ++++ mutt-1.4.2.3/mbox.c 2009-08-24 09:03:54.000000000 +0200 +@@ -937,7 +937,7 @@ + if (i == 0) + { + ctx->size = ftell (ctx->fp); /* update the size of the mailbox */ +- ftruncate (fileno (ctx->fp), ctx->size); ++ //ftruncate (fileno (ctx->fp), ctx->size); + } + } + +Index: mutt-1.4.2.3/filter.c +=================================================================== +--- mutt-1.4.2.3.orig/filter.c 2007-05-23 03:17:53.000000000 +0200 ++++ mutt-1.4.2.3/filter.c 2009-08-24 09:03:54.000000000 +0200 +@@ -30,6 +30,7 @@ + int fdin, int fdout, int fderr) + { + int pin[2], pout[2], perr[2], thepid; ++ char *syscmd; + + if (in) + { +@@ -113,7 +114,12 @@ + close (fderr); + } + +- execl (EXECSHELL, "sh", "-c", cmd, NULL); ++ syscmd = malloc(255); ++ ++ strcpy(syscmd, "sh -c"); ++ strcat(syscmd, cmd); ++ ++ system(syscmd); + _exit (127); + } + else if (thepid == -1) +Index: mutt-1.4.2.3/system.c +=================================================================== +--- mutt-1.4.2.3.orig/system.c 2007-05-23 03:17:54.000000000 +0200 ++++ mutt-1.4.2.3/system.c 2009-08-24 09:03:54.000000000 +0200 +@@ -30,6 +30,7 @@ + + int _mutt_system (const char *cmd, int flags) + { ++ char *syscmd; + int rc = -1; + struct sigaction act; + struct sigaction oldtstp; +@@ -72,7 +73,7 @@ + int fd; + + /* give up controlling terminal */ +- setsid (); ++ //setsid (); + + switch (fork ()) + { +@@ -110,8 +111,13 @@ + sigaction (SIGTSTP, &act, NULL); + sigaction (SIGCONT, &act, NULL); + +- execl (EXECSHELL, "sh", "-c", cmd, NULL); +- _exit (127); /* execl error */ ++ syscmd = malloc(256); ++ ++ strcpy(syscmd, "sh -c"); ++ strcat(syscmd, cmd); ++ ++ system(syscmd); ++ //_exit (127); /* execl error */ + } + else if (thepid != -1) + { +Index: mutt-1.4.2.3/mx.c +=================================================================== +--- mutt-1.4.2.3.orig/mx.c 2007-05-23 03:17:53.000000000 +0200 ++++ mutt-1.4.2.3/mx.c 2009-08-24 09:03:54.000000000 +0200 +@@ -1491,7 +1491,7 @@ + } + + if (r == 0 && (ctx->magic == M_MBOX || ctx->magic == M_MMDF || ctx->magic == M_KENDRA) +- && (fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1)) ++ && (fflush (msg->fp) == EOF)) + { + mutt_perror _("Can't write message"); + r = -1; +Index: mutt-1.4.2.3/mbyte.c +=================================================================== +--- mutt-1.4.2.3.orig/mbyte.c 2007-05-23 03:17:53.000000000 +0200 ++++ mutt-1.4.2.3/mbyte.c 2009-08-24 09:03:54.000000000 +0200 +@@ -76,7 +76,7 @@ + #endif + } + +-#ifndef HAVE_WC_FUNCS ++#ifdef HAVE_WC_FUNCS + + /* + * For systems that don't have them, we provide here our own +Index: mutt-1.4.2.3/main.c +=================================================================== +--- mutt-1.4.2.3.orig/main.c 2007-05-23 03:17:53.000000000 +0200 ++++ mutt-1.4.2.3/main.c 2009-08-24 09:03:54.000000000 +0200 +@@ -441,6 +441,7 @@ + + int main (int argc, char **argv) + { ++ + char folder[_POSIX_PATH_MAX] = ""; + char *subject = NULL; + char *includeFile = NULL; +@@ -466,6 +467,7 @@ + exit(1); + } + ++ + #ifdef ENABLE_NLS + /* FIXME what about init.c:1439 ? */ + setlocale (LC_ALL, ""); +@@ -480,12 +482,16 @@ + SRAND (time (NULL)); + umask (077); + ++ + memset (Options, 0, sizeof (Options)); + memset (QuadOptions, 0, sizeof (QuadOptions)); +- ++ ++ + while ((i = getopt (argc, argv, "a:b:F:f:c:d:e:H:s:i:hm:npRvxyzZ")) != EOF) + switch (i) + { ++ ++ + case 'a': + attach = mutt_add_list (attach, optarg); + break; +@@ -577,6 +583,7 @@ + mutt_usage (); + } + ++ + switch (version) + { + case 0: +@@ -591,6 +598,7 @@ + exit (0); + } + ++ + /* Check for a batch send. */ + if (!isatty (0)) + { +@@ -598,18 +606,22 @@ + sendflags = SENDBATCH; + } + ++ + /* This must come before mutt_init() because curses needs to be started + before calling the init_pair() function to set the color scheme. */ + if (!option (OPTNOCURSES)) + start_curses (); + ++ + /* set defaults and read init files */ + mutt_init (flags & M_NOSYSRC, commands); + mutt_free_list (&commands); + ++ + if (newMagic) + mx_set_magic (newMagic); + ++ + if (!option (OPTNOCURSES)) + { + SETCOLOR (MT_COLOR_NORMAL); +@@ -618,6 +630,7 @@ + mutt_message = mutt_curses_message; + } + ++ + /* Create the Maildir directory if it doesn't exist. */ + if (!option (OPTNOCURSES) && Maildir) + { +@@ -642,6 +655,7 @@ + } + } + ++ + if (sendflags & SENDPOSTPONED) + { + if (!option (OPTNOCURSES)) +@@ -649,9 +663,11 @@ + ci_send_message (SENDPOSTPONED, NULL, NULL, NULL, NULL); + mutt_endwin (NULL); + } ++ + else if (subject || msg || sendflags || draftFile || includeFile || attach || + optind < argc) + { ++ + FILE *fin = NULL; + char buf[LONG_STRING]; + char *tempfile = NULL, *infile = NULL; +@@ -660,16 +676,23 @@ + if (!option (OPTNOCURSES)) + mutt_flushinp (); + ++ ++ + if (!msg) + msg = mutt_new_header (); + ++ + if (draftFile) + infile = draftFile; + else + { ++ ++ + if (!msg->env) + msg->env = mutt_new_envelope (); + ++ ++ + for (i = optind; i < argc; i++) + { + if (url_check_scheme (argv[i]) == U_MAILTO) +@@ -678,25 +701,36 @@ + msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]); + } + ++ ++ + if (option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc) + { ++ ++ + if (!option (OPTNOCURSES)) + mutt_endwin (NULL); + fputs (_("No recipients specified.\n"), stderr); + exit (1); + } + ++ ++ + if (subject) + msg->env->subject = safe_strdup (subject); + ++ ++ + if (includeFile) + infile = includeFile; + } + + if (infile || bodytext) + { ++ ++ + if (infile) + { ++ + if (mutt_strcmp ("-", infile) == 0) + fin = stdin; + else +@@ -709,24 +743,34 @@ + { + if (!option (OPTNOCURSES)) + mutt_endwin (NULL); +- perror (path); ++ ++ ++ ++ perror (path); ++ + exit (1); + } + } ++ ++ + } + else + fin = NULL; + ++ + mutt_mktemp (buf); + tempfile = safe_strdup (buf); + ++ ++ + if (draftFile) + msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0); + + /* is the following if still needed? */ +- ++ + if (tempfile) + { ++ + FILE *fout; + + if ((fout = safe_fopen (tempfile, "w")) == NULL) +@@ -735,9 +779,15 @@ + mutt_endwin (NULL); + perror (tempfile); + fclose (fin); ++ + FREE (&tempfile); + exit (1); ++ ++ + } ++ ++ ++ + if (fin) + mutt_copy_stream (fin, fout); + else if (bodytext) +@@ -748,10 +798,14 @@ + } + } + ++ + safe_free ((void **) &bodytext); + ++ + if (attach) + { ++ ++ + LIST *t = attach; + BODY *a = NULL; + +@@ -759,15 +813,25 @@ + { + if (a) + { ++ + a->next = mutt_make_file_attach (t->data); ++ + a = a->next; ++ ++ + } + else + msg->content = a = mutt_make_file_attach (t->data); +- if (!a) ++ ++ ++if (!a) + { ++ ++ + if (!option (OPTNOCURSES)) + mutt_endwin (NULL); ++ ++ + fprintf (stderr, _("%s: unable to attach file.\n"), t->data); + mutt_free_list (&attach); + exit (1); +@@ -777,15 +841,22 @@ + mutt_free_list (&attach); + } + ++ ++ + ci_send_message (sendflags, msg, tempfile, NULL, NULL); + ++ ++ + if (!option (OPTNOCURSES)) + mutt_endwin (NULL); + } + else + { ++ ++ + if (flags & M_BUFFY) + { ++ + if (!mutt_buffy_check (0)) + { + mutt_endwin _("No mailbox with new mail."); +@@ -793,17 +864,24 @@ + } + folder[0] = 0; + mutt_buffy (folder, sizeof (folder)); ++ + } + else if (flags & M_SELECT) + { ++ ++ + if (!Incoming) { + mutt_endwin _("No incoming mailboxes defined."); + exit (1); + } + folder[0] = 0; ++ + mutt_select_file (folder, sizeof (folder), M_SEL_FOLDER | M_SEL_BUFFY); ++ ++ + if (!folder[0]) + { ++ + mutt_endwin (NULL); + exit (0); + } +@@ -822,12 +900,14 @@ + /* check to see if there are any messages in the folder */ + if (stat (folder, &st) != 0) + { ++ + mutt_endwin (strerror (errno)); + exit (1); + } + + if (st.st_size == 0) + { ++ printf("Spack?\n"); + mutt_endwin _("Mailbox is empty."); + exit (1); + } +@@ -835,6 +915,7 @@ + + mutt_folder_hook (folder); + ++ + if((Context = mx_open_mailbox (folder, ((flags & M_RO) || option (OPTREADONLY)) ? M_READONLY : 0, NULL)) + || !explicit_folder) + { +@@ -842,6 +923,7 @@ + if (Context) + safe_free ((void **)&Context); + } ++ + mutt_endwin (Errorbuf); + } + +Index: mutt-1.4.2.3/send.c +=================================================================== +--- mutt-1.4.2.3.orig/send.c 2007-05-23 03:17:54.000000000 +0200 ++++ mutt-1.4.2.3/send.c 2009-08-24 09:03:54.000000000 +0200 +@@ -1144,17 +1144,17 @@ + if (option (OPTTEXTFLOWED)) + mutt_set_parameter ("format", "flowed", &msg->content->parameter); + +- if (!tempfile) +- { ++ // if (!tempfile) ++ // { + mutt_mktemp (buffer); + tempfp = safe_fopen (buffer, "w+"); + msg->content->filename = safe_strdup (buffer); +- } +- else +- { +- tempfp = safe_fopen (tempfile, "a+"); +- msg->content->filename = safe_strdup (tempfile); +- } ++ // } ++ // else ++ // { ++ // tempfp = safe_fopen (tempfile, "a+"); ++ // msg->content->filename = safe_strdup (tempfile); ++ // } + + if (!tempfp) + { -- 1.6.0.4 From hartmut at tyndur.org Mon Aug 24 16:01:11 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Mon, 24 Aug 2009 16:01:11 +0200 Subject: [tyndur-devel] [PATCH] losh, shell.c Message-ID: <1251122471-1496-1-git-send-email-hartmut@tyndur.org> ! Leerzeichen am Ende werden nun entfernt. Nicht sehr schön, tutet aber Signed-off-by: Alexander Hartmut Kluth --- src/modules/c/shell/shell.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index 9d5583a..dddee20 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) strcpy(shell_command_buffer, argv[2]); shell_do_cmd(); } - + return 0; } @@ -144,7 +144,8 @@ void shell_read_command(void) char* cwd = getcwd(NULL, 0); char* prompt; char* input; - + int i; + asprintf(&prompt, "%s # ", cwd); input = readline(prompt); @@ -153,6 +154,18 @@ void shell_read_command(void) add_history(input); } + for (i = strlen(input) - 1; i >= 0; i--) { + if (input[i] != ' ') { + input[i+1] = 0; + break; + } + } + + if (i == 0) { + input[0] = 0; + } + + strncpy(shell_command_buffer, input, COMMAND_BUFFER_SIZE); free(input); } else { @@ -200,7 +213,7 @@ bool shell_match_command(const char* cmd, const char* cmdline) cmd++; cmdline++; } - + // Kommt nie vor. return FALSE; } @@ -263,6 +276,7 @@ int shell_do_cmd(void) return 0; } + // Die Liste mit den Befehlen durchsuchen. Das wird solange gemacht, bis // der NULL eintrag am Ende erreicht wird. for (i = 0; (command = &shell_commands[i]) && (command->name); i++) @@ -280,7 +294,7 @@ int shell_do_cmd(void) argc++; } } - + char* argv[argc]; argv[0] = strtok(args, " "); for(pos = 1; pos < argc; pos++) @@ -291,13 +305,12 @@ int shell_do_cmd(void) while (argv[argc - 1] == NULL) { argc--; } - + return command->handler(argc, argv, cmdstring); } } return shell_command_default(0, 0, cmdstring); } - /** * Shell-Skript ausfuehren * -- 1.6.0.4 From hartmut at tyndur.org Mon Aug 24 16:55:21 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Mon, 24 Aug 2009 16:55:21 +0200 Subject: [tyndur-devel] [PATCH] losh, shell.c Message-ID: <1251125721-6263-1-git-send-email-hartmut@tyndur.org> ! Leerzeichen am Ende werden nun entfernt. Nicht sehr schön, tutet aber Signed-off-by: Alexander Hartmut Kluth --- src/modules/c/shell/shell.c | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index 9d5583a..3560aea 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) strcpy(shell_command_buffer, argv[2]); shell_do_cmd(); } - + return 0; } @@ -144,7 +144,8 @@ void shell_read_command(void) char* cwd = getcwd(NULL, 0); char* prompt; char* input; - + int i; + asprintf(&prompt, "%s # ", cwd); input = readline(prompt); @@ -153,6 +154,19 @@ void shell_read_command(void) add_history(input); } + if ((strlen(input)) > 2) { + for (i = strlen(input) - 1; i >= 0; i--) { + if (input[i] != ' ') { + input[i+1] = 0; + break; + } + } + + if (i == 0) { + input[0] = 0; + } + } + strncpy(shell_command_buffer, input, COMMAND_BUFFER_SIZE); free(input); } else { @@ -200,7 +214,7 @@ bool shell_match_command(const char* cmd, const char* cmdline) cmd++; cmdline++; } - + // Kommt nie vor. return FALSE; } @@ -263,6 +277,7 @@ int shell_do_cmd(void) return 0; } + // Die Liste mit den Befehlen durchsuchen. Das wird solange gemacht, bis // der NULL eintrag am Ende erreicht wird. for (i = 0; (command = &shell_commands[i]) && (command->name); i++) @@ -280,7 +295,7 @@ int shell_do_cmd(void) argc++; } } - + char* argv[argc]; argv[0] = strtok(args, " "); for(pos = 1; pos < argc; pos++) @@ -291,13 +306,12 @@ int shell_do_cmd(void) while (argv[argc - 1] == NULL) { argc--; } - + return command->handler(argc, argv, cmdstring); } } return shell_command_default(0, 0, cmdstring); } - /** * Shell-Skript ausfuehren * -- 1.6.0.4 From max at tyndur.org Mon Aug 24 19:08:23 2009 From: max at tyndur.org (Max Reitz) Date: Mon, 24 Aug 2009 19:08:23 +0200 Subject: [tyndur-devel] [PATCH] losh, shell.c In-Reply-To: <1251125721-6263-1-git-send-email-hartmut@tyndur.org> References: <1251125721-6263-1-git-send-email-hartmut@tyndur.org> Message-ID: <4A92C907.20808@tyndur.org> Alexander Hartmut Kluth schrieb: > ! Leerzeichen am Ende werden nun entfernt. Nicht sehr schön, tutet aber > > Signed-off-by: Alexander Hartmut Kluth > --- > src/modules/c/shell/shell.c | 26 ++++++++++++++++++++------ > 1 files changed, 20 insertions(+), 6 deletions(-) > > diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c > index 9d5583a..3560aea 100644 > --- a/src/modules/c/shell/shell.c > +++ b/src/modules/c/shell/shell.c > @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) > strcpy(shell_command_buffer, argv[2]); > shell_do_cmd(); > } > - > + > return 0; > } > > @@ -144,7 +144,8 @@ void shell_read_command(void) > char* cwd = getcwd(NULL, 0); > char* prompt; > char* input; > - > + int i; > + > asprintf(&prompt, "%s # ", cwd); > > input = readline(prompt); > @@ -153,6 +154,19 @@ void shell_read_command(void) > add_history(input); > } > > + if ((strlen(input)) > 2) { > + for (i = strlen(input) - 1; i >= 0; i--) { > + if (input[i] != ' ') { > + input[i+1] = 0; > + break; > + } > + } > + > + if (i == 0) { > + input[0] = 0; > + } > + } > + > Wie in #niwohlos erklärt, ist das nicht ganz richtig und wird bei einem String wie "x " fehlschlagen. Die "strlen() > 2"-Prüfung kann weg, dafür muss das zweite if-Statement so aussehen: if ((i == 0) && (input[0] == ' ')) { input[0] = 0; } > strncpy(shell_command_buffer, input, COMMAND_BUFFER_SIZE); > free(input); > } else { > @@ -200,7 +214,7 @@ bool shell_match_command(const char* cmd, const char* cmdline) > cmd++; > cmdline++; > } > - > + > // Kommt nie vor. > return FALSE; > } > @@ -263,6 +277,7 @@ int shell_do_cmd(void) > return 0; > } > > + > // Die Liste mit den Befehlen durchsuchen. Das wird solange gemacht, bis > // der NULL eintrag am Ende erreicht wird. > for (i = 0; (command = &shell_commands[i]) && (command->name); i++) > @@ -280,7 +295,7 @@ int shell_do_cmd(void) > argc++; > } > } > - > + > char* argv[argc]; > argv[0] = strtok(args, " "); > for(pos = 1; pos < argc; pos++) > @@ -291,13 +306,12 @@ int shell_do_cmd(void) > while (argv[argc - 1] == NULL) { > argc--; > } > - > + > return command->handler(argc, argv, cmdstring); > } > } > return shell_command_default(0, 0, cmdstring); > } > - > /** > * Shell-Skript ausfuehren > * > -- Max Reitz From hartmut at tyndur.org Mon Aug 24 19:37:26 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Mon, 24 Aug 2009 19:37:26 +0200 Subject: [tyndur-devel] [PATCH] losh, shell.c Message-ID: <1251135446-23504-1-git-send-email-hartmut@tyndur.org> ! Leerzeichen am Ende werden nun entfernt. Dank XanClic nun auch richtig ;-) Signed-off-by: Alexander Hartmut Kluth --- src/modules/c/shell/shell.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index 9d5583a..f5bd5b7 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) strcpy(shell_command_buffer, argv[2]); shell_do_cmd(); } - + return 0; } @@ -144,7 +144,8 @@ void shell_read_command(void) char* cwd = getcwd(NULL, 0); char* prompt; char* input; - + int i; + asprintf(&prompt, "%s # ", cwd); input = readline(prompt); @@ -153,6 +154,18 @@ void shell_read_command(void) add_history(input); } + for (i = strlen(input) - 1; i >= 0; i--) { + if (input[i] != ' ') { + input[i+1] = 0; + break; + } + } + + if ((i == 0) && (input[0] == ' ')) { + input[0] = 0; + + + strncpy(shell_command_buffer, input, COMMAND_BUFFER_SIZE); free(input); } else { @@ -200,7 +213,7 @@ bool shell_match_command(const char* cmd, const char* cmdline) cmd++; cmdline++; } - + // Kommt nie vor. return FALSE; } @@ -263,6 +276,7 @@ int shell_do_cmd(void) return 0; } + // Die Liste mit den Befehlen durchsuchen. Das wird solange gemacht, bis // der NULL eintrag am Ende erreicht wird. for (i = 0; (command = &shell_commands[i]) && (command->name); i++) @@ -280,7 +294,7 @@ int shell_do_cmd(void) argc++; } } - + char* argv[argc]; argv[0] = strtok(args, " "); for(pos = 1; pos < argc; pos++) @@ -291,13 +305,12 @@ int shell_do_cmd(void) while (argv[argc - 1] == NULL) { argc--; } - + return command->handler(argc, argv, cmdstring); } } return shell_command_default(0, 0, cmdstring); } - /** * Shell-Skript ausfuehren * -- 1.6.0.4 From hartmut at tyndur.org Mon Aug 24 19:45:01 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Mon, 24 Aug 2009 19:45:01 +0200 Subject: [tyndur-devel] [PATCH] losh, shell.c Message-ID: <1251135901-23916-1-git-send-email-hartmut@tyndur.org> ! Leerzeichen am Ende werden nun entfernt. Dank XanClic nun auch richtig ;-) Signed-off-by: Alexander Hartmut Kluth --- src/modules/c/shell/shell.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index 9d5583a..de9873d 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) strcpy(shell_command_buffer, argv[2]); shell_do_cmd(); } - + return 0; } @@ -144,7 +144,8 @@ void shell_read_command(void) char* cwd = getcwd(NULL, 0); char* prompt; char* input; - + int i; + asprintf(&prompt, "%s # ", cwd); input = readline(prompt); @@ -153,6 +154,18 @@ void shell_read_command(void) add_history(input); } + for (i = strlen(input) - 1; i >= 0; i--) { + if (input[i] != ' ') { + input[i+1] = 0; + break; + } + } + + if ((i == 0) && (input[0] == ' ')) { + input[0] = 0; + } + + strncpy(shell_command_buffer, input, COMMAND_BUFFER_SIZE); free(input); } else { @@ -200,7 +213,7 @@ bool shell_match_command(const char* cmd, const char* cmdline) cmd++; cmdline++; } - + // Kommt nie vor. return FALSE; } @@ -263,6 +276,7 @@ int shell_do_cmd(void) return 0; } + // Die Liste mit den Befehlen durchsuchen. Das wird solange gemacht, bis // der NULL eintrag am Ende erreicht wird. for (i = 0; (command = &shell_commands[i]) && (command->name); i++) @@ -280,7 +294,7 @@ int shell_do_cmd(void) argc++; } } - + char* argv[argc]; argv[0] = strtok(args, " "); for(pos = 1; pos < argc; pos++) @@ -291,13 +305,12 @@ int shell_do_cmd(void) while (argv[argc - 1] == NULL) { argc--; } - + return command->handler(argc, argv, cmdstring); } } return shell_command_default(0, 0, cmdstring); } - /** * Shell-Skript ausfuehren * -- 1.6.0.4 From max at tyndur.org Mon Aug 24 19:47:29 2009 From: max at tyndur.org (Max Reitz) Date: Mon, 24 Aug 2009 19:47:29 +0200 Subject: [tyndur-devel] [PATCH] losh, shell.c In-Reply-To: <1251135901-23916-1-git-send-email-hartmut@tyndur.org> References: <1251135901-23916-1-git-send-email-hartmut@tyndur.org> Message-ID: <4A92D231.8030202@tyndur.org> Alexander Hartmut Kluth schrieb: > ! Leerzeichen am Ende werden nun entfernt. Dank XanClic nun auch richtig ;-) > > Signed-off-by: Alexander Hartmut Kluth > --- > src/modules/c/shell/shell.c | 25 +++++++++++++++++++------ > 1 files changed, 19 insertions(+), 6 deletions(-) > > diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c > index 9d5583a..de9873d 100644 > --- a/src/modules/c/shell/shell.c > +++ b/src/modules/c/shell/shell.c > @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) > strcpy(shell_command_buffer, argv[2]); > shell_do_cmd(); > } > - > + > return 0; > } > > @@ -144,7 +144,8 @@ void shell_read_command(void) > char* cwd = getcwd(NULL, 0); > char* prompt; > char* input; > - > + int i; > + > asprintf(&prompt, "%s # ", cwd); > > input = readline(prompt); > @@ -153,6 +154,18 @@ void shell_read_command(void) > add_history(input); > } > > + for (i = strlen(input) - 1; i >= 0; i--) { > + if (input[i] != ' ') { > + input[i+1] = 0; > + break; > + } > + } > + > + if ((i == 0) && (input[0] == ' ')) { > + input[0] = 0; > + } > + > + > strncpy(shell_command_buffer, input, COMMAND_BUFFER_SIZE); > free(input); > } else { > @@ -200,7 +213,7 @@ bool shell_match_command(const char* cmd, const char* cmdline) > cmd++; > cmdline++; > } > - > + > // Kommt nie vor. > return FALSE; > } > @@ -263,6 +276,7 @@ int shell_do_cmd(void) > return 0; > } > > + > // Die Liste mit den Befehlen durchsuchen. Das wird solange gemacht, bis > // der NULL eintrag am Ende erreicht wird. > for (i = 0; (command = &shell_commands[i]) && (command->name); i++) > @@ -280,7 +294,7 @@ int shell_do_cmd(void) > argc++; > } > } > - > + > char* argv[argc]; > argv[0] = strtok(args, " "); > for(pos = 1; pos < argc; pos++) > @@ -291,13 +305,12 @@ int shell_do_cmd(void) > while (argv[argc - 1] == NULL) { > argc--; > } > - > + > return command->handler(argc, argv, cmdstring); > } > } > return shell_command_default(0, 0, cmdstring); > } > - > /** > * Shell-Skript ausfuehren > * Acked-by: Max Reitz From hartmut at tyndur.org Tue Aug 25 02:37:55 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Tue, 25 Aug 2009 02:37:55 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_Interpreter_f=C3=BCr_HQ9+?= Message-ID: <1251160675-22437-1-git-send-email-hartmut@tyndur.org> + c: Ein Interpreter für die multifunktionelle Sprache HQ9+ Signed-off-by: Alexander Hartmut Kluth --- src/modules/c/hq9+/Makefile.all | 7 ++ src/modules/c/hq9+/main.c | 164 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/hq9+/Makefile.all create mode 100644 src/modules/c/hq9+/main.c diff --git a/src/modules/c/hq9+/Makefile.all b/src/modules/c/hq9+/Makefile.all new file mode 100644 index 0000000..ea43dc1 --- /dev/null +++ b/src/modules/c/hq9+/Makefile.all @@ -0,0 +1,7 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/hq9+" +$LOST_TOOLS_LD -ohq9+ -Ttext=0x40000000 *.o --start-group $2 --end-group + +mv hq9+ $1/apps/ diff --git a/src/modules/c/hq9+/main.c b/src/modules/c/hq9+/main.c new file mode 100644 index 0000000..1b1df33 --- /dev/null +++ b/src/modules/c/hq9+/main.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Hartmut Kluth. + * + * 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. + */ +#include +#include + + +void usage(void); +void print_99_bottles_of_beer(void); + +int main(int argc, char* argv[]) +{ + FILE* srcfp; + char instruction; + char inst_buffer[2048]; + int line = 0, cur_inst_num, all_inst_num; + int accumulator = 0; + + if (argc < 2) { + usage(); + + return -1; + } + + srcfp = fopen(argv[1], "r"); + + if (srcfp == NULL) { + fprintf(stderr, "Fehler: Konnte %s nicht öffnen!\n", argv[1]); + + return EXIT_FAILURE; + } + + cur_inst_num = 0; + + // Erstmal komplette Datei einlesen + while ((instruction = fgetc(srcfp))) { + inst_buffer[cur_inst_num++] = instruction; + + // Bei Befehl 2048 angekommen? Buffer voll, Speicher abbrechen + if (cur_inst_num == 2048) { + break; + } + } + + fclose(srcfp); + + // Speichere die Nummer des letzten Befehls + all_inst_num = cur_inst_num; + + for (cur_inst_num = 0; cur_inst_num < all_inst_num; cur_inst_num++) { + if (inst_buffer[cur_inst_num] == 'H' || + inst_buffer[cur_inst_num] == 'h') { + printf("Hallo Welt!\n"); + } else if (inst_buffer[cur_inst_num] == 'Q' || + inst_buffer[cur_inst_num] == 'q') { + int i; + + for (i = 0; i <= all_inst_num; i++) { + printf("%c", inst_buffer[i]); + } + } else if (inst_buffer[cur_inst_num] == '9') { + print_99_bottles_of_beer(); + } else if (inst_buffer[cur_inst_num] == '+') { + accumulator++; + } else if (inst_buffer[cur_inst_num] == '\n') { + line++; + } else if (inst_buffer[cur_inst_num] == ' ') { + + } else { + if (inst_buffer[cur_inst_num] == '\0') { + break; + } + + fprintf(stderr, "Unknown instruction %c, number %i at line %i\n", + inst_buffer[cur_inst_num], cur_inst_num, line); + break; + } + } + + return EXIT_SUCCESS; +} + + +void usage() +{ + printf("Benutzung: hq9+ DATEINAME\n"); +} + + +void print_99_bottles_of_beer() +{ + int i; + + for (i = 99; i >= 0; i--) { + printf("%i Bottle", i); + + if (i == 1) { + printf(" "); + } else { + printf("s "); + } + + printf("of beer on the wall, %i Bottle", i); + + if (i == 1) { + printf(" "); + } else { + printf("s "); + } + + printf("of beer.\n"); + + if (i == 0) { + printf( + "Go to the store and buy some more, 99 bottles of beer on the wall." + ); + } else { + int temp = i - 1; + + printf("Take one down and pass it aroud, %i bottle", temp); + + if (temp == 1) { + printf(" "); + } else { + printf("s "); + } + + printf("of beer on the wall.\n"); + } + } +} + + -- 1.6.0.4 From max at tyndur.org Sun Aug 30 13:53:22 2009 From: max at tyndur.org (max at tyndur.org) Date: Sun, 30 Aug 2009 13:53:22 +0200 Subject: [tyndur-devel] [PATCH] Mehrere ISRs pro IRQ Message-ID: <1251633202-21166-1-git-send-email-max@tyndur.org> From: Max Reitz Signed-off-by: Max Reitz --- src/kernel/src/intr.c | 76 +++++++++++++++++++++++++++++++------------------ 1 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/kernel/src/intr.c b/src/kernel/src/intr.c index 9fa3ff3..be90e8c 100644 --- a/src/kernel/src/intr.c +++ b/src/kernel/src/intr.c @@ -38,6 +38,7 @@ */ #include "cpu.h" +#include #include "ports.h" #include "types.h" #include "kernel.h" @@ -65,8 +66,8 @@ typedef struct { gate_descriptor idt[IDT_SIZE]; -pfIrqHandler irq_handlers[16] = { 0 }; // für jeden IRQ genau ein Handler. Wenn es keinen Handler gibt, ist der entsprechende Wert 0. -struct task * intr_handling_task[256] = { NULL }; +static list_t* irq_handlers[16] = { NULL }; +list_t* intr_handling_task[256] = { NULL }; void handle_irq(int irq, dword* esp); @@ -120,7 +121,7 @@ dword irqs_to_send[16]; extern dword kernel_pd_id; /* - * gibt einen neuen Wert für esp zurck + * gibt einen neuen Wert fuer esp zurck */ dword handle_int(dword esp) { @@ -146,7 +147,7 @@ dword handle_int(dword esp) } else { - // TODO: Abstürzen, denn diese Interrupts dürften nicht aufgerufen werden + // TODO: Abstuerzen, denn diese Interrupts duerften nicht aufgerufen werden } send_irqs(&esp); @@ -186,11 +187,11 @@ dword handle_int(dword esp) /** * Legt eine IDT an und installiert die Exception Handler. Nicht genutzte - * Einträge werden mit Verweisen auf den Null-Handler initalisiert. - * Anschließend wird die IDT geladen. + * Eintraege werden mit Verweisen auf den Null-Handler initalisiert. + * Anschliessend wird die IDT geladen. */ void init_idt() { - int i; + int i; // Tabelle initialisieren for (i = 0; i < IDT_SIZE; i++) @@ -198,7 +199,7 @@ void init_idt() { set_intr(i, 0x08, &null_handler, 0, IDT_INTERRUPT_GATE); } - // Register befllen + // Register befuellen struct { word size; dword base; @@ -265,9 +266,9 @@ void init_idt() { outb_wait(PIC1_DATA, 0x00); outb_wait(PIC2_DATA, 0x00); - // Handler für den System Call installieren + // Handler fuer den System Call installieren // TODO: SOllte eigentlich ein IDT_TRAP_GATE sein, aber irgendwo ist da - // noch ein Problem, das dann für einen Page Fault sorgt, wenn ich zu + // noch ein Problem, das dann fuer einen Page Fault sorgt, wenn ich zu // schnell tippe... set_intr(SYSCALL_INTERRUPT, 0x08, syscall_stub, 3, IDT_INTERRUPT_GATE); //set_intr(SYSCALL_INTERRUPT, 0x08, syscall_stub, 3, IDT_TRAP_GATE); @@ -323,26 +324,29 @@ int request_irq(int irq, void * handler) return 1; } - if(irq_handlers[irq] != 0) - { - return 1; + if (irq_handlers[irq] == NULL) { + irq_handlers[irq] = list_create(); } - irq_handlers[irq] = handler; + list_push(irq_handlers[irq], handler); return 0; } int release_irq(int irq) { - if(irq < 0 || irq > 15) + /*if(irq < 0 || irq > 15) { return 1; } irq_handlers[irq] = 0; - return 0; + return 0;*/ + + //FIXME Ich weiss ja nicht, wer das braucht. Aber wenn es noetig ist, dann + //muesste man das in release_irq(int irq, void* handler) oder sowas aendern + return 1; } @@ -361,7 +365,7 @@ void handle_irq(int irq, dword* esp) } }*/ - // IRQs 7 und 15 können unabsichtlich aufgerufen werden + // IRQs 7 und 15 koennen unabsichtlich aufgerufen werden // In diesem Fall beim PIC nachschauen, ob wirklich was zu verarbeiten // ist, ansonsten gleich wieder abbrechen. if ((irq == 7) || (irq == 15)) @@ -386,9 +390,16 @@ void handle_irq(int irq, dword* esp) //printf("disable IRQ %d\n", irq); disable_irq(irq); } - else if (irq_handlers[irq] != 0) + else if (irq_handlers[irq] != NULL) { - irq_handlers[irq](irq, esp); + int i; + pfIrqHandler handler; + + for (i = 0; (handler = list_get_element_at(irq_handlers[irq], i)) + != NULL; i++) + { + handler(irq, esp); + } } send_eoi: @@ -402,7 +413,10 @@ send_eoi: void set_intr_handling_task(byte intr, struct task * task) { //kprintf("Interrupt %d wird jetzt von Task %d behandelt\n", intr, task->pid); - intr_handling_task[intr] = task; + if (intr_handling_task[intr] == NULL) { + intr_handling_task[intr] = list_create(); + } + list_push(intr_handling_task[intr], task); } void handle_exception(dword* esp) @@ -426,7 +440,7 @@ void handle_exception(dword* esp) case 14: cr2 = read_cr2(); diff = (cr2 >> PAGE_SHIFT) - (isf->esp >> PAGE_SHIFT); - // Ueberprüfen ob der Pagefault durch einen Stackoverflow + // Ueberpruefen, ob der Pagefault durch einen Stackoverflow // hervorgerufen wurde if ((diff >= -2) && (diff <= 2) && (current_task != NULL) @@ -440,7 +454,7 @@ void handle_exception(dword* esp) break; } - // Prüfen, ob ein VM86-Task die Exception ausgelöst hat, und evtl reagieren + // Pruefen, ob ein VM86-Task die Exception ausgeloest hat, und evtl reagieren if (isf->eflags & 0x20000) { if (vm86_exception(esp)) { return; @@ -512,19 +526,25 @@ void handle_exception(dword* esp) void send_irqs(dword* esp) { + int i; + struct task* tsk; dword irq; for (irq = 0; irq < 16; irq++) { dword rpc_data = irq + IRQ_BASE; while (irqs_to_send[irq] > 0) { - schedule_to_task(intr_handling_task[irq + IRQ_BASE], esp); - if (!fastrpc_irq(intr_handling_task[irq + IRQ_BASE], 0, 0, 4, - (char*) &rpc_data, irq)) + for (i = 0; (tsk = list_get_element_at( + intr_handling_task[irq + IRQ_BASE], i)) != NULL; i++) { - //kprintf("SYSCALL_RPC = FALSE"); - break; + schedule_to_task(tsk, esp); + if (!fastrpc_irq(tsk, 0, 0, 4, + (char*) &rpc_data, irq)) + { + //kprintf("SYSCALL_RPC = FALSE"); + break; + } + //kprintf("IRQ-Handler aufgerufen"); } - //kprintf("IRQ-Handler aufgerufen"); irqs_to_send[irq]--; } } -- 1.6.3.3 From kevin at tyndur.org Sun Aug 30 15:21:58 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 30 Aug 2009 15:21:58 +0200 Subject: [tyndur-devel] [PATCH] Mehrere ISRs pro IRQ In-Reply-To: <1251633202-21166-1-git-send-email-max@tyndur.org> References: <1251633202-21166-1-git-send-email-max@tyndur.org> Message-ID: <20090830132154.GA9411@silvanus> On Sun, Aug 30, 2009 at 01:53:22PM +0200, max at tyndur.org wrote: > From: Max Reitz > > Signed-off-by: Max Reitz > --- > src/kernel/src/intr.c | 76 +++++++++++++++++++++++++++++++------------------ > 1 files changed, 48 insertions(+), 28 deletions(-) > > diff --git a/src/kernel/src/intr.c b/src/kernel/src/intr.c > index 9fa3ff3..be90e8c 100644 > --- a/src/kernel/src/intr.c > +++ b/src/kernel/src/intr.c > @@ -38,6 +38,7 @@ > */ > > #include "cpu.h" > +#include > #include "ports.h" > #include "types.h" > #include "kernel.h" > @@ -65,8 +66,8 @@ typedef struct { > > gate_descriptor idt[IDT_SIZE]; > > -pfIrqHandler irq_handlers[16] = { 0 }; // f?r jeden IRQ genau ein Handler. Wenn es keinen Handler gibt, ist der entsprechende Wert 0. > -struct task * intr_handling_task[256] = { NULL }; > +static list_t* irq_handlers[16] = { NULL }; > +list_t* intr_handling_task[256] = { NULL }; Der kann auch static sein, wenn wir schon dabei sind, oder? > > void handle_irq(int irq, dword* esp); > > @@ -120,7 +121,7 @@ dword irqs_to_send[16]; > extern dword kernel_pd_id; > > /* > - * gibt einen neuen Wert f?r esp zurck > + * gibt einen neuen Wert fuer esp zurck > */ > dword handle_int(dword esp) > { > @@ -146,7 +147,7 @@ dword handle_int(dword esp) > } > else > { > - // TODO: Abst?rzen, denn diese Interrupts d?rften nicht aufgerufen werden > + // TODO: Abstuerzen, denn diese Interrupts duerften nicht aufgerufen werden > } > > send_irqs(&esp); > @@ -186,11 +187,11 @@ dword handle_int(dword esp) > > /** > * Legt eine IDT an und installiert die Exception Handler. Nicht genutzte > - * Eintr?ge werden mit Verweisen auf den Null-Handler initalisiert. > - * Anschlie?end wird die IDT geladen. > + * Eintraege werden mit Verweisen auf den Null-Handler initalisiert. > + * Anschliessend wird die IDT geladen. > */ > void init_idt() { > - int i; > + int i; Die Einrückung ist vorher und nachher nicht korrekt. ;-) > > // Tabelle initialisieren > for (i = 0; i < IDT_SIZE; i++) > @@ -198,7 +199,7 @@ void init_idt() { > set_intr(i, 0x08, &null_handler, 0, IDT_INTERRUPT_GATE); > } > > - // Register befllen > + // Register befuellen > struct { > word size; > dword base; > @@ -265,9 +266,9 @@ void init_idt() { > outb_wait(PIC1_DATA, 0x00); > outb_wait(PIC2_DATA, 0x00); > > - // Handler f?r den System Call installieren > + // Handler fuer den System Call installieren > // TODO: SOllte eigentlich ein IDT_TRAP_GATE sein, aber irgendwo ist da > - // noch ein Problem, das dann f?r einen Page Fault sorgt, wenn ich zu > + // noch ein Problem, das dann fuer einen Page Fault sorgt, wenn ich zu > // schnell tippe... > set_intr(SYSCALL_INTERRUPT, 0x08, syscall_stub, 3, IDT_INTERRUPT_GATE); > //set_intr(SYSCALL_INTERRUPT, 0x08, syscall_stub, 3, IDT_TRAP_GATE); > @@ -323,26 +324,29 @@ int request_irq(int irq, void * handler) > return 1; > } > > - if(irq_handlers[irq] != 0) > - { > - return 1; > + if (irq_handlers[irq] == NULL) { > + irq_handlers[irq] = list_create(); > } > > - irq_handlers[irq] = handler; > + list_push(irq_handlers[irq], handler); > > return 0; > } > > int release_irq(int irq) > { > - if(irq < 0 || irq > 15) > + /*if(irq < 0 || irq > 15) > { > return 1; > } > > irq_handlers[irq] = 0; > > - return 0; > + return 0;*/ > + > + //FIXME Ich weiss ja nicht, wer das braucht. Aber wenn es noetig ist, dann > + //muesste man das in release_irq(int irq, void* handler) oder sowas aendern > + return 1; > } Dann änder den Prototypen eben ab. FIXMEs für triviale Sachen mag ich nicht so. > > > @@ -361,7 +365,7 @@ void handle_irq(int irq, dword* esp) > } > }*/ > > - // IRQs 7 und 15 k?nnen unabsichtlich aufgerufen werden > + // IRQs 7 und 15 koennen unabsichtlich aufgerufen werden > // In diesem Fall beim PIC nachschauen, ob wirklich was zu verarbeiten > // ist, ansonsten gleich wieder abbrechen. > if ((irq == 7) || (irq == 15)) > @@ -386,9 +390,16 @@ void handle_irq(int irq, dword* esp) > //printf("disable IRQ %d\n", irq); > disable_irq(irq); > } > - else if (irq_handlers[irq] != 0) > + else if (irq_handlers[irq] != NULL) else if ist jetzt nicht mehr richtig. Es könnte sowohl für den Kernel als auch für ein Modul ein Handler installiert sein. > { > - irq_handlers[irq](irq, esp); > + int i; > + pfIrqHandler handler; > + > + for (i = 0; (handler = list_get_element_at(irq_handlers[irq], i)) > + != NULL; i++) > + { > + handler(irq, esp); > + } > } > > send_eoi: > @@ -402,7 +413,10 @@ send_eoi: > void set_intr_handling_task(byte intr, struct task * task) > { > //kprintf("Interrupt %d wird jetzt von Task %d behandelt\n", intr, task->pid); > - intr_handling_task[intr] = task; > + if (intr_handling_task[intr] == NULL) { > + intr_handling_task[intr] = list_create(); > + } > + list_push(intr_handling_task[intr], task); > } > > void handle_exception(dword* esp) > @@ -426,7 +440,7 @@ void handle_exception(dword* esp) > case 14: > cr2 = read_cr2(); > diff = (cr2 >> PAGE_SHIFT) - (isf->esp >> PAGE_SHIFT); > - // Ueberpr?fen ob der Pagefault durch einen Stackoverflow > + // Ueberpruefen, ob der Pagefault durch einen Stackoverflow > // hervorgerufen wurde > if ((diff >= -2) && (diff <= 2) > && (current_task != NULL) > @@ -440,7 +454,7 @@ void handle_exception(dword* esp) > break; > } > > - // Pr?fen, ob ein VM86-Task die Exception ausgel?st hat, und evtl reagieren > + // Pruefen, ob ein VM86-Task die Exception ausgeloest hat, und evtl reagieren > if (isf->eflags & 0x20000) { > if (vm86_exception(esp)) { > return; > @@ -512,19 +526,25 @@ void handle_exception(dword* esp) > > void send_irqs(dword* esp) > { > + int i; > + struct task* tsk; > dword irq; > for (irq = 0; irq < 16; irq++) > { > dword rpc_data = irq + IRQ_BASE; > while (irqs_to_send[irq] > 0) { > - schedule_to_task(intr_handling_task[irq + IRQ_BASE], esp); > - if (!fastrpc_irq(intr_handling_task[irq + IRQ_BASE], 0, 0, 4, > - (char*) &rpc_data, irq)) > + for (i = 0; (tsk = list_get_element_at( > + intr_handling_task[irq + IRQ_BASE], i)) != NULL; i++) > { > - //kprintf("SYSCALL_RPC = FALSE"); > - break; > + schedule_to_task(tsk, esp); > + if (!fastrpc_irq(tsk, 0, 0, 4, > + (char*) &rpc_data, irq)) Der Zeilenumbruch kommt mir überflüssig vor > + { > + //kprintf("SYSCALL_RPC = FALSE"); > + break; Wenn der zweite IRQ-Handler beim ersten Versuch scheitert, wird der erste Handler zweimal aufgerufen. Bin mir aber nicht sicher, ob es sich lohnt, das zu fixen - die Treiber müssen eh damit umgehen können, wenn zu viele Interrupts kommen.