You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(35) |
Dec
(2) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(37) |
Feb
(10) |
Mar
|
Apr
(2) |
May
(17) |
Jun
(1) |
Jul
(14) |
Aug
(14) |
Sep
(4) |
Oct
|
Nov
(14) |
Dec
(4) |
2005 |
Jan
(6) |
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(92) |
Dec
(12) |
2006 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
(5) |
May
(3) |
Jun
(15) |
Jul
(3) |
Aug
(1) |
Sep
(29) |
Oct
(1) |
Nov
(6) |
Dec
(5) |
2007 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(3) |
May
(14) |
Jun
(2) |
Jul
(16) |
Aug
(73) |
Sep
(12) |
Oct
(9) |
Nov
(27) |
Dec
(3) |
2008 |
Jan
(4) |
Feb
(4) |
Mar
(3) |
Apr
(8) |
May
(23) |
Jun
(4) |
Jul
(1) |
Aug
(3) |
Sep
(7) |
Oct
(5) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
|
Feb
(10) |
Mar
|
Apr
(4) |
May
(4) |
Jun
(10) |
Jul
|
Aug
(1) |
Sep
|
Oct
(7) |
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
|
Jun
(3) |
Jul
(11) |
Aug
(1) |
Sep
|
Oct
(15) |
Nov
(1) |
Dec
(5) |
2011 |
Jan
(4) |
Feb
(1) |
Mar
(6) |
Apr
|
May
(22) |
Jun
|
Jul
(8) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2012 |
Jan
|
Feb
(10) |
Mar
(1) |
Apr
(6) |
May
(27) |
Jun
(48) |
Jul
(30) |
Aug
(4) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
(11) |
2013 |
Jan
(4) |
Feb
(7) |
Mar
(6) |
Apr
(18) |
May
(28) |
Jun
(20) |
Jul
|
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
(7) |
2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(9) |
May
(11) |
Jun
(10) |
Jul
|
Aug
(18) |
Sep
(12) |
Oct
(17) |
Nov
(10) |
Dec
(16) |
2015 |
Jan
(5) |
Feb
(1) |
Mar
(5) |
Apr
(4) |
May
(28) |
Jun
(2) |
Jul
|
Aug
|
Sep
(6) |
Oct
|
Nov
(2) |
Dec
(1) |
2016 |
Jan
(14) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
(1) |
2017 |
Jan
(11) |
Feb
|
Mar
(21) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(2) |
Sep
(4) |
Oct
(4) |
Nov
|
Dec
(1) |
2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(13) |
Sep
(4) |
Oct
|
Nov
|
Dec
|
2020 |
Jan
(10) |
Feb
(9) |
Mar
(5) |
Apr
(4) |
May
(3) |
Jun
(18) |
Jul
(4) |
Aug
(2) |
Sep
(20) |
Oct
(2) |
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2022 |
Jan
(1) |
Feb
(2) |
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
2023 |
Jan
(10) |
Feb
(7) |
Mar
(29) |
Apr
(31) |
May
(29) |
Jun
(34) |
Jul
(3) |
Aug
(24) |
Sep
(22) |
Oct
(10) |
Nov
(38) |
Dec
(27) |
2024 |
Jan
(15) |
Feb
(8) |
Mar
(4) |
Apr
(20) |
May
(33) |
Jun
(18) |
Jul
(15) |
Aug
(23) |
Sep
(26) |
Oct
(32) |
Nov
(6) |
Dec
(4) |
2025 |
Jan
(7) |
Feb
(1) |
Mar
(1) |
Apr
(4) |
May
(46) |
Jun
(19) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ljs...@us...> - 2012-06-02 03:32:12
|
Revision: 792 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=792&view=rev Author: ljsebald Date: 2012-06-02 03:32:06 +0000 (Sat, 02 Jun 2012) Log Message: ----------- Make DHCP shutdown clean things up a bit nicer... Modified Paths: -------------- kos/kernel/net/net_dhcp.c Modified: kos/kernel/net/net_dhcp.c =================================================================== --- kos/kernel/net/net_dhcp.c 2012-06-02 03:31:11 UTC (rev 791) +++ kos/kernel/net/net_dhcp.c 2012-06-02 03:32:06 UTC (rev 792) @@ -652,11 +652,15 @@ } void net_dhcp_shutdown() { - if(dhcp_cbid != -1) + if(dhcp_cbid != -1) { net_thd_del_callback(dhcp_cbid); + dhcp_cbid = -1; + } - if(dhcp_sock != -1) + if(dhcp_sock != -1) { close(dhcp_sock); + dhcp_sock = -1; + } if(dhcp_lock) { rlock_destroy(dhcp_lock); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-06-02 03:31:17
|
Revision: 791 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=791&view=rev Author: ljsebald Date: 2012-06-02 03:31:11 +0000 (Sat, 02 Jun 2012) Log Message: ----------- Two small things in thread creation: 1. Make sure that the malloc of the stack succeeds. If not, then don't continue creating the thread. 2. Give irq_create_context() the right size argument array. Modified Paths: -------------- kos/kernel/thread/thread.c Modified: kos/kernel/thread/thread.c =================================================================== --- kos/kernel/thread/thread.c 2012-06-02 03:29:18 UTC (rev 790) +++ kos/kernel/thread/thread.c 2012-06-02 03:31:11 UTC (rev 791) @@ -311,7 +311,7 @@ kthread_t *thd_create(int detach, void *(*routine)(void *param), void *param) { kthread_t *nt = NULL; tid_t tid; - uint32 params[2]; + uint32 params[4]; int oldirq = 0; oldirq = irq_disable(); @@ -327,11 +327,19 @@ /* Create a new thread stack */ nt->stack = (uint32*)malloc(THD_STACK_SIZE); + if(!nt->stack) { + free(nt); + irq_restore(oldirq); + return NULL; + } + nt->stack_size = THD_STACK_SIZE; /* Populate the context */ params[0] = (uint32)routine; params[1] = (uint32)param; + params[2] = 0; + params[3] = 0; irq_create_context(&nt->context, ((uint32)nt->stack)+nt->stack_size, (uint32)thd_birth, params, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-06-02 03:29:24
|
Revision: 790 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=790&view=rev Author: ljsebald Date: 2012-06-02 03:29:18 +0000 (Sat, 02 Jun 2012) Log Message: ----------- Change the default stack size from 8192 bytes to 32768. Simply put, the old value would make it so that you could not safely ever open any files in a thread. The fs_open() function (and its child calls) would end up creating a stack frame that was more than 8192 bytes in size, which would mean that random other malloc'd blocks end up getting written over. This lead to all kinds of random bugs that were quite hard to trace, until I narrowed it down to calling fs_open as breaking things. I'm actually really surprised that nobody noticed this before... Make sure that you completely rebuild KOS after updating to this revision (make clean all). Modified Paths: -------------- kos/kernel/arch/dreamcast/include/arch/arch.h Modified: kos/kernel/arch/dreamcast/include/arch/arch.h =================================================================== --- kos/kernel/arch/dreamcast/include/arch/arch.h 2012-06-01 04:33:10 UTC (rev 789) +++ kos/kernel/arch/dreamcast/include/arch/arch.h 2012-06-02 03:29:18 UTC (rev 790) @@ -38,7 +38,7 @@ #define HZ 100 /** \brief Default thread stack size. */ -#define THD_STACK_SIZE 8192 +#define THD_STACK_SIZE 32768 /** \brief Default video mode. */ #define DEFAULT_VID_MODE DM_640x480 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-06-01 04:33:17
|
Revision: 789 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=789&view=rev Author: ljsebald Date: 2012-06-01 04:33:10 +0000 (Fri, 01 Jun 2012) Log Message: ----------- Two things here: 1. Make the reaper thread have a higher priority so it gets run ASAP when a thread needs to be reaped. 2. Free the thread's reent structure the right way. Modified Paths: -------------- kos/kernel/thread/thread.c Modified: kos/kernel/thread/thread.c =================================================================== --- kos/kernel/thread/thread.c 2012-06-01 04:19:36 UTC (rev 788) +++ kos/kernel/thread/thread.c 2012-06-01 04:33:10 UTC (rev 789) @@ -227,9 +227,7 @@ thd_current->rv = rv; /* Call newlib's thread cleanup function */ - if(thd_current->thd_reent.__cleanup) { - thd_current->thd_reent.__cleanup(_impure_ptr); - } + _reclaim_reent(&thd_current->thd_reent); if(thd_current->flags & THD_DETACHED) { /* Call Dr. Kevorkian; after this executes we could be killed @@ -840,7 +838,7 @@ thd_reap_sem = sem_create(0); reaper = thd_create(0, thd_reaper, NULL); strcpy(reaper->label, "[reaper]"); - thd_set_prio(reaper, PRIO_MAX - 1); + thd_set_prio(reaper, 1); /* Main thread -- the kern thread */ thd_current = kern; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <los...@us...> - 2012-06-01 04:19:45
|
Revision: 788 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=788&view=rev Author: lostgeneration Date: 2012-06-01 04:19:36 +0000 (Fri, 01 Jun 2012) Log Message: ----------- Hopefully fixup dcload to work with GCC >= 4.0 * The target discs for dcload ip and serial we're basically unbootable. This hopefully fixes that by using the shelf.x linker script from KOS and changed to use the correct stack address as well as the correct startup address. * The option to use the GCC 3.x toolchain ist still an available option by changing Makefile.cfg's TARGETCCVER. * This isn't very well tested yet, but I was told at least dcload-ip works. Modified Paths: -------------- dcload/dcload-ip/Makefile.cfg dcload/dcload-ip/example-src/Makefile dcload/dcload-ip/target-src/1st_read/Makefile dcload/dcload-ip/target-src/dcload/Makefile dcload/dcload-serial/Makefile.cfg dcload/dcload-serial/example-src/Makefile dcload/dcload-serial/target-src/1st_read/Makefile dcload/dcload-serial/target-src/dcload/Makefile Added Paths: ----------- dcload/dcload-ip/example-src/dc3.x dcload/dcload-ip/example-src/dc4.x dcload/dcload-ip/target-src/1st_read/dc3.x dcload/dcload-ip/target-src/1st_read/dc4.x dcload/dcload-ip/target-src/dcload/dcload3.x dcload/dcload-ip/target-src/dcload/dcload4.x dcload/dcload-serial/example-src/dc3.x dcload/dcload-serial/example-src/dc4.x dcload/dcload-serial/target-src/1st_read/dc3.x dcload/dcload-serial/target-src/1st_read/dc4.x dcload/dcload-serial/target-src/dcload/dcload3.x dcload/dcload-serial/target-src/dcload/dcload4.x Removed Paths: ------------- dcload/dcload-ip/example-src/dc.x dcload/dcload-ip/target-src/1st_read/dc.x dcload/dcload-ip/target-src/dcload/dcload.x dcload/dcload-serial/example-src/dc.x dcload/dcload-serial/target-src/1st_read/dc.x dcload/dcload-serial/target-src/dcload/dcload.x Modified: dcload/dcload-ip/Makefile.cfg =================================================================== --- dcload/dcload-ip/Makefile.cfg 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/Makefile.cfg 2012-06-01 04:19:36 UTC (rev 788) @@ -23,6 +23,8 @@ #BFDINCLUDE = /usr/local/include # sh-elf-stuff + # Replace with 3 if you're using gcc < 4.x +TARGETCCVER = 4 TARGETCC = sh-elf-gcc TARGETCFLAGS = -O2 -ml -m4-single-only TARGETOBJCOPY = sh-elf-objcopy Modified: dcload/dcload-ip/example-src/Makefile =================================================================== --- dcload/dcload-ip/example-src/Makefile 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/example-src/Makefile 2012-06-01 04:19:36 UTC (rev 788) @@ -28,13 +28,13 @@ $(OBJCOPY) -O binary $< $@ console-test: $(OBJECTS) console-test.o - $(CC) $(CFLAGS) -Wl,-Tdc.x -nostartfiles -nostdlib $^ -o $@ -lgcc + $(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc gethostinfo: $(OBJECTS) gethostinfo.o - $(CC) $(CFLAGS) -Wl,-Tdc.x -nostartfiles -nostdlib $^ -o $@ -lgcc + $(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc exception-test: $(OBJECTS) exception-test.o - $(CC) $(CFLAGS) -Wl,-Tdc.x -nostartfiles -nostdlib $^ -o $@ -lgcc + $(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc .PHONY : clean clean: Deleted: dcload/dcload-ip/example-src/dc.x =================================================================== --- dcload/dcload-ip/example-src/dc.x 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/example-src/dc.x 2012-06-01 04:19:36 UTC (rev 788) @@ -1,228 +0,0 @@ -/* Sega Dreamcast linker script */ - -OUTPUT_FORMAT("elf32-shl", "elf32-shl", - "elf32-shl") -OUTPUT_ARCH(sh) -ENTRY(start) - SEARCH_DIR(/usr/local/dcdev/sh-elf/lib); -/* Do we need any of these for elf? - __DYNAMIC = 0; */ - -MEMORY -{ - ram (rwx) : ORIGIN = 0x8c010000, LENGTH = 0xfe0000 -} - -SECTIONS -{ - /* Read-only sections, merged into text segment: */ -/* . = 0x1000;*/ - .interp : { *(.interp) } - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : - { - *(.rel.text) - *(.rel.text.*) - *(.rel.gnu.linkonce.t*) - } - .rela.text : - { - *(.rela.text) - *(.rela.text.*) - *(.rela.gnu.linkonce.t*) - } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : - { - *(.rel.rodata) - *(.rel.rodata.*) - *(.rel.gnu.linkonce.r*) - } - .rela.rodata : - { - *(.rela.rodata) - *(.rela.rodata.*) - *(.rela.gnu.linkonce.r*) - } - .rel.data : - { - *(.rel.data) - *(.rel.data.*) - *(.rel.gnu.linkonce.d*) - } - .rela.data : - { - *(.rela.data) - *(.rela.data.*) - *(.rela.gnu.linkonce.d*) - } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.sdata : - { - *(.rel.sdata) - *(.rel.sdata.*) - *(.rel.gnu.linkonce.s*) - } - .rela.sdata : - { - *(.rela.sdata) - *(.rela.sdata.*) - *(.rela.gnu.linkonce.s*) - } - .rel.sbss : { *(.rel.sbss) } - .rela.sbss : { *(.rela.sbss) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .init : - { - KEEP (*(.init)) - } =0 - .plt : { *(.plt) } - .text : - { - *(.text) - *(.text.*) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - } =0 - _etext = .; - PROVIDE (etext = .); - .fini : - { - KEEP (*(.fini)) - } =0 - .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } - .rodata1 : { *(.rodata1) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(128) + (. & (128 - 1)); - .data : - { - *(.data) - *(.data.*) - *(.gnu.linkonce.d*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - .eh_frame : { *(.eh_frame) } - .gcc_except_table : { *(.gcc_except_table) } - .ctors ALIGN(4): - { - ___ctors = .; - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - /* We don't want to include the .ctor section from - from the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - ___ctors_end = .; - } - .dtors : - { - ___dtors = .; - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - ___dtors_end = .; - } - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : - { - *(.sdata) - *(.sdata.*) - *(.gnu.linkonce.s.*) - } - _edata = .; - PROVIDE (edata = .); - __bss_start = .; - .sbss : - { - *(.dynsbss) - *(.sbss) - *(.sbss.*) - *(.scommon) - } - .bss : - { - *(.dynbss) - *(.bss) - *(.bss.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(32 / 8); - } - . = ALIGN(32 / 8); - _end = .; - PROVIDE (end = .); - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } -/* .stack 0x8c00f400 : { _stack = .; *(.stack) }*/ - /* These must appear regardless of . */ -_stack = 0x8d000000; -} Added: dcload/dcload-ip/example-src/dc3.x =================================================================== --- dcload/dcload-ip/example-src/dc3.x (rev 0) +++ dcload/dcload-ip/example-src/dc3.x 2012-06-01 04:19:36 UTC (rev 788) @@ -0,0 +1,228 @@ +/* Sega Dreamcast linker script */ + +OUTPUT_FORMAT("elf32-shl", "elf32-shl", + "elf32-shl") +OUTPUT_ARCH(sh) +ENTRY(start) + SEARCH_DIR(/usr/local/dcdev/sh-elf/lib); +/* Do we need any of these for elf? + __DYNAMIC = 0; */ + +MEMORY +{ + ram (rwx) : ORIGIN = 0x8c010000, LENGTH = 0xfe0000 +} + +SECTIONS +{ + /* Read-only sections, merged into text segment: */ +/* . = 0x1000;*/ + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.sdata : + { + *(.rel.sdata) + *(.rel.sdata.*) + *(.rel.gnu.linkonce.s*) + } + .rela.sdata : + { + *(.rela.sdata) + *(.rela.sdata.*) + *(.rela.gnu.linkonce.s*) + } + .rel.sbss : { *(.rel.sbss) } + .rela.sbss : { *(.rela.sbss) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .text : + { + *(.text) + *(.text.*) + *(.stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + } =0 + _etext = .; + PROVIDE (etext = .); + .fini : + { + KEEP (*(.fini)) + } =0 + .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } + .rodata1 : { *(.rodata1) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(128) + (. & (128 - 1)); + .data : + { + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + .eh_frame : { *(.eh_frame) } + .gcc_except_table : { *(.gcc_except_table) } + .ctors ALIGN(4): + { + ___ctors = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ___ctors_end = .; + } + .dtors : + { + ___dtors = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ___dtors_end = .; + } + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata : + { + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + } + _edata = .; + PROVIDE (edata = .); + __bss_start = .; + .sbss : + { + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.scommon) + } + .bss : + { + *(.dynbss) + *(.bss) + *(.bss.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. */ + . = ALIGN(32 / 8); + } + . = ALIGN(32 / 8); + _end = .; + PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } +/* .stack 0x8c00f400 : { _stack = .; *(.stack) }*/ + /* These must appear regardless of . */ +_stack = 0x8d000000; +} Property changes on: dcload/dcload-ip/example-src/dc3.x ___________________________________________________________________ Added: svn:eol-style + native Added: dcload/dcload-ip/example-src/dc4.x =================================================================== --- dcload/dcload-ip/example-src/dc4.x (rev 0) +++ dcload/dcload-ip/example-src/dc4.x 2012-06-01 04:19:36 UTC (rev 788) @@ -0,0 +1,228 @@ +/* Script for -z combreloc: combine and sort reloc sections */ +OUTPUT_FORMAT("elf32-shl", "elf32-shl", + "elf32-shl") +OUTPUT_ARCH(sh) +ENTRY(start) +SEARCH_DIR("/usr/local/dc-new/sh-elf/sh-elf/lib"); +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = 0x8c010000); . = 0x8c010000; + .text : + { + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0 + .init : + { + KEEP (*(.init)) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*) + *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*) + *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*) + *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) + *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*) + *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) + *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .plt : { *(.plt) } + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .sdata2 : + { + *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) + } + .sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(128) + (. & (128 - 1)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + ___ctors = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ___ctors_end = .; + } + .dtors : + { + ___dtors = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ___dtors_end = .; + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .data : + { + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + .got : { *(.got.plt) *(.got) } + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata : + { + *(.sdata .sdata.* .gnu.linkonce.s.*) + } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + .sbss : + { + *(.dynsbss) + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + } + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 32 / 8 : 1); + } + . = ALIGN(32 / 8); + . = ALIGN(32 / 8); + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) } +_stack = 0x8d000000; +} Property changes on: dcload/dcload-ip/example-src/dc4.x ___________________________________________________________________ Added: svn:eol-style + native Modified: dcload/dcload-ip/target-src/1st_read/Makefile =================================================================== --- dcload/dcload-ip/target-src/1st_read/Makefile 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/target-src/1st_read/Makefile 2012-06-01 04:19:36 UTC (rev 788) @@ -9,13 +9,13 @@ OBJECTS = crt0.o 1st_read.o disable.o memcpy.o dcload.o exception.o .c.o: - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< .S.o: - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< .s.o: - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< all: 1st_read.bin 1st_read.srec @@ -32,18 +32,18 @@ $(LD) -A sh -b binary --oformat elf32-shl $< -o $@ -r -EL --no-warn-mismatch 1st_read.bin: 1st_read - $(OBJCOPY) -O binary $< $@ + $(OBJCOPY) -O binary $< $@ 1st_read.srec: 1st_read - $(OBJCOPY) -O srec $< $@ + $(OBJCOPY) -O srec $< $@ 1st_read: $(OBJECTS) - $(CC) $(CFLAGS) -Wl,-Tdc.x -nostartfiles -nostdlib $^ -o $@ -lgcc + $(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc .PHONY : clean clean: rm -f $(OBJECTS) 1st_read dcload.bin exception.bin .PHONY : distclean -distclean: clean +distclean: clean rm -f 1st_read.bin 1st_read.srec Deleted: dcload/dcload-ip/target-src/1st_read/dc.x =================================================================== --- dcload/dcload-ip/target-src/1st_read/dc.x 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/target-src/1st_read/dc.x 2012-06-01 04:19:36 UTC (rev 788) @@ -1,228 +0,0 @@ -/* Sega Dreamcast linker script */ - -OUTPUT_FORMAT("elf32-shl", "elf32-shl", - "elf32-shl") -OUTPUT_ARCH(sh) -ENTRY(start) - SEARCH_DIR(/usr/local/dcdev/sh-elf/lib); -/* Do we need any of these for elf? - __DYNAMIC = 0; */ - -MEMORY -{ - ram (rwx) : ORIGIN = 0x8c010000, LENGTH = 0xfe0000 -} - -SECTIONS -{ - /* Read-only sections, merged into text segment: */ -/* . = 0x1000;*/ - .interp : { *(.interp) } - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : - { - *(.rel.text) - *(.rel.text.*) - *(.rel.gnu.linkonce.t*) - } - .rela.text : - { - *(.rela.text) - *(.rela.text.*) - *(.rela.gnu.linkonce.t*) - } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : - { - *(.rel.rodata) - *(.rel.rodata.*) - *(.rel.gnu.linkonce.r*) - } - .rela.rodata : - { - *(.rela.rodata) - *(.rela.rodata.*) - *(.rela.gnu.linkonce.r*) - } - .rel.data : - { - *(.rel.data) - *(.rel.data.*) - *(.rel.gnu.linkonce.d*) - } - .rela.data : - { - *(.rela.data) - *(.rela.data.*) - *(.rela.gnu.linkonce.d*) - } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.sdata : - { - *(.rel.sdata) - *(.rel.sdata.*) - *(.rel.gnu.linkonce.s*) - } - .rela.sdata : - { - *(.rela.sdata) - *(.rela.sdata.*) - *(.rela.gnu.linkonce.s*) - } - .rel.sbss : { *(.rel.sbss) } - .rela.sbss : { *(.rela.sbss) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .init : - { - KEEP (*(.init)) - } =0 - .plt : { *(.plt) } - .text : - { - *(.text) - *(.text.*) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - } =0 - _etext = .; - PROVIDE (etext = .); - .fini : - { - KEEP (*(.fini)) - } =0 - .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } - .rodata1 : { *(.rodata1) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(128) + (. & (128 - 1)); - .data : - { - *(.data) - *(.data.*) - *(.gnu.linkonce.d*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - .eh_frame : { *(.eh_frame) } - .gcc_except_table : { *(.gcc_except_table) } - .ctors ALIGN(4): - { - ___ctors = .; - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - /* We don't want to include the .ctor section from - from the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - ___ctors_end = .; - } - .dtors : - { - ___dtors = .; - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - ___dtors_end = .; - } - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : - { - *(.sdata) - *(.sdata.*) - *(.gnu.linkonce.s.*) - } - _edata = .; - PROVIDE (edata = .); - __bss_start = .; - .sbss : - { - *(.dynsbss) - *(.sbss) - *(.sbss.*) - *(.scommon) - } - .bss : - { - *(.dynbss) - *(.bss) - *(.bss.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(32 / 8); - } - . = ALIGN(32 / 8); - _end = .; - PROVIDE (end = .); - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } -/* .stack 0x8c00f400 : { _stack = .; *(.stack) }*/ - /* These must appear regardless of . */ -_stack = 0x8d000000; -} Added: dcload/dcload-ip/target-src/1st_read/dc3.x =================================================================== --- dcload/dcload-ip/target-src/1st_read/dc3.x (rev 0) +++ dcload/dcload-ip/target-src/1st_read/dc3.x 2012-06-01 04:19:36 UTC (rev 788) @@ -0,0 +1,228 @@ +/* Sega Dreamcast linker script */ + +OUTPUT_FORMAT("elf32-shl", "elf32-shl", + "elf32-shl") +OUTPUT_ARCH(sh) +ENTRY(start) + SEARCH_DIR(/usr/local/dcdev/sh-elf/lib); +/* Do we need any of these for elf? + __DYNAMIC = 0; */ + +MEMORY +{ + ram (rwx) : ORIGIN = 0x8c010000, LENGTH = 0xfe0000 +} + +SECTIONS +{ + /* Read-only sections, merged into text segment: */ +/* . = 0x1000;*/ + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.sdata : + { + *(.rel.sdata) + *(.rel.sdata.*) + *(.rel.gnu.linkonce.s*) + } + .rela.sdata : + { + *(.rela.sdata) + *(.rela.sdata.*) + *(.rela.gnu.linkonce.s*) + } + .rel.sbss : { *(.rel.sbss) } + .rela.sbss : { *(.rela.sbss) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .text : + { + *(.text) + *(.text.*) + *(.stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + } =0 + _etext = .; + PROVIDE (etext = .); + .fini : + { + KEEP (*(.fini)) + } =0 + .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } + .rodata1 : { *(.rodata1) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(128) + (. & (128 - 1)); + .data : + { + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + .eh_frame : { *(.eh_frame) } + .gcc_except_table : { *(.gcc_except_table) } + .ctors ALIGN(4): + { + ___ctors = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ___ctors_end = .; + } + .dtors : + { + ___dtors = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ___dtors_end = .; + } + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata : + { + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + } + _edata = .; + PROVIDE (edata = .); + __bss_start = .; + .sbss : + { + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.scommon) + } + .bss : + { + *(.dynbss) + *(.bss) + *(.bss.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. */ + . = ALIGN(32 / 8); + } + . = ALIGN(32 / 8); + _end = .; + PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } +/* .stack 0x8c00f400 : { _stack = .; *(.stack) }*/ + /* These must appear regardless of . */ +_stack = 0x8d000000; +} Property changes on: dcload/dcload-ip/target-src/1st_read/dc3.x ___________________________________________________________________ Added: svn:eol-style + native Added: dcload/dcload-ip/target-src/1st_read/dc4.x =================================================================== --- dcload/dcload-ip/target-src/1st_read/dc4.x (rev 0) +++ dcload/dcload-ip/target-src/1st_read/dc4.x 2012-06-01 04:19:36 UTC (rev 788) @@ -0,0 +1,228 @@ +/* Script for -z combreloc: combine and sort reloc sections */ +OUTPUT_FORMAT("elf32-shl", "elf32-shl", + "elf32-shl") +OUTPUT_ARCH(sh) +ENTRY(start) +SEARCH_DIR("/usr/local/dc-new/sh-elf/sh-elf/lib"); +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = 0x8c010000); . = 0x8c010000; + .text : + { + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0 + .init : + { + KEEP (*(.init)) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*) + *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*) + *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*) + *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) + *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*) + *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) + *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .plt : { *(.plt) } + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .sdata2 : + { + *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) + } + .sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(128) + (. & (128 - 1)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + ___ctors = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ___ctors_end = .; + } + .dtors : + { + ___dtors = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ___dtors_end = .; + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .data : + { + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + .got : { *(.got.plt) *(.got) } + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata : + { + *(.sdata .sdata.* .gnu.linkonce.s.*) + } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + .sbss : + { + *(.dynsbss) + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + } + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 32 / 8 : 1); + } + . = ALIGN(32 / 8); + . = ALIGN(32 / 8); + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) } +_stack = 0x8d000000; +} Property changes on: dcload/dcload-ip/target-src/1st_read/dc4.x ___________________________________________________________________ Added: svn:eol-style + native Modified: dcload/dcload-ip/target-src/dcload/Makefile =================================================================== --- dcload/dcload-ip/target-src/dcload/Makefile 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/target-src/dcload/Makefile 2012-06-01 04:19:36 UTC (rev 788) @@ -10,18 +10,18 @@ EXCOBJECTS = exception.o %.o : %.c - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< %.o : %.s - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< %.o : %.S - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< %.bin: % - $(OBJCOPY) -R .stack -O binary $< $@ + $(OBJCOPY) -R .stack -O binary $< $@ all: dcload.bin exception.bin dcload: $(DCLOBJECTS) - $(CC) $(CFLAGS) -Wl,-Tdcload.x -nostartfiles -nostdlib $^ -o $@ -lgcc + $(CC) $(CFLAGS) -Wl,-Tdcload$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc exception: $(EXCOBJECTS) $(CC) $(CFLAGS) -Wl,-Ttext=0x8c00f400 -nostartfiles -nostdlib $^ -o $@ @@ -31,5 +31,5 @@ rm -f $(DCLOBJECTS) $(EXCOBJECTS) dcload exception .PHONY : distclean -distclean: clean +distclean: clean rm -f dcload.bin exception.bin Deleted: dcload/dcload-ip/target-src/dcload/dcload.x =================================================================== --- dcload/dcload-ip/target-src/dcload/dcload.x 2012-05-31 21:55:42 UTC (rev 787) +++ dcload/dcload-ip/target-src/dcload/dcload.x 2012-06-01 04:19:36 UTC (rev 788) @@ -1,228 +0,0 @@ -/* Sega Dreamcast linker script */ - -OUTPUT_FORMAT("elf32-shl", "elf32-shl", - "elf32-shl") -OUTPUT_ARCH(sh) -ENTRY(start) - SEARCH_DIR(/usr/local/dcdev/sh-elf/lib); -/* Do we need any of these for elf? - __DYNAMIC = 0; */ - -MEMORY -{ - ram (rwx) : ORIGIN = 0x8c004000, LENGTH = 0xb400 -} - -SECTIONS -{ - /* Read-only sections, merged into text segment: */ -/* . = 0x1000;*/ - .interp : { *(.interp) } - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : - { - *(.rel.text) - *(.rel.text.*) - *(.rel.gnu.linkonce.t*) - } - .rela.text : - { - *(.rela.text) - *(.rela.text.*) - *(.rela.gnu.linkonce.t*) - } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : - { - *(.rel.rodata) - *(.rel.rodata.*) - *(.rel.gnu.linkonce.r*) - } - .rela.rodata : - { - *(.rela.rodata) - *(.rela.rodata.*) - *(.rela.gnu.linkonce.r*) - } - .rel.data : - { - *(.rel.data) - *(.rel.data.*) - *(.rel.gnu.linkonce.d*) - } - .rela.data : - { - *(.rela.data) - *(.rela.data.*) - *(.rela.gnu.linkonce.d*) - } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.sdata : - { - *(.rel.sdata) - *(.rel.sdata.*) - *(.rel.gnu.linkonce.s*) - } - .rela.sdata : - { - *(.rela.sdata) - *(.rela.sdata.*) - *(.rela.gnu.linkonce.s*) - } - .rel.sbss : { *(.rel.sbss) } - .rela.sbss : { *(.rela.sbss) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .init : - { - KEEP (*(.init)) - } =0 - .plt : { *(.plt) } - .text : - { - *(.text) - *(.text.*) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - } =0 - _etext = .; - PROVIDE (etext = .); - .fini : - { - KEEP (*(.fini)) - } =0 - .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } - .rodata1 : { *(.rodata1) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(128) + (. & (128 - 1)); - .data : - { - *(.data) - *(.data.*) - *(.gnu.linkonce.d*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - .eh_frame : { *(.eh_frame) } - .gcc_except_table : { *(.gcc_except_table) } - .ctors ALIGN(4): - { - ___ctors = .; - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - /* We don't want to include the .ctor section from - from the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - ___ctors_end = .; - } - .dtors : - { - ___dtors = .; - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - ___dtors_end = .; - } - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : - { - *(.sdata) - *(.sdata.*) - *(.gnu.linkonce.s.*) - } - _edata = .; - PROVIDE (edata = .); - __bss_start = .; - .sbss : - { - *(.dynsbss) - *(.sbss) - *(.sbss.*) - *(.scommon) - } - .bss : - { - *(.dynbss) - *(.bss) - *(.bss.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(32 / 8); - } - . = ALIGN(32 / 8); - _end = .; - PROVIDE (end = .); - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } -/* .stack 0x8c00f400 : { _stack = .; *(.stack) }*/ - /* These must appear regardless of . */ -_stack = 0x8c00f400; -} Added: dcload/dcload-ip/target-src/dcload/dcload3.x =================================================================== --- dcload/dcload-ip/target-src/dcload/dcload3.x (rev 0) +++ dcload/dcload-ip/target-src/dcload/dcload3.x 2012-06-01 04:19:36 UTC (rev 788) @@ -0,0 +1,228 @@ +/* Sega Dreamcast linker script */ + +OUTPUT_FORMAT("elf32-shl", "elf32-shl", + "elf32-shl") +OUTPUT_ARCH(sh) +ENTRY(start) + SEARCH_DIR(/usr/local/dcdev/sh-elf/lib); +/* Do we need any of these for elf? + __DYNAMIC = 0; */ + +MEMORY +{ + ram (rwx) : ORIGIN = 0x8c004000, LENGTH = 0xb400 +} + +SECTIONS +{ + /* Read-only sections, merged into text segment: */ +/* . = 0x1000;*/ + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.sdata : + { + *(.rel.sdata) + *(.rel.sdata.*) + *(.rel.gnu.linkonce.s*) + } + .rela.sdata : + { + *(.rela.sdata) + *(.rela.sdata.*) + *(.rela.gnu.linkonce.s*) + } + .rel.sbss : { *(.rel.sbss) } + .rela.sbss : { *(.rela.sbss) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .text : + { + *(.text) + *(.text.*) + *(.stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + } =0 + _etext = .; + PROVIDE (etext = .); + .fini : + { + KEEP (*(.fini)) + } =0 + .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } + .rodata1 : { *(.rodata1) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(128) + (. & (128 - 1)); + .data : + { + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + .eh_frame : { *(.eh_frame) } + .gcc_except_table : { *(.gcc_except_table) } + .ctors ALIGN(4): + { + ___ctors = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.c... [truncated message content] |
From: <ljs...@us...> - 2012-05-31 21:55:48
|
Revision: 787 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=787&view=rev Author: ljsebald Date: 2012-05-31 21:55:42 +0000 (Thu, 31 May 2012) Log Message: ----------- Slightly nicer checksum function. Modified Paths: -------------- kos/kernel/net/net_ipv4.c Modified: kos/kernel/net/net_ipv4.c =================================================================== --- kos/kernel/net/net_ipv4.c 2012-05-31 21:54:40 UTC (rev 786) +++ kos/kernel/net/net_ipv4.c 2012-05-31 21:55:42 UTC (rev 787) @@ -25,41 +25,40 @@ /* Perform an IP-style checksum on a block of data */ uint16 net_ipv4_checksum(const uint8 *data, int bytes, uint16 start) { uint32 sum = start; - int i; + int i = bytes; /* Make sure we don't do any unaligned memory accesses */ if(((uint32)data) & 0x01) { - for(i = 0; i < bytes; i += 2) { - sum += (data[i]) | (data[i + 1] << 8); + const uint8 *ptr = data; - if(sum & 0xFFFF0000) { - sum &= 0xFFFF; - ++sum; - } + while(i > 1) { + sum += *ptr | ((*ptr + 1) << 8); + ptr += 2; + i -= 2; + + while(sum >> 16) + sum = (sum >> 16) + (sum & 0xFFFF); } } else { - uint16 *ptr = (uint16 *)data; + const uint16 *ptr = (const uint16 *)data; - for(i = 0; i < (bytes >> 1); ++i) { - sum += ptr[i]; + while(i > 1) { + sum += *ptr++; + i -= 2; - if(sum & 0xFFFF0000) { - sum &= 0xFFFF; - ++sum; - } + while(sum >> 16) + sum = (sum >> 16) + (sum & 0xFFFF); } } /* Handle the last byte, if we have an odd byte count */ - if(bytes & 0x01) { + if(i) sum += data[bytes - 1]; - if(sum & 0xFFFF0000) { - sum &= 0xFFFF; - ++sum; - } - } + /* Take care of any carry bits */ + while(sum >> 16) + sum = (sum >> 16) + (sum & 0xFFFF); return sum ^ 0xFFFF; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-31 21:54:46
|
Revision: 786 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=786&view=rev Author: ljsebald Date: 2012-05-31 21:54:40 +0000 (Thu, 31 May 2012) Log Message: ----------- Fix checksum calculation on packets with size >= 256. Modified Paths: -------------- kos/kernel/net/net_udp.c Modified: kos/kernel/net/net_udp.c =================================================================== --- kos/kernel/net/net_udp.c 2012-05-31 20:25:05 UTC (rev 785) +++ kos/kernel/net/net_udp.c 2012-05-31 21:54:40 UTC (rev 786) @@ -732,7 +732,7 @@ if(hdr->checksum != 0) { cs = net_ipv6_checksum_pseudo(&ip->src_addr, &ip->dst_addr, - IPPROTO_UDP, size); + size, IPPROTO_UDP); /* If the checksum is right, we'll get zero back from the checksum function */ @@ -874,7 +874,7 @@ memcpy(buf + sizeof(udp_hdr_t), data, size); size += sizeof(udp_hdr_t); - cs = net_ipv6_checksum_pseudo(&srcaddr, &dst->sin6_addr, IPPROTO_UDP, size); + cs = net_ipv6_checksum_pseudo(&srcaddr, &dst->sin6_addr, size, IPPROTO_UDP); hdr->src_port = src->sin6_port; hdr->dst_port = dst->sin6_port; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <los...@us...> - 2012-05-31 20:25:12
|
Revision: 785 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=785&view=rev Author: lostgeneration Date: 2012-05-31 20:25:05 +0000 (Thu, 31 May 2012) Log Message: ----------- Cleanup most warnings * Mostly moving packed from each member to the structure definition, but also a bit of whitespace clean up, fixed casting, and including string.h to get memcpy forward definition. Modified Paths: -------------- dcload/dcload-ip/target-src/1st_read/1st_read.c dcload/dcload-ip/target-src/1st_read/crt0.S dcload/dcload-ip/target-src/1st_read/disable.s dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c dcload/dcload-ip/target-src/dcload/commands.c dcload/dcload-ip/target-src/dcload/commands.h dcload/dcload-ip/target-src/dcload/lan_adapter.c dcload/dcload-ip/target-src/dcload/net.c dcload/dcload-ip/target-src/dcload/packet.c dcload/dcload-ip/target-src/dcload/packet.h dcload/dcload-ip/target-src/dcload/rtl8139.c dcload/dcload-ip/target-src/dcload/syscalls.c dcload/dcload-ip/target-src/dcload/syscalls.h dcload/dcload-ip/target-src/dcload/video.h Modified: dcload/dcload-ip/target-src/1st_read/1st_read.c =================================================================== --- dcload/dcload-ip/target-src/1st_read/1st_read.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/1st_read/1st_read.c 2012-05-31 20:25:05 UTC (rev 785) @@ -1,4 +1,4 @@ -/* +/* * This file is part of the dcload Dreamcast ethernet loader * * Copyright (C) 2001 Andrew Kieschnick <an...@au...> @@ -19,6 +19,8 @@ * */ +#include <string.h> + #define TARGET1 (unsigned int *)0x8c004000 #define TARGET2 (unsigned int *)0x8c00f400 @@ -31,10 +33,9 @@ int main(void) { - memcpy(TARGET1, &binary_dcload_bin_start, &binary_dcload_bin_size); - memcpy(TARGET2, &binary_exception_bin_start, &binary_exception_bin_size); + memcpy(TARGET1, &binary_dcload_bin_start, binary_dcload_bin_size); + memcpy(TARGET2, &binary_exception_bin_start, binary_exception_bin_size); - disable_cache(); - (*(void (*)()) 0x8c004000) (); - + disable_cache(); + (*(void (*)()) 0x8c004000) (); } Modified: dcload/dcload-ip/target-src/1st_read/crt0.S =================================================================== --- dcload/dcload-ip/target-src/1st_read/crt0.S 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/1st_read/crt0.S 2012-05-31 20:25:05 UTC (rev 785) @@ -11,7 +11,7 @@ mov.l ccr_addr,r0 mov.w ccr_data,r1 mov.l r1,@r0 - mov.l start_2_k,r0 + mov.l start_2_k,r0 nop nop nop @@ -19,9 +19,9 @@ nop nop nop - jmp @r0 + jmp @r0 nop -start_2: +start_2: mov.l old_stack_k,r14 mov.l r15,@r14 mov.l old_pr_k,r14 @@ -44,7 +44,7 @@ mov #0,r4 lds r3,fpscr - ! call the mainline + ! call the mainline mov.l main_k,r0 jsr @r0 nop @@ -58,12 +58,12 @@ _atexit: rts nop - + .align 4 set_fpscr_k: .long ___set_fpscr stack_k: - .long _stack + .long _stack edata_k: .long _edata end_k: @@ -80,8 +80,8 @@ .long 0 setup_cache_k: .long setup_cache -start_2_k: - .long start_2 +start_2_k: + .long start_2 p2_mask: .long 0xa0000000 ccr_addr: @@ -90,7 +90,7 @@ .word 0x090b .align 4 - + #ifdef __ELF__ .section .stack,"aw" #else Modified: dcload/dcload-ip/target-src/1st_read/disable.s =================================================================== --- dcload/dcload-ip/target-src/1st_read/disable.s 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/1st_read/disable.s 2012-05-31 20:25:05 UTC (rev 785) @@ -1,37 +1,37 @@ .section .text .global _disable_cache - + _disable_cache: mov.l disable_cache_k,r0 - mov.l p2_mask,r1 - or r1,r0 - jmp @r0 - nop + mov.l p2_mask,r1 + or r1,r0 + jmp @r0 + nop disable_cache: mov.l ccr_addr,r0 mov.l ccr_data_k,r1 mov.l @r1,r1 mov.l r1,@r0 nop - nop - nop - nop - nop - nop - nop - nop + nop + nop + nop + nop + nop + nop + nop rts - nop + nop .align 4 - + disable_cache_k: - .long disable_cache + .long disable_cache p2_mask: - .long 0xa0000000 + .long 0xa0000000 ccr_addr: - .long 0xff00001c + .long 0xff00001c ccr_data_k: - .long ccr_data + .long ccr_data ccr_data: - .long 0x00000808 + .long 0x00000808 Modified: dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c =================================================================== --- dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c 2012-05-31 20:25:05 UTC (rev 785) @@ -19,6 +19,7 @@ * */ +#include <string.h> #include "syscalls.h" #include "packet.h" #include "net.h" Modified: dcload/dcload-ip/target-src/dcload/commands.c =================================================================== --- dcload/dcload-ip/target-src/dcload/commands.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/commands.c 2012-05-31 20:25:05 UTC (rev 785) @@ -1,3 +1,4 @@ +#include <string.h> #include "commands.h" #include "packet.h" #include "net.h" Modified: dcload/dcload-ip/target-src/dcload/commands.h =================================================================== --- dcload/dcload-ip/target-src/dcload/commands.h 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/commands.h 2012-05-31 20:25:05 UTC (rev 785) @@ -1,11 +1,11 @@ #ifndef __COMMANDS_H__ #define __COMMANDS_H__ -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int address __attribute__ ((packed)); - unsigned int size __attribute__ ((packed)); - unsigned char data[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned int address; + unsigned int size; + unsigned char data[1]; } command_t; #define CMD_EXECUTE "EXEC" /* execute */ Modified: dcload/dcload-ip/target-src/dcload/lan_adapter.c =================================================================== --- dcload/dcload-ip/target-src/dcload/lan_adapter.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/lan_adapter.c 2012-05-31 20:25:05 UTC (rev 785) @@ -4,6 +4,7 @@ Copyright (C)2002,2003 Dan Potter (NEW BSD LICENSE) */ +#include <string.h> #include "packet.h" #include "net.h" #include "adapter.h" Modified: dcload/dcload-ip/target-src/dcload/net.c =================================================================== --- dcload/dcload-ip/target-src/dcload/net.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/net.c 2012-05-31 20:25:05 UTC (rev 785) @@ -1,3 +1,4 @@ +#include <string.h> #include "commands.h" #include "packet.h" #include "adapter.h" @@ -79,7 +80,7 @@ icmp->checksum = 0; icmp->checksum = checksum((unsigned short *)icmp, ntohs(ip->length)/2 - 2*(ip->version_ihl & 0x0f)); /* transmit */ - bb->tx(ether, ETHER_H_LEN + ntohs(ip->length)); + bb->tx((unsigned char *)ether, ETHER_H_LEN + ntohs(ip->length)); } } Modified: dcload/dcload-ip/target-src/dcload/packet.c =================================================================== --- dcload/dcload-ip/target-src/dcload/packet.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/packet.c 2012-05-31 20:25:05 UTC (rev 785) @@ -1,3 +1,4 @@ +#include <string.h> #include "packet.h" unsigned short checksum(unsigned short *buf, int count) Modified: dcload/dcload-ip/target-src/dcload/packet.h =================================================================== --- dcload/dcload-ip/target-src/dcload/packet.h 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/packet.h 2012-05-31 20:25:05 UTC (rev 785) @@ -8,57 +8,57 @@ unsigned char type[2]; } ether_header_t; -typedef struct { - unsigned char version_ihl __attribute__ ((packed)); - unsigned char tos __attribute__ ((packed)); - unsigned short length __attribute__ ((packed)); - unsigned short packet_id __attribute__ ((packed)); - unsigned short flags_frag_offset __attribute__ ((packed)); - unsigned char ttl __attribute__ ((packed)); - unsigned char protocol __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned int src __attribute__ ((packed)); - unsigned int dest __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char version_ihl; + unsigned char tos; + unsigned short length; + unsigned short packet_id; + unsigned short flags_frag_offset; + unsigned char ttl; + unsigned char protocol; + unsigned short checksum; + unsigned int src; + unsigned int dest; } ip_header_t; -typedef struct { - unsigned short src __attribute__ ((packed)); - unsigned short dest __attribute__ ((packed)); - unsigned short length __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned char data[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned short src; + unsigned short dest; + unsigned short length; + unsigned short checksum; + unsigned char data[1]; } udp_header_t; -typedef struct { - unsigned char type __attribute__ ((packed)); - unsigned char code __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned int misc __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char type; + unsigned char code; + unsigned short checksum; + unsigned int misc; } icmp_header_t; -typedef struct { - unsigned short hw_addr_space __attribute__ ((packed)); - unsigned short proto_addr_space __attribute__ ((packed)); - unsigned char hw_addr_len __attribute__ ((packed)); - unsigned char proto_addr_len __attribute__ ((packed)); - unsigned short opcode __attribute__ ((packed)); - unsigned char hw_sender[6] __attribute__ ((packed)); - unsigned char proto_sender[4] __attribute__ ((packed)); - unsigned char hw_target[6] __attribute__ ((packed)); - unsigned char proto_target[4] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned short hw_addr_space; + unsigned short proto_addr_space; + unsigned char hw_addr_len; + unsigned char proto_addr_len; + unsigned short opcode; + unsigned char hw_sender[6]; + unsigned char proto_sender[4]; + unsigned char hw_target[6]; + unsigned char proto_target[4]; } arp_header_t; -typedef struct { - unsigned int src_ip __attribute__ ((packed)); - unsigned int dest_ip __attribute__ ((packed)); - unsigned char zero __attribute__ ((packed)); - unsigned char protocol __attribute__ ((packed)); - unsigned short udp_length __attribute__ ((packed)); - unsigned short src_port __attribute__ ((packed)); - unsigned short dest_port __attribute__ ((packed)); - unsigned short length __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned char data[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned int src_ip; + unsigned int dest_ip; + unsigned char zero; + unsigned char protocol; + unsigned short udp_length; + unsigned short src_port; + unsigned short dest_port; + unsigned short length; + unsigned short checksum; + unsigned char data[1]; } ip_udp_pseudo_header_t; unsigned short checksum(unsigned short *buf, int count); Modified: dcload/dcload-ip/target-src/dcload/rtl8139.c =================================================================== --- dcload/dcload-ip/target-src/dcload/rtl8139.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/rtl8139.c 2012-05-31 20:25:05 UTC (rev 785) @@ -1,3 +1,4 @@ +#include <string.h> #include "packet.h" #include "net.h" #include "rtl8139.h" Modified: dcload/dcload-ip/target-src/dcload/syscalls.c =================================================================== --- dcload/dcload-ip/target-src/dcload/syscalls.c 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/syscalls.c 2012-05-31 20:25:05 UTC (rev 785) @@ -26,6 +26,7 @@ #include <utime.h> #include <stdarg.h> #include <dirent.h> +#include <string.h> #include "syscalls.h" #include "packet.h" #include "net.h" @@ -42,7 +43,7 @@ /* send command, enable bb, bb_loop(), then return */ -int strlen(const char *s) +size_t strlen(const char *s) { int c = 0; Modified: dcload/dcload-ip/target-src/dcload/syscalls.h =================================================================== --- dcload/dcload-ip/target-src/dcload/syscalls.h 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/syscalls.h 2012-05-31 20:25:05 UTC (rev 785) @@ -47,42 +47,42 @@ extern unsigned int syscall_retval; extern unsigned char* syscall_data; -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int value0 __attribute__ ((packed)); - unsigned int value1 __attribute__ ((packed)); - unsigned int value2 __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned int value0; + unsigned int value1; + unsigned int value2; } command_3int_t; -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int value0 __attribute__ ((packed)); - unsigned int value1 __attribute__ ((packed)); - unsigned char string[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned int value0; + unsigned int value1; + unsigned char string[1]; } command_2int_string_t; -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int value0 __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned int value0; } command_int_t; -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int value0 __attribute__ ((packed)); - unsigned char string[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned int value0; + unsigned char string[1]; } command_int_string_t; -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned char string[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned char string[1]; } command_string_t; -typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int value0 __attribute__ ((packed)); - unsigned int value1 __attribute__ ((packed)); - unsigned int value2 __attribute__ ((packed)); - unsigned char string[1] __attribute__ ((packed)); +typedef struct __attribute__ ((packed)) { + unsigned char id[4]; + unsigned int value0; + unsigned int value1; + unsigned int value2; + unsigned char string[1]; } command_3int_string_t; void build_send_packet(int command_len); Modified: dcload/dcload-ip/target-src/dcload/video.h =================================================================== --- dcload/dcload-ip/target-src/dcload/video.h 2012-05-31 19:56:48 UTC (rev 784) +++ dcload/dcload-ip/target-src/dcload/video.h 2012-05-31 20:25:05 UTC (rev 785) @@ -1,7 +1,7 @@ #ifndef __VIDEO_H__ #define __VIDEO_H__ -void draw_string(int x, int y, char *string, int colour); +void draw_string(int x, int y, const char *string, int colour); void clrscr(int colour); void init_video(int cabletype, int pixelmode); int check_cable(void); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <los...@us...> - 2012-05-31 19:56:57
|
Revision: 784 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=784&view=rev Author: lostgeneration Date: 2012-05-31 19:56:48 +0000 (Thu, 31 May 2012) Log Message: ----------- Standardize formatting for my own sanity Modified Paths: -------------- dcload/dcload-ip/target-src/dcload/bswap.s dcload/dcload-ip/target-src/dcload/cdfs_redir.s dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c dcload/dcload-ip/target-src/dcload/commands.c dcload/dcload-ip/target-src/dcload/commands.h dcload/dcload-ip/target-src/dcload/dcload-crt0.s dcload/dcload-ip/target-src/dcload/dcload.c dcload/dcload-ip/target-src/dcload/disable.s dcload/dcload-ip/target-src/dcload/exception.s dcload/dcload-ip/target-src/dcload/go.s dcload/dcload-ip/target-src/dcload/lan_adapter.c dcload/dcload-ip/target-src/dcload/memcmp.c dcload/dcload-ip/target-src/dcload/memset.S dcload/dcload-ip/target-src/dcload/net.c dcload/dcload-ip/target-src/dcload/packet.c dcload/dcload-ip/target-src/dcload/packet.h dcload/dcload-ip/target-src/dcload/rtl8139.c dcload/dcload-ip/target-src/dcload/rtl8139.h dcload/dcload-ip/target-src/dcload/scif.c dcload/dcload-ip/target-src/dcload/scif.h dcload/dcload-ip/target-src/dcload/syscalls.c dcload/dcload-ip/target-src/dcload/syscalls.h dcload/dcload-ip/target-src/dcload/video.s Modified: dcload/dcload-ip/target-src/dcload/bswap.s =================================================================== --- dcload/dcload-ip/target-src/dcload/bswap.s 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/bswap.s 2012-05-31 19:56:48 UTC (rev 784) @@ -5,7 +5,7 @@ ! r4 = dest _bswap16: - rts + rts swap.b r4,r0 _bswap32: @@ -13,6 +13,6 @@ swap.w r0,r4 rts swap.b r4,r0 - + .end Modified: dcload/dcload-ip/target-src/dcload/cdfs_redir.s =================================================================== --- dcload/dcload-ip/target-src/dcload/cdfs_redir.s 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/cdfs_redir.s 2012-05-31 19:56:48 UTC (rev 784) @@ -3,7 +3,7 @@ .global _cdfs_redir_disable .global _cdfs_redir_save .align 2 - + _cdfs_redir_save: mov.l cdfs_saved_k, r0 mov.l @r0, r0 @@ -13,10 +13,10 @@ mov.l @r0,r0 mov.l cdfs_saved_k, r1 mov.l r0, @r1 -already_saved: +already_saved: rts nop - + _cdfs_redir_disable: mov.l cdfs_saved_k, r0 mov.l @r0, r0 @@ -31,7 +31,7 @@ mov.l r1, @r0 rts nop - + .align 4 cdfs_entry_k: .long 0x8c0000bc Modified: dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c =================================================================== --- dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/cdfs_syscalls.c 2012-05-31 19:56:48 UTC (rev 784) @@ -1,4 +1,4 @@ -/* +/* * This file is part of the dcload Dreamcast ethernet loader * * Copyright (C) 2001 Andrew Kieschnick <an...@au...> @@ -28,52 +28,52 @@ int gdStatus; struct TOC { - unsigned int entry[99]; - unsigned int first, last; - unsigned int dunno; + unsigned int entry[99]; + unsigned int first, last; + unsigned int dunno; }; int gdGdcReqCmd(int cmd, int *param) { - command_3int_t * command = (command_3int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); - struct TOC *toc; - int i; - - switch (cmd) { - case 16: /* read sectors */ - - memcpy(command->id, CMD_CDFSREAD, 4); - command->value0 = htonl(param[0]); - command->value1 = htonl(param[2]); - command->value2 = htonl(param[1]*2048); - build_send_packet(sizeof(command_3int_t)); - bb->loop(); + command_3int_t * command = (command_3int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); + struct TOC *toc; + int i; - param[3] = 0; - gdStatus = 2; + switch (cmd) { + case 16: /* read sectors */ - return 0; - break; - case 19: /* read toc */ - toc = (struct TOC *)param[1]; - toc->entry[0] = 0x41000096; /* CTRL = 4, ADR = 1, LBA = 150 */ - for(i=1; i<99; i++) - toc->entry[i] = -1; - toc->first = 0x41010000; /* first = track 1 */ - toc->last = 0x41010000; /* last = track 1 */ - gdStatus = 2; - return 0; - break; - case 24: /* init disc */ - gdStatus = 2; - return 0; - break; - default: - gdStatus = 0; - return -1; - break; - } + memcpy(command->id, CMD_CDFSREAD, 4); + command->value0 = htonl(param[0]); + command->value1 = htonl(param[2]); + command->value2 = htonl(param[1]*2048); + build_send_packet(sizeof(command_3int_t)); + bb->loop(); + param[3] = 0; + gdStatus = 2; + + return 0; + break; + case 19: /* read toc */ + toc = (struct TOC *)param[1]; + toc->entry[0] = 0x41000096; /* CTRL = 4, ADR = 1, LBA = 150 */ + for(i=1; i<99; i++) + toc->entry[i] = -1; + toc->first = 0x41010000; /* first = track 1 */ + toc->last = 0x41010000; /* last = track 1 */ + gdStatus = 2; + return 0; + break; + case 24: /* init disc */ + gdStatus = 2; + return 0; + break; + default: + gdStatus = 0; + return -1; + break; + } + } void gdGdcExecServer(void) @@ -82,23 +82,22 @@ int gdGdcGetCmdStat(int f, int *status) { - if (gdStatus == 0) - status[0] = 0; - return gdStatus; + if (gdStatus == 0) + status[0] = 0; + return gdStatus; } void gdGdcGetDrvStat(int *param) { - param[1] = 32; + param[1] = 32; } int gdGdcChangeDataType(int *param) { - return 0; + return 0; } void gdGdcInitSystem(void) { } - Modified: dcload/dcload-ip/target-src/dcload/commands.c =================================================================== --- dcload/dcload-ip/target-src/dcload/commands.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/commands.c 2012-05-31 19:56:48 UTC (rev 784) @@ -19,9 +19,9 @@ #define min(a, b) ((a) < (b) ? (a) : (b)) typedef struct { - unsigned int load_address; - unsigned int load_size; - unsigned char map[16384]; + unsigned int load_address; + unsigned int load_size; + unsigned char map[16384]; } bin_info_t; bin_info_t bin_info; @@ -31,177 +31,177 @@ void cmd_reboot(ether_header_t * ether, ip_header_t * ip, udp_header_t * udp, command_t * command) { - booted = 0; - running = 0; + booted = 0; + running = 0; - disable_cache(); - go(0x8c004000); + disable_cache(); + go(0x8c004000); } void cmd_execute(ether_header_t * ether, ip_header_t * ip, udp_header_t * udp, command_t * command) { - if (!running) { - tool_ip = ntohl(ip->src); - tool_port = ntohs(udp->src); - memcpy(tool_mac, ether->src, 6); + if (!running) { + tool_ip = ntohl(ip->src); + tool_port = ntohs(udp->src); + memcpy(tool_mac, ether->src, 6); + our_ip = ntohl(ip->dest); + + make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); + make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); + bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); + + if (!booted) + disp_info(); + else + disp_status("executing..."); + + if (ntohl(command->size)&1) + *(unsigned int *)0x8c004004 = 0xdeadbeef; /* enable console */ + else + *(unsigned int *)0x8c004004 = 0xfeedface; /* disable console */ + if (ntohl(command->size)>>1) + cdfs_redir_enable(); + + bb->stop(); + + running = 1; + + disable_cache(); + go(ntohl(command->address)); + } +} + +void cmd_loadbin(ip_header_t * ip, udp_header_t * udp, command_t * command) +{ + bin_info.load_address = ntohl(command->address); + bin_info.load_size = ntohl(command->size); + memset(bin_info.map, 0, 16384); + our_ip = ntohl(ip->dest); make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); - - if (!booted) - disp_info(); - else - disp_status("executing..."); - - if (ntohl(command->size)&1) - *(unsigned int *)0x8c004004 = 0xdeadbeef; /* enable console */ - else - *(unsigned int *)0x8c004004 = 0xfeedface; /* disable console */ - if (ntohl(command->size)>>1) - cdfs_redir_enable(); - - bb->stop(); - - running = 1; - disable_cache(); - go(ntohl(command->address)); - } + if (!running) { + if (!booted) + disp_info(); + disp_status("receiving data..."); + } } -void cmd_loadbin(ip_header_t * ip, udp_header_t * udp, command_t * command) +void cmd_partbin(ip_header_t * ip, udp_header_t * udp, command_t * command) { - bin_info.load_address = ntohl(command->address); - bin_info.load_size = ntohl(command->size); - memset(bin_info.map, 0, 16384); + int index = 0; - our_ip = ntohl(ip->dest); - - make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); - make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); - bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); + memcpy((unsigned char *)ntohl(command->address), command->data, ntohl(command->size)); - if (!running) { - if (!booted) - disp_info(); - disp_status("receiving data..."); - } + index = (ntohl(command->address) - bin_info.load_address) >> 10; + bin_info.map[index] = 1; } - -void cmd_partbin(ip_header_t * ip, udp_header_t * udp, command_t * command) -{ - int index = 0; - memcpy((unsigned char *)ntohl(command->address), command->data, ntohl(command->size)); - - index = (ntohl(command->address) - bin_info.load_address) >> 10; - bin_info.map[index] = 1; -} - void cmd_donebin(ip_header_t * ip, udp_header_t * udp, command_t * command) { - int i; - - for(i = 0; i < (bin_info.load_size + 1023)/1024; i++) - if (!bin_info.map[i]) - break; - if ( i == (bin_info.load_size + 1023)/1024 ) { - command->address = htonl(0); - command->size = htonl(0); - } else { - command->address = htonl( bin_info.load_address + i * 1024); - command->size = htonl(min(bin_info.load_size - i * 1024, 1024)); - } - - make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); - make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); - bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); + int i; - if (!running) { - if (!booted) - disp_info(); - disp_status("idle..."); - } + for(i = 0; i < (bin_info.load_size + 1023)/1024; i++) + if (!bin_info.map[i]) + break; + if ( i == (bin_info.load_size + 1023)/1024 ) { + command->address = htonl(0); + command->size = htonl(0); + } else { + command->address = htonl( bin_info.load_address + i * 1024); + command->size = htonl(min(bin_info.load_size - i * 1024, 1024)); + } + + make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); + make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); + bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); + + if (!running) { + if (!booted) + disp_info(); + disp_status("idle..."); + } } void cmd_sendbinq(ip_header_t * ip, udp_header_t * udp, command_t * command) { - int numpackets, i; - unsigned char *ptr; - unsigned int bytes_left; - unsigned int bytes_thistime; + int numpackets, i; + unsigned char *ptr; + unsigned int bytes_left; + unsigned int bytes_thistime; - bytes_left = ntohl(command->size); - numpackets = (ntohl(command->size)+1023) / 1024; - ptr = (unsigned char *)ntohl(command->address); - - memcpy(response->id, CMD_SENDBIN, 4); - for(i = 0; i < numpackets; i++) { - if (bytes_left >= 1024) - bytes_thistime = 1024; - else - bytes_thistime = bytes_left; - bytes_left -= bytes_thistime; - - response->address = htonl((unsigned int)ptr); - memcpy(response->data, ptr, bytes_thistime); - response->size = htonl(bytes_thistime); - make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN + bytes_thistime, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); - make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) response, COMMAND_LEN + bytes_thistime, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); - bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN + bytes_thistime); - ptr += bytes_thistime; - } - - memcpy(response->id, CMD_DONEBIN, 4); - response->address = htonl(0); - response->size = htonl(0); - make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); - make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) response, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); - bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); + bytes_left = ntohl(command->size); + numpackets = (ntohl(command->size)+1023) / 1024; + ptr = (unsigned char *)ntohl(command->address); + + memcpy(response->id, CMD_SENDBIN, 4); + for(i = 0; i < numpackets; i++) { + if (bytes_left >= 1024) + bytes_thistime = 1024; + else + bytes_thistime = bytes_left; + bytes_left -= bytes_thistime; + + response->address = htonl((unsigned int)ptr); + memcpy(response->data, ptr, bytes_thistime); + response->size = htonl(bytes_thistime); + make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN + bytes_thistime, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); + make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) response, COMMAND_LEN + bytes_thistime, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); + bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN + bytes_thistime); + ptr += bytes_thistime; + } + + memcpy(response->id, CMD_DONEBIN, 4); + response->address = htonl(0); + response->size = htonl(0); + make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); + make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) response, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); + bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); } void cmd_sendbin(ip_header_t * ip, udp_header_t * udp, command_t * command) { - our_ip = ntohl(ip->dest); + our_ip = ntohl(ip->dest); - if (!running) { - if (!booted) - disp_info(); - disp_status("sending data..."); - } - - cmd_sendbinq(ip, udp, command); + if (!running) { + if (!booted) + disp_info(); + disp_status("sending data..."); + } - if (!running) { - disp_status("idle..."); - } + cmd_sendbinq(ip, udp, command); + + if (!running) { + disp_status("idle..."); + } } void cmd_version(ip_header_t * ip, udp_header_t * udp, command_t * command) { - int i; + int i; - i = strlen("DCLOAD-IP " DCLOAD_VERSION) + 1; - memcpy(response, command, COMMAND_LEN); - strcpy(response->data, "DCLOAD-IP " DCLOAD_VERSION); - make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN + i, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); - make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) response, COMMAND_LEN + i, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); - bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN + i); + i = strlen("DCLOAD-IP " DCLOAD_VERSION) + 1; + memcpy(response, command, COMMAND_LEN); + strcpy(response->data, "DCLOAD-IP " DCLOAD_VERSION); + make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN + i, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); + make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) response, COMMAND_LEN + i, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); + bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN + i); } void cmd_retval(ip_header_t * ip, udp_header_t * udp, command_t * command) { - if (running) { - make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); - make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); - bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); + if (running) { + make_ip(ntohl(ip->src), ntohl(ip->dest), UDP_H_LEN + COMMAND_LEN, 17, (ip_header_t *)(pkt_buf + ETHER_H_LEN)); + make_udp(ntohs(udp->src), ntohs(udp->dest),(unsigned char *) command, COMMAND_LEN, (ip_header_t *)(pkt_buf + ETHER_H_LEN), (udp_header_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN)); + bb->tx(pkt_buf, ETHER_H_LEN + IP_H_LEN + UDP_H_LEN + COMMAND_LEN); - bb->stop(); + bb->stop(); - syscall_retval = ntohl(command->address); - syscall_data = command->data; - escape_loop = 1; - } + syscall_retval = ntohl(command->address); + syscall_data = command->data; + escape_loop = 1; + } } Modified: dcload/dcload-ip/target-src/dcload/commands.h =================================================================== --- dcload/dcload-ip/target-src/dcload/commands.h 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/commands.h 2012-05-31 19:56:48 UTC (rev 784) @@ -2,10 +2,10 @@ #define __COMMANDS_H__ typedef struct { - unsigned char id[4] __attribute__ ((packed)); - unsigned int address __attribute__ ((packed)); - unsigned int size __attribute__ ((packed)); - unsigned char data[1] __attribute__ ((packed)); + unsigned char id[4] __attribute__ ((packed)); + unsigned int address __attribute__ ((packed)); + unsigned int size __attribute__ ((packed)); + unsigned char data[1] __attribute__ ((packed)); } command_t; #define CMD_EXECUTE "EXEC" /* execute */ Modified: dcload/dcload-ip/target-src/dcload/dcload-crt0.s =================================================================== --- dcload/dcload-ip/target-src/dcload/dcload-crt0.s 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/dcload-crt0.s 2012-05-31 19:56:48 UTC (rev 784) @@ -1,5 +1,5 @@ ! crt0.s for dcload - + .section .text .global start .global _atexit @@ -9,19 +9,19 @@ nop ! for checking if dcload is present - + dcloadmagic: .long 0xdeadbeef ! normal programs use this call - -dcloadsyscall_k: + +dcloadsyscall_k: .long _dcloadsyscall - + ! exception handler uses these calls -setup_video_k: - .long _setup_video +setup_video_k: + .long _setup_video clrscr_k: .long _clrscr draw_string_k: @@ -30,25 +30,25 @@ .long _uint_to_string exc_to_string_k: .long _exception_code_to_string - + realstart: stc sr,r0 mov.l sr_mask,r1 - and r1,r0 - or #0xf0,r0 + and r1,r0 + or #0xf0,r0 ldc r0,sr mov.l setup_cache_k,r0 mov.l p2_mask,r1 or r1,r0 jmp @r0 nop - + setup_cache: mov.l ccr_addr,r0 mov.w ccr_data,r1 mov.l r1,@r0 mov.l start_2_k,r0 - mov #0,r1 + mov #0,r1 nop nop nop @@ -56,7 +56,7 @@ nop nop jmp @r0 - mov r1,r0 + mov r1,r0 start_2: mov.l stack_k,r15 @@ -76,7 +76,7 @@ mov #0,r4 lds r3,fpscr - ! call main + ! call main mov.l main_k,r0 jsr @r0 or r0,r0 @@ -95,7 +95,7 @@ set_fpscr_k: .long ___set_fpscr stack_k: - .long _stack + .long _stack edata_k: .long _edata end_k: @@ -104,8 +104,8 @@ .long _main setup_cache_k: .long setup_cache -start_2_k: - .long start_2 +start_2_k: + .long start_2 p2_mask: .long 0xa0000000 ccr_addr: @@ -119,7 +119,7 @@ mov.l correctmagic,r0 cmp/eq r0,r1 bf badsyscall - + mov r4,r0 mov r5,r4 mov r6,r5 @@ -134,8 +134,8 @@ mov.l @(r0,r1),r0 jmp @r0 nop - -badsyscall: + +badsyscall: mov #-1,r0 rts nop @@ -144,7 +144,7 @@ dcloadmagic_k: .long dcloadmagic correctmagic: - .long 0xdeadbeef + .long 0xdeadbeef first_syscall: .long read_k read_k: @@ -163,7 +163,7 @@ .long _unlink chdir_k: .long _chdir -chmod_k: +chmod_k: .long _chmod lseek_k: .long _lseek @@ -185,7 +185,7 @@ .long _closedir readdir_k: .long _readdir -hostinfo_k: +hostinfo_k: .long _gethostinfo gdbpacket_k: .long _gdbpacket Modified: dcload/dcload-ip/target-src/dcload/dcload.c =================================================================== --- dcload/dcload-ip/target-src/dcload/dcload.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/dcload.c 2012-05-31 19:56:48 UTC (rev 784) @@ -1,4 +1,4 @@ -/* +/* * dcload, a Dreamcast ethernet loader * * Copyright (C) 2001 Andrew Kieschnick <an...@au...> @@ -41,112 +41,112 @@ /* converts expevt value to description, used by exception handler */ unsigned char * exception_code_to_string(unsigned int expevt) { - switch(expevt) { - case 0x1e0: - return "User break"; - break; - case 0x0e0: - return "Address error (read)"; - break; - case 0x040: - return "TLB miss exception (read)"; - break; - case 0x0a0: - return "TLB protection violation exception (read)"; - break; - case 0x180: - return "General illegal instruction exception"; - break; - case 0x1a0: - return "Slot illegal instruction exception"; - break; - case 0x800: - return "General FPU disable exception"; - break; - case 0x820: - return "Slot FPU disable exception"; - break; - case 0x100: - return "Address error (write)"; - break; - case 0x060: - return "TLB miss exception (write)"; - break; - case 0x0c0: - return "TLB protection violation exception (write)"; - break; - case 0x120: - return "FPU exception"; - break; - case 0x080: - return "Initial page write exception"; - break; - case 0x160: - return "Unconditional trap (TRAPA)"; - break; - default: - return "Unknown exception"; - break; - } + switch(expevt) { + case 0x1e0: + return "User break"; + break; + case 0x0e0: + return "Address error (read)"; + break; + case 0x040: + return "TLB miss exception (read)"; + break; + case 0x0a0: + return "TLB protection violation exception (read)"; + break; + case 0x180: + return "General illegal instruction exception"; + break; + case 0x1a0: + return "Slot illegal instruction exception"; + break; + case 0x800: + return "General FPU disable exception"; + break; + case 0x820: + return "Slot FPU disable exception"; + break; + case 0x100: + return "Address error (write)"; + break; + case 0x060: + return "TLB miss exception (write)"; + break; + case 0x0c0: + return "TLB protection violation exception (write)"; + break; + case 0x120: + return "FPU exception"; + break; + case 0x080: + return "Initial page write exception"; + break; + case 0x160: + return "Unconditional trap (TRAPA)"; + break; + default: + return "Unknown exception"; + break; + } } void uint_to_string(unsigned int foo, unsigned char *bar) { - char hexdigit[16] = "0123456789abcdef"; - int i; + char hexdigit[16] = "0123456789abcdef"; + int i; - for(i=7; i>=0; i--) { - bar[i] = hexdigit[(foo & 0x0f)]; - foo = foo >> 4; - } - bar[8] = 0; + for(i=7; i>=0; i--) { + bar[i] = hexdigit[(foo & 0x0f)]; + foo = foo >> 4; + } + bar[8] = 0; } void uchar_to_string(unsigned int foo, unsigned char *bar) { - char hexdigit[16] = "0123456789abcdef"; - int i; + char hexdigit[16] = "0123456789abcdef"; + int i; - bar[1] = hexdigit[foo & 0x0f]; - bar[0] = hexdigit[foo >> 4]; + bar[1] = hexdigit[foo & 0x0f]; + bar[0] = hexdigit[foo >> 4]; } /* set n lines starting at line y to value c */ void clear_lines(unsigned int y, unsigned int n, unsigned int c) { - unsigned short * vmem = (unsigned short *)(0xa5000000 + y*640*2); - n = n * 640; - while (n-- > 0) - *vmem++ = c; + unsigned short * vmem = (unsigned short *)(0xa5000000 + y*640*2); + n = n * 640; + while (n-- > 0) + *vmem++ = c; } void draw_progress(unsigned int current, unsigned int total) { - unsigned char current_string[9]; - unsigned char total_string[9]; + unsigned char current_string[9]; + unsigned char total_string[9]; - uint_to_string(total, total_string); - uint_to_string(current, current_string); - clear_lines(120, 24, 0x0100); - draw_string(30, 174, "(", 0xffff); - draw_string(42, 174, current_string, 0xffff); - draw_string(138, 174, "/", 0xffff); - draw_string(150, 174, total_string, 0xffff); - draw_string(246, 174, ")", 0xffff); + uint_to_string(total, total_string); + uint_to_string(current, current_string); + clear_lines(120, 24, 0x0100); + draw_string(30, 174, "(", 0xffff); + draw_string(42, 174, current_string, 0xffff); + draw_string(138, 174, "/", 0xffff); + draw_string(150, 174, total_string, 0xffff); + draw_string(246, 174, ")", 0xffff); } void setup_video(unsigned int mode, unsigned int color) { - init_video(check_cable(), mode); - clrscr(color); + init_video(check_cable(), mode); + clrscr(color); } void error_bb(unsigned char *msg) { - setup_video(0,0x2000); - draw_string(30, 54, NAME, 0xffff); - draw_string(30, 78, msg, 0xffff); - while(1); + setup_video(0,0x2000); + draw_string(30, 54, NAME, 0xffff); + draw_string(30, 78, msg, 0xffff); + while(1); } unsigned char *mac_string = "de:ad:be:ef:ba:be"; @@ -154,86 +154,85 @@ void disp_info(void) { - int c; - unsigned char *ip = (unsigned char *)&our_ip; + int c; + unsigned char *ip = (unsigned char *)&our_ip; - setup_video(0,0x0100); - draw_string(30, 54, NAME, 0xffff); - draw_string(30, 78, bb->name, 0xffff); - draw_string(30, 102, mac_string, 0xffff); - for(c = 0; c < 4; c++) - uchar_to_string(ip[3-c], &ip_string[c*3]); - draw_string(30, 126, ip_string, 0xffff); - booted = 1; + setup_video(0,0x0100); + draw_string(30, 54, NAME, 0xffff); + draw_string(30, 78, bb->name, 0xffff); + draw_string(30, 102, mac_string, 0xffff); + for(c = 0; c < 4; c++) + uchar_to_string(ip[3-c], &ip_string[c*3]); + draw_string(30, 126, ip_string, 0xffff); + booted = 1; } void disp_status(const char * status) { - clear_lines(150, 24, 0x0100); - draw_string(30, 150, status, 0xffff); + clear_lines(150, 24, 0x0100); + draw_string(30, 150, status, 0xffff); } void set_ip(void) { - int i; - int c; - unsigned char *ip = (unsigned char *)&our_ip; + int i; + int c; + unsigned char *ip = (unsigned char *)&our_ip; - i = 0; - c = 0; - - while(DREAMCAST_IP[c] != 0) { - if (DREAMCAST_IP[c] != '.') { - ip[i] *= 10; - ip[i] += DREAMCAST_IP[c] - '0'; + i = 0; + c = 0; + + while(DREAMCAST_IP[c] != 0) { + if (DREAMCAST_IP[c] != '.') { + ip[i] *= 10; + ip[i] += DREAMCAST_IP[c] - '0'; + } + else + i++; + c++; } - else - i++; - c++; - } - our_ip = ntohl(our_ip); + our_ip = ntohl(our_ip); } - int main(void) { - unsigned char crap; - unsigned int addr; - unsigned int size; - unsigned int console; - unsigned int start; + unsigned char crap; + unsigned int addr; + unsigned int size; + unsigned int console; + unsigned int start; - running = 0; + running = 0; -/* scif_init(115200); */ + /* scif_init(115200); */ - if (adapter_detect() < 0) - error_bb("NO ETHERNET ADAPTER DETECTED!"); + if (adapter_detect() < 0) + error_bb("NO ETHERNET ADAPTER DETECTED!"); - for(start = 0; start < 6; start++) - uchar_to_string(bb->mac[start], mac_string + start*3); + for(start = 0; start < 6; start++) + uchar_to_string(bb->mac[start], mac_string + start*3); - set_ip(); + set_ip(); - cdfs_redir_save(); /* will only save value once */ - cdfs_redir_disable(); + cdfs_redir_save(); /* will only save value once */ + cdfs_redir_disable(); - if (!booted) { - disp_info(); - } else - booted = 0; -/* - scif_puts(NAME); - scif_puts("\n"); -*/ - while (1) { - *VIDBORDER = 0; + if (!booted) { + disp_info(); + } else + booted = 0; + /* + scif_puts(NAME); + scif_puts("\n"); + */ + while (1) { + *VIDBORDER = 0; - if (booted) { - disp_status("idle..."); - } + if (booted) { + disp_status("idle..."); + } - bb->loop(); - } + bb->loop(); + } } Modified: dcload/dcload-ip/target-src/dcload/disable.s =================================================================== --- dcload/dcload-ip/target-src/dcload/disable.s 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/disable.s 2012-05-31 19:56:48 UTC (rev 784) @@ -1,37 +1,37 @@ .section .text .global _disable_cache - + _disable_cache: mov.l disable_cache_k,r0 - mov.l p2_mask,r1 - or r1,r0 - jmp @r0 - nop + mov.l p2_mask,r1 + or r1,r0 + jmp @r0 + nop disable_cache: - mov.l ccr_addr,r0 - mov.l ccr_data_k,r1 - mov.l @r1,r1 - mov.l r1,@r0 + mov.l ccr_addr,r0 + mov.l ccr_data_k,r1 + mov.l @r1,r1 + mov.l r1,@r0 nop - nop - nop - nop - nop - nop - nop - nop + nop + nop + nop + nop + nop + nop + nop rts - nop + nop - .align 4 - +.align 4 + disable_cache_k: - .long disable_cache + .long disable_cache p2_mask: - .long 0xa0000000 + .long 0xa0000000 ccr_addr: - .long 0xff00001c + .long 0xff00001c ccr_data_k: - .long ccr_data + .long ccr_data ccr_data: - .long 0x00000808 + .long 0x00000808 Modified: dcload/dcload-ip/target-src/dcload/exception.s =================================================================== --- dcload/dcload-ip/target-src/dcload/exception.s 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/exception.s 2012-05-31 19:56:48 UTC (rev 784) @@ -2,10 +2,10 @@ ! ! a general exception handler that displays a register dump onscreen ! for general exceptions (VBR + 0x100) and TLB miss exceptions (VBR + 0x400) -! - +! + .section .text -disp_labels: +disp_labels: ! r4 -> @(0,r15) = addr of labels ! r5 -> @(4,r15) = number of labels @@ -19,9 +19,9 @@ mov.l r7,@(8,r15) mov.l r6,@(12,r15) mov r5,r0 -disp_loop: +disp_loop: ! display a label - mov.l r0,@(4,r15) + mov.l r0,@(4,r15) mov.l @(12,r15),r4 mov.l @(8,r15),r5 mov.l @(0,r15),r6 @@ -58,8 +58,8 @@ mov.l r7,@(8,r15) mov.l r6,@(12,r15) mov r5,r0 -val_loop: - mov.l r0,@(4,r15) +val_loop: + mov.l r0,@(4,r15) mov.l @(0,r15),r4 mov.l @r4,r4 ! convert string @@ -71,7 +71,7 @@ nop mova misc_string,r0 mov r0,r6 -! display string +! display string mov.l @(12,r15),r4 mov.l @(8,r15),r5 mov #0xff,r7 @@ -93,10 +93,10 @@ lds.l @r15+,pr rts nop - + .balign 0x100 -! VBR + 0x100 +! VBR + 0x100 ! general exceptions general_1: ! assume the stack may be fux0red @@ -109,7 +109,7 @@ sts.l pr,@-r15 mov.l r0,@-r15 mov.l r1,@-r15 - mova regdump,r0 + mova regdump,r0 jsr @r0 nop add #12,r15 @@ -117,7 +117,7 @@ add #66,r15 add #66,r15 add #66,r15 -! display exception identifier string +! display exception identifier string mov.l expevt,r4 mov.l @r4,r4 mov.l exc_to_string_k,r0 @@ -132,7 +132,7 @@ mov.l @r0,r0 jsr @r0 nop -! display "EXPEVT" +! display "EXPEVT" mov #0,r4 mov #48,r5 mova expevt_string,r0 @@ -142,7 +142,7 @@ mov.l @r0,r0 jsr @r0 nop -! convert expevt to string +! convert expevt to string mov.l expevt,r4 mov.l @r4,r4 mova misc_string,r0 @@ -151,7 +151,7 @@ mov.l @r0,r0 jsr @r0 nop -! display expevt +! display expevt mov #84,r4 extu.b r4,r4 mov #48,r5 @@ -171,7 +171,7 @@ .long 0x8d000000 exc_to_string_k: .long 0x8c00401c - + regdump: ! save registers for display ! caller has allocated 264 bytes on stack for regs @@ -229,7 +229,7 @@ stc r7_bank,r1 mov.l r1,@r0 add #4,r0 -! r0-r7 bank 1 +! r0-r7 bank 1 mov.l @(8,r15),r1 mov.l r1,@r0 add #4,r0 @@ -263,7 +263,7 @@ add #4,r0 mov.l r14,@r0 add #4,r0 -! sgr (r15) +! sgr (r15) stc sgr,r1 mov.l r1,@r0 add #4,r0 @@ -456,7 +456,7 @@ ! return lds.l @r15+,pr rts - nop + nop .align 4 fpscr_val_fr: .long 0x00040001 @@ -482,7 +482,7 @@ .long labels3 labels4_k: .long labels4 -setup_video_k: +setup_video_k: .long 0x8c00400c .align 2 expevt_string: @@ -493,12 +493,12 @@ .balign 0x400 -! VBR + 0x400 +! VBR + 0x400 general_2: bra general_1 nop .align 2 -labels1: +labels1: .asciz "PC " .asciz "PR " .asciz "SR " @@ -516,7 +516,7 @@ .asciz "R6B0" .asciz "R7B0" .align 2 -labels2: +labels2: .asciz "R0B1" .asciz "R1B1" .asciz "R2B1" @@ -534,7 +534,7 @@ .asciz "R14 " .asciz "R15 " .align 2 -labels3: +labels3: .asciz "FPSC" ! FPSCR .asciz "FR0 " .asciz "FR1 " @@ -553,7 +553,7 @@ .asciz "FR14" .asciz "FR15" .align 2 -labels4: +labels4: .asciz "FPUL" .asciz "XF0 " .asciz "XF1 " Modified: dcload/dcload-ip/target-src/dcload/go.s =================================================================== --- dcload/dcload-ip/target-src/dcload/go.s 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/go.s 2012-05-31 19:56:48 UTC (rev 784) @@ -1,6 +1,6 @@ .section .text .global _go - + _go: mov.l stack_addr_k,r0 mov.l @r0,r15 @@ -54,4 +54,3 @@ .long fpscr_data fpscr_data: .long 0x40001 - \ No newline at end of file Modified: dcload/dcload-ip/target-src/dcload/lan_adapter.c =================================================================== --- dcload/dcload-ip/target-src/dcload/lan_adapter.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/lan_adapter.c 2012-05-31 19:56:48 UTC (rev 784) @@ -1,6 +1,6 @@ /* DC "Lan Adapter" driver for dc-load-ip - + Copyright (C)2002,2003 Dan Potter (NEW BSD LICENSE) */ @@ -29,7 +29,7 @@ static vuint32 *xpl = REGL(0xa0600000); #define REG(x) ( xpl[(x) + 0x400/4] & 0xff ) #define REGW(x) ( xpc[(x)*4 + 0x400] ) - + /* This is based on the JLI EEPROM reader from FreeBSD. EEPROM in the Sega adapter is a bit simpler than what is described in the Fujitsu manual -- it appears to contain only the MAC address and not a base @@ -129,7 +129,7 @@ for (;;) ; } - + /* Reset the interface */ xpc[0x0480] = 0; xpc[0x0480] = 1; @@ -162,14 +162,14 @@ DEBUG("bb_init exited, already done\r\n"); return 0; } - + if (bb_started == 0) { if (!bb_detect()) { DEBUG("bb_init exited, bb_detect() failed\r\n"); return -1; } } - + /* Clear interrupt status */ REGW(0) = 0xff; REGW(1) = 0xff; @@ -208,7 +208,7 @@ /* Copy it into the adapter structure for dcload */ memcpy(adapter_la.mac, mac, 6); - + /* Clear the multicast address */ SETBANK(1); for (i=0; i<6; i++) @@ -253,7 +253,7 @@ /* Stop lan adapter */ void bb_stop() { DEBUG("bb_stop entered\r\n"); - + if (bb_started != 2) { DEBUG("bb_stop exited, state != 2\r\n"); return; @@ -265,7 +265,7 @@ /* Disable all receive */ REGW(5) = (REG(5) & ~0x03); - + bb_started = 3; DEBUG("bb_stop exited\r\n"); } @@ -287,7 +287,7 @@ } */ /* Transmit a packet */ -/* Note that it's technically possible to queue up more than one packet +/* Note that it's technically possible to queue up more than one packet at a time for transmission, but this is the simple way. */ static int bb_tx(unsigned char *pkt, int len) { int i; @@ -346,7 +346,7 @@ for (;;) ; } - + for (count = 0; ; count++) { /* Is the buffer empty? */ if (REG(5) & 0x40) { @@ -393,7 +393,7 @@ int result; DEBUG("bb_loop entered\r\n"); - + while (!escape_loop) { /* Check for received packets */ result = bb_rx(); Modified: dcload/dcload-ip/target-src/dcload/memcmp.c =================================================================== --- dcload/dcload-ip/target-src/dcload/memcmp.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/memcmp.c 2012-05-31 19:56:48 UTC (rev 784) @@ -1,31 +1,31 @@ /* FUNCTION - <<memcmp>>---compare two memory areas + <<memcmp>>---compare two memory areas INDEX - memcmp + memcmp ANSI_SYNOPSIS - #include <string.h> - int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); + #include <string.h> + int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); TRAD_SYNOPSIS - #include <string.h> - int memcmp(<[s1]>, <[s2]>, <[n]>) - void *<[s1]>; - void *<[s2]>; - size_t <[n]>; + #include <string.h> + int memcmp(<[s1]>, <[s2]>, <[n]>) + void *<[s1]>; + void *<[s2]>; + size_t <[n]>; DESCRIPTION - This function compares not more than <[n]> characters of the - object pointed to by <[s1]> with the object pointed to by <[s2]>. + This function compares not more than <[n]> characters of the + object pointed to by <[s1]> with the object pointed to by <[s2]>. RETURNS - The function returns an integer greater than, equal to or - less than zero according to whether the object pointed to by - <[s1]> is greater than, equal to or less than the object - pointed to by <[s2]>. + The function returns an integer greater than, equal to or + less than zero according to whether the object pointed to by + <[s1]> is greater than, equal to or less than the object + pointed to by <[s2]>. PORTABILITY <<memcmp>> is ANSI C. @@ -33,7 +33,7 @@ <<memcmp>> requires no supporting OS subroutines. QUICKREF - memcmp ansi pure + memcmp ansi pure */ #include <string.h> @@ -54,52 +54,52 @@ _CONST _PTR m1 _AND _CONST _PTR m2 _AND size_t n) { #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char *s1 = (unsigned char *) m1; - unsigned char *s2 = (unsigned char *) m2; + unsigned char *s1 = (unsigned char *) m1; + unsigned char *s2 = (unsigned char *) m2; - while (n--) { - if (*s1 != *s2) { - return *s1 - *s2; + while (n--) { + if (*s1 != *s2) { + return *s1 - *s2; + } + s1++; + s2++; } - s1++; - s2++; - } - return 0; + return 0; #else - unsigned char *s1 = (unsigned char *) m1; - unsigned char *s2 = (unsigned char *) m2; - unsigned long *a1; - unsigned long *a2; + unsigned char *s1 = (unsigned char *) m1; + unsigned char *s2 = (unsigned char *) m2; + unsigned long *a1; + unsigned long *a2; - /* If the size is too small, or either pointer is unaligned, - then we punt to the byte compare loop. Hopefully this will - not turn up in inner loops. */ - if (!TOO_SMALL(n) && !UNALIGNED(s1, s2)) { - /* Otherwise, load and compare the blocks of memory one - word at a time. */ - a1 = (unsigned long *) s1; - a2 = (unsigned long *) s2; - while (n >= LBLOCKSIZE) { - if (*a1 != *a2) - break; - a1++; - a2++; - n -= LBLOCKSIZE; - } + /* If the size is too small, or either pointer is unaligned, + then we punt to the byte compare loop. Hopefully this will + not turn up in inner loops. */ + if (!TOO_SMALL(n) && !UNALIGNED(s1, s2)) { + /* Otherwise, load and compare the blocks of memory one + word at a time. */ + a1 = (unsigned long *) s1; + a2 = (unsigned long *) s2; + while (n >= LBLOCKSIZE) { + if (*a1 != *a2) + break; + a1++; + a2++; + n -= LBLOCKSIZE; + } - /* check m mod LBLOCKSIZE remaining characters */ + /* check m mod LBLOCKSIZE remaining characters */ - s1 = (char *) a1; - s2 = (char *) a2; - } + s1 = (char *) a1; + s2 = (char *) a2; + } - while (n--) { - if (*s1 != *s2) - return *s1 - *s2; - s1++; - s2++; - } + while (n--) { + if (*s1 != *s2) + return *s1 - *s2; + s1++; + s2++; + } - return 0; -#endif /* not PREFER_SIZE_OVER_SPEED */ + return 0; +#endif /* not PREFER_SIZE_OVER_SPEED */ } Modified: dcload/dcload-ip/target-src/dcload/memset.S =================================================================== --- dcload/dcload-ip/target-src/dcload/memset.S 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/memset.S 2012-05-31 19:56:48 UTC (rev 784) @@ -31,7 +31,7 @@ tst #3,r0 bf L_align_loop -L_dup_bytes: +L_dup_bytes: swap.b r5,r2 ! Duplicate bytes across longword or r2,r5 swap.w r5,r2 Modified: dcload/dcload-ip/target-src/dcload/net.c =================================================================== --- dcload/dcload-ip/target-src/dcload/net.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/net.c 2012-05-31 19:56:48 UTC (rev 784) @@ -8,215 +8,215 @@ void process_broadcast(unsigned char *pkt, int len) { - ether_header_t *ether_header = (ether_header_t *)pkt; - arp_header_t *arp_header = (arp_header_t *)(pkt + ETHER_H_LEN); - unsigned char tmp[10]; - unsigned int ip = htonl(our_ip); + ether_header_t *ether_header = (ether_header_t *)pkt; + arp_header_t *arp_header = (arp_header_t *)(pkt + ETHER_H_LEN); + unsigned char tmp[10]; + unsigned int ip = htonl(our_ip); - if (ether_header->type[1] != 0x06) /* ARP */ - return; + if (ether_header->type[1] != 0x06) /* ARP */ + return; - /* hardware address space = ethernet */ - if (arp_header->hw_addr_space != 0x0100) - return; + /* hardware address space = ethernet */ + if (arp_header->hw_addr_space != 0x0100) + return; - /* protocol address space = IP */ - if (arp_header->proto_addr_space != 0x0008) - return; + /* protocol address space = IP */ + if (arp_header->proto_addr_space != 0x0008) + return; - if (arp_header->opcode == 0x0100) { /* arp request */ - if (our_ip == 0) /* return if we don't know our ip */ - return; - if (!memcmp(arp_header->proto_target, &ip, 4)) { /* for us */ - /* put src hw address into dest hw address */ - memcpy(ether_header->dest, ether_header->src, 6); - /* put our hw address into src hw address */ - memcpy(ether_header->src, bb->mac, 6); - arp_header->opcode = 0x0200; /* arp reply */ - /* swap sender and target addresses */ - memcpy(tmp, arp_header->hw_sender, 10); - memcpy(arp_header->hw_sender, arp_header->hw_target, 10); - memcpy(arp_header->hw_target, tmp, 10); - /* put our hw address into sender hw address */ - memcpy(arp_header->hw_sender, bb->mac, 6); - /* transmit */ - bb->tx(pkt, ETHER_H_LEN + ARP_H_LEN); + if (arp_header->opcode == 0x0100) { /* arp request */ + if (our_ip == 0) /* return if we don't know our ip */ + return; + if (!memcmp(arp_header->proto_target, &ip, 4)) { /* for us */ + /* put src hw address into dest hw address */ + memcpy(ether_header->dest, ether_header->src, 6); + /* put our hw address into src hw address */ + memcpy(ether_header->src, bb->mac, 6); + arp_header->opcode = 0x0200; /* arp reply */ + /* swap sender and target addresses */ + memcpy(tmp, arp_header->hw_sender, 10); + memcpy(arp_header->hw_sender, arp_header->hw_target, 10); + memcpy(arp_header->hw_target, tmp, 10); + /* put our hw address into sender hw address */ + memcpy(arp_header->hw_sender, bb->mac, 6); + /* transmit */ + bb->tx(pkt, ETHER_H_LEN + ARP_H_LEN); + } } - } } unsigned char pkt_buf[1514]; void process_icmp(ether_header_t *ether, ip_header_t *ip, icmp_header_t *icmp) { - unsigned int i; - unsigned char tmp[6]; + unsigned int i; + unsigned char tmp[6]; - memset(pkt_buf, 0, ntohs(ip->length) + (ntohs(ip->length)%2) - 4*(ip->version_ihl & 0x0f)); + memset(pkt_buf, 0, ntohs(ip->length) + (ntohs(ip->length)%2) - 4*(ip->version_ihl & 0x0f)); - /* check icmp checksum */ - i = icmp->checksum; - icmp->checksum = 0; - memcpy(pkt_buf, icmp, ntohs(ip->length) - 4*(ip->version_ihl & 0x0f)); - icmp->checksum = checksum((unsigned short *)pkt_buf, (ntohs(ip->length)+1)/2 - 2*(ip->version_ihl & 0x0f)); - if (i != icmp->checksum) - return; - - if (icmp->type == 8) { /* echo request */ - icmp->type = 0; /* echo reply */ - /* swap src and dest hw addresses */ - memcpy(tmp, ether->dest, 6); - memcpy(ether->dest, ether->src, 6); - memcpy(ether->src, tmp, 6); - /* swap src and dest ip addresses */ - memcpy(&i, &ip->src, 4); - memcpy(&ip->src, &ip->dest, 4); - memcpy(&ip->dest, &i, 4); - /* recompute ip header checksum */ - ip->checksum = 0; - ip->checksum = checksum((unsigned short *)ip, 2*(ip->version_ihl & 0x0f)); - /* recompute icmp checksum */ - icmp->checksum = 0; - icmp->checksum = checksum((unsigned short *)icmp, ntohs(ip->length)/2 - 2*(ip->version_ihl & 0x0f)); - /* transmit */ - bb->tx(ether, ETHER_H_LEN + ntohs(ip->length)); - } + /* check icmp checksum */ + i = icmp->checksum; + icmp->checksum = 0; + memcpy(pkt_buf, icmp, ntohs(ip->length) - 4*(ip->version_ihl & 0x0f)); + icmp->checksum = checksum((unsigned short *)pkt_buf, (ntohs(ip->length)+1)/2 - 2*(ip->version_ihl & 0x0f)); + if (i != icmp->checksum) + return; + + if (icmp->type == 8) { /* echo request */ + icmp->type = 0; /* echo reply */ + /* swap src and dest hw addresses */ + memcpy(tmp, ether->dest, 6); + memcpy(ether->dest, ether->src, 6); + memcpy(ether->src, tmp, 6); + /* swap src and dest ip addresses */ + memcpy(&i, &ip->src, 4); + memcpy(&ip->src, &ip->dest, 4); + memcpy(&ip->dest, &i, 4); + /* recompute ip header checksum */ + ip->checksum = 0; + ip->checksum = checksum((unsigned short *)ip, 2*(ip->version_ihl & 0x0f)); + /* recompute icmp checksum */ + icmp->checksum = 0; + icmp->checksum = checksum((unsigned short *)icmp, ntohs(ip->length)/2 - 2*(ip->version_ihl & 0x0f)); + /* transmit */ + bb->tx(ether, ETHER_H_LEN + ntohs(ip->length)); + } } typedef struct { - unsigned int load_address; - unsigned int load_size; - unsigned char map[16384]; + unsigned int load_address; + unsigned int load_size; + unsigned char map[16384]; } bin_info_t; bin_info_t bin_info; void process_udp(ether_header_t *ether, ip_header_t *ip, udp_header_t *udp) { - ip_udp_pseudo_header_t *pseudo; - unsigned short i; - command_t *command; + ip_udp_pseudo_header_t *pseudo; + unsigned short i; + command_t *command; - pseudo = (ip_udp_pseudo_header_t *)pkt_buf; - pseudo->src_ip = ip->src; - pseudo->dest_ip = ip->dest; - pseudo->zero = 0; - pseudo->protocol = ip->protocol; - pseudo->udp_length = udp->length; - pseudo->src_port = udp->src; - pseudo->dest_port = udp->dest; - pseudo->length = udp->length; - pseudo->checksum = 0; - memset(pseudo->data, 0, ntohs(udp->length) - 8 + (ntohs(udp->length)%2)); - memcpy(pseudo->data, udp->data, ntohs(udp->length) - 8); + pseudo = (ip_udp_pseudo_header_t *)pkt_buf; + pseudo->src_ip = ip->src; + pseudo->dest_ip = ip->dest; + pseudo->zero = 0; + pseudo->protocol = ip->protocol; + pseudo->udp_length = udp->length; + pseudo->src_port = udp->src; + pseudo->dest_port = udp->dest; + pseudo->length = udp->length; + pseudo->checksum = 0; + memset(pseudo->data, 0, ntohs(udp->length) - 8 + (ntohs(udp->length)%2)); + memcpy(pseudo->data, udp->data, ntohs(udp->length) - 8); - /* checksum == 0 means no checksum */ - if (udp->checksum != 0) - i = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + ntohs(udp->length) - 9 + 1)/2); - else - i = 0; - /* checksum == 0xffff means checksum was really 0 */ - if (udp->checksum == 0xffff) - udp->checksum = 0; + /* checksum == 0 means no checksum */ + if (udp->checksum != 0) + i = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + ntohs(udp->length) - 9 + 1)/2); + else + i = 0; + /* checksum == 0xffff means checksum was really 0 */ + if (udp->checksum == 0xffff) + udp->checksum = 0; - if (i != udp->checksum) { -/* scif_puts("UDP CHECKSUM BAD\n"); */ - return; - } + if (i != udp->checksum) { + /* scif_puts("UDP CHECKSUM BAD\n"); */ + return; + } - make_ether(ether->src, ether->dest, (ether_header_t *)pkt_buf); + make_ether(ether->src, ether->dest, (ether_header_t *)pkt_buf); - command = (command_t *)udp->data; + command = (command_t *)udp->data; - if (!memcmp(command->id, CMD_EXECUTE, 4)) { - cmd_execute(ether, ip, udp, command); - } + if (!memcmp(command->id, CMD_EXECUTE, 4)) { + cmd_execute(ether, ip, udp, command); + } - if (!memcmp(command->id, CMD_LOADBIN, 4)) { - cmd_loadbin(ip, udp, command); - } - - if (!memcmp(command->id, CMD_PARTBIN, 4)) { - cmd_partbin(ip, udp, command); - } + if (!memcmp(command->id, CMD_LOADBIN, 4)) { + cmd_loadbin(ip, udp, command); + } - if (!memcmp(command->id, CMD_DONEBIN, 4)) { - cmd_donebin(ip, udp, command); - } + if (!memcmp(command->id, CMD_PARTBIN, 4)) { + cmd_partbin(ip, udp, command); + } - if (!memcmp(command->id, CMD_SENDBINQ, 4)) { - cmd_sendbinq(ip, udp, command); - } + if (!memcmp(command->id, CMD_DONEBIN, 4)) { + cmd_donebin(ip, udp, command); + } - if (!memcmp(command->id, CMD_SENDBIN, 4)) { - cmd_sendbin(ip, udp, command); - } + if (!memcmp(command->id, CMD_SENDBINQ, 4)) { + cmd_sendbinq(ip, udp, command); + } - if (!memcmp(command->id, CMD_VERSION, 4)) { - cmd_version(ip, udp, command); - } + if (!memcmp(command->id, CMD_SENDBIN, 4)) { + cmd_sendbin(ip, udp, command); + } - if (!memcmp(command->id, CMD_RETVAL, 4)) { - cmd_retval(ip, udp, command); - } + if (!memcmp(command->id, CMD_VERSION, 4)) { + cmd_version(ip, udp, command); + } - if (!memcmp(command->id, CMD_REBOOT, 4)) { - cmd_reboot(ip, udp, command); - } + if (!memcmp(command->id, CMD_RETVAL, 4)) { + cmd_retval(ip, udp, command); + } + + if (!memcmp(command->id, CMD_REBOOT, 4)) { + cmd_reboot(ip, udp, command); + } } void process_mine(unsigned char *pkt, int len) { - ether_header_t *ether_header = (ether_header_t *)pkt; - ip_header_t *ip_header = (ip_header_t *)(pkt + 14); - icmp_header_t *icmp_header; - udp_header_t *udp_header; - ip_udp_pseudo_header_t *ip_udp_pseudo_header; - unsigned char tmp[6]; - int i; - - if (ether_header->type[1] != 0x00) - return; + ether_header_t *ether_header = (ether_header_t *)pkt; + ip_header_t *ip_header = (ip_header_t *)(pkt + 14); + icmp_header_t *icmp_header; + udp_header_t *udp_header; + ip_udp_pseudo_header_t *ip_udp_pseudo_header; + unsigned char tmp[6]; + int i; - /* ignore fragmented packets */ + if (ether_header->type[1] != 0x00) + return; - if (ntohs(ip_header->flags_frag_offset) & 0x3fff) - return; - - /* check ip header checksum */ - i = ip_header->checksum; - ip_header->checksum = 0; - ip_header->checksum = checksum((unsigned short *)ip_header, 2*(ip_header->version_ihl & 0x0f)); - if (i != ip_header->checksum) - return; + /* ignore fragmented packets */ - switch (ip_header->protocol) { - case 1: /* icmp */ - icmp_header = (icmp_header_t *)(pkt + ETHER_H_LEN + 4*(ip_header->version_ihl & 0x0f)); - process_icmp(ether_header, ip_header, icmp_header); - break; - case 17: /* udp */ - udp_header = (udp_header_t *)(pkt + ETHER_H_LEN + 4*(ip_header->version_ihl & 0x0f)); - process_udp(ether_header, ip_header, udp_header); - default: - break; - } + if (ntohs(ip_header->flags_frag_offset) & 0x3fff) + return; + + /* check ip header checksum */ + i = ip_header->checksum; + ip_header->checksum = 0; + ip_header->checksum = checksum((unsigned short *)ip_header, 2*(ip_header->version_ihl & 0x0f)); + if (i != ip_header->checksum) + return; + + switch (ip_header->protocol) { + case 1: /* icmp */ + icmp_header = (icmp_header_t *)(pkt + ETHER_H_LEN + 4*(ip_header->version_ihl & 0x0f)); + process_icmp(ether_header, ip_header, icmp_header); + break; + case 17: /* udp */ + udp_header = (udp_header_t *)(pkt + ETHER_H_LEN + 4*(ip_header->version_ihl & 0x0f)); + process_udp(ether_header, ip_header, udp_header); + default: + break; + } } void process_pkt(unsigned char *pkt, int len) { - ether_header_t *ether_header = (ether_header_t *)pkt; + ether_header_t *ether_header = (ether_header_t *)pkt; - if (ether_header->type[0] != 0x08) - return; + if (ether_header->type[0] != 0x08) + return; - if (!memcmp(ether_header->dest, broadcast, 6)) { - process_broadcast(pkt, len); - return; - } + if (!memcmp(ether_header->dest, broadcast, 6)) { + process_broadcast(pkt, len); + return; + } - if (!memcmp(ether_header->dest, bb->mac, 6)) { - process_mine(pkt, len); - return; - } + if (!memcmp(ether_header->dest, bb->mac, 6)) { + process_mine(pkt, len); + return; + } } Modified: dcload/dcload-ip/target-src/dcload/packet.c =================================================================== --- dcload/dcload-ip/target-src/dcload/packet.c 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/packet.c 2012-05-31 19:56:48 UTC (rev 784) @@ -2,67 +2,67 @@ unsigned short checksum(unsigned short *buf, int count) { - unsigned long sum = 0; + unsigned long sum = 0; - while (count--) { - sum += *buf++; - if (sum & 0xffff0000) { - sum &= 0xffff; - sum++; + while (count--) { + sum += *buf++; + if (sum & 0xffff0000) { + sum &= 0xffff; + sum++; + } } - } - return ~(sum & 0xffff); + return ~(sum & 0xffff); } void make_ether(char *dest, char *src, ether_header_t *ether) { - memcpy(ether->dest, dest, 6); - memcpy(ether->src, src, 6); - ether->type[0] = 8; - ether->type[1] = 0; + memcpy(ether->dest, dest, 6); + memcpy(ether->src, src, 6); + ether->type[0] = 8; + ether->type[1] = 0; } void make_ip(int dest, int src, int length, char protocol, ip_header_t *ip) { - ip->version_ihl = 0x45; - ip->tos = 0; - ip->length = htons(20 + length); - ip->packet_id = 0; - ip->flags_frag_offset = htons(0x4000); - ip->ttl = 0x40; - ip->protocol = protocol; - ip->checksum = 0; - ip->src = htonl(src); - ip->dest = htonl(dest); + ip->version_ihl = 0x45; + ip->tos = 0; + ip->length = htons(20 + length); + ip->packet_id = 0; + ip->flags_frag_offset = htons(0x4000); + ip->ttl = 0x40; + ip->protocol = protocol; + ip->checksum = 0; + ip->src = htonl(src); + ip->dest = htonl(dest); - ip->checksum = checksum((unsigned short *)ip, sizeof(ip_header_t)/2); + ip->checksum = checksum((unsigned short *)ip, sizeof(ip_header_t)/2); } unsigned char crap[1514]; void make_udp(unsigned short dest, unsigned short src, unsigned char * data, int length, ip_header_t *ip, udp_header_t *udp) { - ip_udp_pseudo_header_t *pseudo = (ip_udp_pseudo_header_t *)crap; +ip_udp_pseudo_header_t *pseudo = (ip_udp_pseudo_header_t *)crap; - udp->src = htons(src); - udp->dest = htons(dest); - udp->length = htons(length + 8); - udp->checksum = 0; - memcpy(udp->data, data, length); +udp->src = htons(src); +udp->dest = htons(dest); +udp->length = htons(length + 8); +udp->checksum = 0; +memcpy(udp->data, data, length); - pseudo->src_ip = ip->src; - pseudo->dest_ip = ip->dest; - pseudo->zero = 0; - pseudo->protocol = ip->protocol; - pseudo->udp_length = udp->length; - pseudo->src_port = udp->src; - pseudo->dest_port = udp->dest; - pseudo->length = udp->length; - pseudo->checksum = 0; - memset(pseudo->data, 0, length + (length%2)); - memcpy(pseudo->data, udp->data, length); +pseudo->src_ip = ip->src; +pseudo->dest_ip = ip->dest; +pseudo->zero = 0; +pseudo->protocol = ip->protocol; +pseudo->udp_length = udp->length; +pseudo->src_port = udp->src; +pseudo->dest_port = udp->dest; +pseudo->length = udp->length; +pseudo->checksum = 0; +memset(pseudo->data, 0, length + (length%2)); +memcpy(pseudo->data, udp->data, length); - udp->checksum = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + length)/2); - if (udp->checksum == 0) - udp->checksum = 0xffff; +udp->checksum = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + length)/2); +if (udp->checksum == 0) + udp->checksum = 0xffff; } Modified: dcload/dcload-ip/target-src/dcload/packet.h =================================================================== --- dcload/dcload-ip/target-src/dcload/packet.h 2012-05-30 23:23:18 UTC (rev 783) +++ dcload/dcload-ip/target-src/dcload/packet.h 2012-05-31 19:56:48 UTC (rev 784) @@ -3,62 +3,62 @@ typedef struct { - unsigned char dest[6]; - unsigned char src[6]; - unsigned char type[2]; + unsigned char dest[6]; + unsigned char src[6]; + unsigned char type[2]; } ether_header_t; typedef struct { - unsigned char version_ihl __attribute__ ((packed)); - unsigned char tos __attribute__ ((packed)); - unsigned short length __attribute__ ((packed)); - unsigned short packet_id __attribute__ ((packed)); - unsigned short flags_frag_offset __attribute__ ((packed)); - unsigned char ttl __attribute__ ((packed)); - unsigned char protocol __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned int src __attribute__ ((packed)); - unsigned int dest __attribute__ ((packed)); + unsigned char version_ihl __attribute__ ((packed)); + unsigned char tos __attribute__ ((packed)); + unsigned short length __attribute__ ((packed)); + unsigned short packet_id __attribute__ ((packed)); + unsigned short flags_frag_offset __attribute__ ((packed)); + unsigned char ttl __attribute__ ((packed)); + unsigned char protocol __attribute__ ((packed)); + unsigned short checksum __attribute__ ((packed)); + unsigned int src __attribute__ ((packed)); + unsigned int dest __attribute__ ((packed)); } ip_header_t; typedef struct { - unsigned short src __attribute__ ((packed)); - unsigned short dest __attribute__ ((packed)); - unsigned short length __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned char data[1] __attribute__ ((packed)); + unsigned short src __attribute__ ((packed)); + unsigned short dest __attribute__ ((packed)); + unsigned short length __attribute__ ((packed)); + unsigned short checksum __attribute__ ((packed)); + unsigned char data[1] __attribute__ ((packed)); } udp_header_t; typedef struct { - unsigned char type __attribute__ ((packed)); - unsigned char code __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned int misc __attribute__ ((packed)); + unsigned char type __attribute__ ((packed)); + unsigned char code __attribute__ ((packed)); + unsigned short checksum __attribute__ ((packed)); + unsigned int misc __attribute__ ((packed)); } icmp_header_t; typedef struct { - unsigned short hw_addr_space __attribute__ ((packed)); - unsigned short proto_addr_space __attribute__ ((packed)); - unsigned char hw_addr_len __attribute__ ((packed)); - unsigned char proto_addr_len __attribute__ ((packed)); - unsigned short opcode __attribute__ ((packed)); - unsigned char hw_sender[6] __attribute__ ((packed)); - unsigned char proto_sender[4] __attribute__ ((packed)); - unsigned char hw_target[6] __attribute__ ((packed)); - unsigned char proto_target[4] __attribute__ ((packed)); + unsigned short hw_addr_space __attribute__ ((packed)); + unsigned short proto_addr_space __attribute__ ((packed)); + unsigned char hw_addr_len __attribute__ ((packed)); + unsigned char proto_addr_len __attribute__ ((packed)); + unsigned short opcode __attribute__ ((packed)); + unsigned char hw_sender[6] __attribute__ ((packed)); + unsigned char proto_sender[4] __attribute__ ((packed)); + unsigned char hw_target[6] __attribute__ ((packed)); + unsigned char proto_target[4] __attribute__ ((packed)); } arp_header_t; typedef struct { - unsigned int src_ip __attribute__ ((packed)); - unsigned int dest_ip __attribute__ ((packed)); - unsigned char zero __attribute__ ((packed)); - unsigned char protocol __attribute__ ((packed)); - unsigned short udp_length __attribute__ ((packed)); - unsigned short src_port __attribute__ ((packed)); - unsigned short dest_port __attribute__ ((packed)); - unsigned short length __attribute__ ((packed)); - unsigned short checksum __attribute__ ((packed)); - unsigned char data[1] __attribute__ ((packed)); + unsigned int src_ip __attribute__ ((packed)); + unsigned int dest_ip __attribute__ ((packed)); + unsigned char zero __attribute__ ((packed)); + unsigned char protocol __attribute__ ((packed)); + unsigned short udp_length __attribute__ ((packed)); + unsigned short src_port __attribute__ ((packed)); + unsigned short dest_port __attribute__ ((packed)); + unsigned short length __attribute__ ((packed)); + unsigned short checksum __attribute__ ((packed)); + unsigned char data[1] __attribute__ ((packed)); } ip_udp_pseudo_header_t; unsigned short checksum(unsigned short *buf, int... [truncated message content] |
From: <ljs...@us...> - 2012-05-30 23:23:24
|
Revision: 783 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=783&view=rev Author: ljsebald Date: 2012-05-30 23:23:18 +0000 (Wed, 30 May 2012) Log Message: ----------- Clarify a couple of error cases... Modified Paths: -------------- kos/kernel/net/net_ipv4.c kos/kernel/net/net_ipv6.c kos/kernel/net/net_ndp.c Modified: kos/kernel/net/net_ipv4.c =================================================================== --- kos/kernel/net/net_ipv4.c 2012-05-27 17:31:21 UTC (rev 782) +++ kos/kernel/net/net_ipv4.c 2012-05-30 23:23:18 UTC (rev 783) @@ -100,6 +100,11 @@ if(net == NULL) { net = net_default_dev; + + if(!net) { + errno = ENETDOWN; + return -1; + } } net_ipv4_parse_address(ntohl(hdr->dest), dest_ip); Modified: kos/kernel/net/net_ipv6.c =================================================================== --- kos/kernel/net/net_ipv6.c 2012-05-27 17:31:21 UTC (rev 782) +++ kos/kernel/net/net_ipv6.c 2012-05-30 23:23:18 UTC (rev 783) @@ -59,6 +59,7 @@ net = net_default_dev; if(!net) { + errno = ENETDOWN; return -1; } } @@ -94,8 +95,7 @@ return err; } else if(err == -2) { - ++ipv6_stats.pkt_send_failed; - return err; + return 0; } } @@ -128,6 +128,7 @@ net = net_default_dev; if(!net) { + errno = ENETDOWN; return -1; } } Modified: kos/kernel/net/net_ndp.c =================================================================== --- kos/kernel/net/net_ndp.c 2012-05-27 17:31:21 UTC (rev 782) +++ kos/kernel/net/net_ndp.c 2012-05-30 23:23:18 UTC (rev 783) @@ -181,7 +181,7 @@ /* Its not there, add an incomplete entry and solicit the info */ if(!(i = (ndp_entry_t *)malloc(sizeof(ndp_entry_t)))) { - return -3; + return -1; } memset(i, 0, sizeof(ndp_entry_t)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-27 17:31:28
|
Revision: 782 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=782&view=rev Author: ljsebald Date: 2012-05-27 17:31:21 +0000 (Sun, 27 May 2012) Log Message: ----------- Add ARP/NDP entries on incoming packets. Modified Paths: -------------- kos/include/kos/net.h kos/kernel/net/net_arp.c kos/kernel/net/net_input.c kos/kernel/net/net_ipv4.c kos/kernel/net/net_ipv4.h kos/kernel/net/net_ipv6.c kos/kernel/net/net_ipv6.h Modified: kos/include/kos/net.h =================================================================== --- kos/include/kos/net.h 2012-05-27 05:04:51 UTC (rev 781) +++ kos/include/kos/net.h 2012-05-27 17:31:21 UTC (rev 782) @@ -266,7 +266,8 @@ entry, otherwise set to jiffies. \retval 0 On success (no error conditions defined). */ -int net_arp_insert(netif_t *nif, uint8 mac[6], uint8 ip[4], uint32 timestamp); +int net_arp_insert(netif_t *nif, const uint8 mac[6], const uint8 ip[4], + uint32 timestamp); /** \brief Look up an entry from the ARP cache. @@ -285,7 +286,7 @@ \retval -1 A query is outstanding for that address. \retval -2 Address not found, query generated. */ -int net_arp_lookup(netif_t *nif, uint8 ip_in[4], uint8 mac_out[6], +int net_arp_lookup(netif_t *nif, const uint8 ip_in[4], uint8 mac_out[6], const ip_hdr_t *pkt, const uint8 *data, int data_size); /** \brief Do a reverse ARP lookup. @@ -299,7 +300,7 @@ \retval 0 On success. \retval -1 On failure. */ -int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], uint8 mac_in[6]); +int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], const uint8 mac_in[6]); /** \brief Receive an ARP packet and process it (called by net_input). \param nif The network device in use. @@ -314,7 +315,7 @@ \param ip The IP to query. \retval 0 On success (no error conditions defined). */ -int net_arp_query(netif_t *nif, uint8 ip[4]); +int net_arp_query(netif_t *nif, const uint8 ip[4]); /***** net_input.c *********************************************************/ Modified: kos/kernel/net/net_arp.c =================================================================== --- kos/kernel/net/net_arp.c 2012-05-27 05:04:51 UTC (rev 781) +++ kos/kernel/net/net_arp.c 2012-05-27 17:31:21 UTC (rev 782) @@ -3,7 +3,7 @@ kernel/net/net_arp.c Copyright (C) 2002 Dan Potter - Copyright (C) 2005, 2010 Lawrence Sebald + Copyright (C) 2005, 2010, 2012 Lawrence Sebald */ #include <string.h> @@ -98,7 +98,8 @@ } /* Add an entry to the ARP cache manually */ -int net_arp_insert(netif_t *nif, uint8 mac[6], uint8 ip[4], uint32 timestamp) { +int net_arp_insert(netif_t *nif, const uint8 mac[6], const uint8 ip[4], + uint32 timestamp) { netarp_t *cur; /* First make sure the entry isn't already there */ @@ -142,7 +143,7 @@ query will be sent and an error will be returned. Thus your packet send should also fail. Later when the transmit retries, hopefully the answer will have arrived. */ -int net_arp_lookup(netif_t *nif, uint8 ip_in[4], uint8 mac_out[6], +int net_arp_lookup(netif_t *nif, const uint8 ip_in[4], uint8 mac_out[6], const ip_hdr_t *pkt, const uint8 *data, int data_size) { netarp_t *cur; @@ -202,7 +203,7 @@ /* Do a reverse ARP lookup: look for an IP for a given mac address; note that if this fails, you have no recourse. */ -int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], uint8 mac_in[6]) { +int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], const uint8 mac_in[6]) { netarp_t *cur; /* Look for the entry */ @@ -276,7 +277,7 @@ } /* Generate an ARP who-has query on the given device */ -int net_arp_query(netif_t *nif, uint8 ip[4]) { +int net_arp_query(netif_t *nif, const uint8 ip[4]) { arp_pkt_t pkt_out; eth_hdr_t eth_hdr; uint8 buf[sizeof(arp_pkt_t) + sizeof(eth_hdr_t)]; Modified: kos/kernel/net/net_input.c =================================================================== --- kos/kernel/net/net_input.c 2012-05-27 05:04:51 UTC (rev 781) +++ kos/kernel/net/net_input.c 2012-05-27 17:31:21 UTC (rev 782) @@ -2,7 +2,7 @@ kernel/net/net_input.c Copyright (C) 2002 Dan Potter - Copyright (C) 2005 Lawrence Sebald + Copyright (C) 2005, 2012 Lawrence Sebald */ #include <stdio.h> @@ -31,14 +31,16 @@ switch(proto) { case 0x0800: return net_ipv4_input(nif, data + sizeof(eth_hdr_t), - len - sizeof(eth_hdr_t)); + len - sizeof(eth_hdr_t), + (const eth_hdr_t *)data); case 0x0806: return net_arp_input(nif, data, len); case 0x86DD: return net_ipv6_input(nif, data + sizeof(eth_hdr_t), - len - sizeof(eth_hdr_t)); + len - sizeof(eth_hdr_t), + (const eth_hdr_t *)data); default: return 0; Modified: kos/kernel/net/net_ipv4.c =================================================================== --- kos/kernel/net/net_ipv4.c 2012-05-27 05:04:51 UTC (rev 781) +++ kos/kernel/net/net_ipv4.c 2012-05-27 17:31:21 UTC (rev 782) @@ -113,7 +113,7 @@ ++ipv4_stats.pkt_sent; /* Send it "away" */ - net_ipv4_input(NULL, pkt, 4 * (hdr->version_ihl & 0x0f) + size); + net_ipv4_input(NULL, pkt, 4 * (hdr->version_ihl & 0x0f) + size, NULL); return 0; } @@ -193,11 +193,13 @@ return net_ipv4_frag_send(net, &hdr, data, size); } -int net_ipv4_input(netif_t *src, const uint8 *pkt, int pktsize) { +int net_ipv4_input(netif_t *src, const uint8 *pkt, int pktsize, + const eth_hdr_t *eth) { ip_hdr_t *ip; int i; uint8 *data; int hdrlen; + uint8 ipa[4]; if(pktsize < sizeof(ip_hdr_t)) { /* This is obviously a bad packet, drop it */ @@ -227,6 +229,12 @@ data = (uint8 *)(pkt + hdrlen); + /* Add the sender to the ARP cache, if they're not already there. */ + if(eth) { + net_ipv4_parse_address(ntohl(ip->src), ipa); + net_arp_insert(src, eth->src, ipa, jiffies); + } + /* Submit the packet for possible reassembly. */ return net_ipv4_reassemble(src, ip, data, ntohs(ip->length) - hdrlen); } Modified: kos/kernel/net/net_ipv4.h =================================================================== --- kos/kernel/net/net_ipv4.h 2012-05-27 05:04:51 UTC (rev 781) +++ kos/kernel/net/net_ipv4.h 2012-05-27 17:31:21 UTC (rev 782) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kernel/net/net_ipv4.h - Copyright (C) 2005, 2007, 2008 Lawrence Sebald + Copyright (C) 2005, 2007, 2008, 2012 Lawrence Sebald */ @@ -32,7 +32,8 @@ int size); int net_ipv4_send(netif_t *net, const uint8 *data, int size, int id, int ttl, int proto, uint32 src, uint32 dst); -int net_ipv4_input(netif_t *src, const uint8 *pkt, int pktsize); +int net_ipv4_input(netif_t *src, const uint8 *pkt, int pktsize, + const eth_hdr_t *eth); int net_ipv4_input_proto(netif_t *net, ip_hdr_t *ip, const uint8 *data); uint16 net_ipv4_checksum_pseudo(in_addr_t src, in_addr_t dst, uint8 proto, Modified: kos/kernel/net/net_ipv6.c =================================================================== --- kos/kernel/net/net_ipv6.c 2012-05-27 05:04:51 UTC (rev 781) +++ kos/kernel/net/net_ipv6.c 2012-05-27 17:31:21 UTC (rev 782) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kernel/net/net_ipv6.c - Copyright (C) 2010 Lawrence Sebald + Copyright (C) 2010, 2012 Lawrence Sebald */ @@ -71,7 +71,7 @@ ++ipv6_stats.pkt_sent; /* Send the packet "away" */ - net_ipv6_input(NULL, pkt, sizeof(ipv6_hdr_t) + data_size); + net_ipv6_input(NULL, pkt, sizeof(ipv6_hdr_t) + data_size, NULL); return 0; } else if(IN6_IS_ADDR_MULTICAST(&hdr->dst_addr)) { @@ -168,7 +168,8 @@ return net_ipv6_send_packet(net, &hdr, data, data_size); } -int net_ipv6_input(netif_t *src, const uint8 *pkt, int pktsize) { +int net_ipv6_input(netif_t *src, const uint8 *pkt, int pktsize, + const eth_hdr_t *eth) { ipv6_hdr_t *ip; uint8 next_hdr; int pos, len, rv; @@ -193,6 +194,9 @@ pos = sizeof(ipv6_hdr_t); next_hdr = ip->next_header; + if(eth) + net_ndp_insert(src, eth->src, &ip->src_addr, 1); + /* XXXX: Parse options and deal with fragmentation */ switch(next_hdr) { case IPV6_HDR_ICMP: Modified: kos/kernel/net/net_ipv6.h =================================================================== --- kos/kernel/net/net_ipv6.h 2012-05-27 05:04:51 UTC (rev 781) +++ kos/kernel/net/net_ipv6.h 2012-05-27 17:31:21 UTC (rev 782) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kernel/net/net_ipv6.h - Copyright (C) 2010 Lawrence Sebald + Copyright (C) 2010, 2012 Lawrence Sebald */ @@ -10,6 +10,8 @@ #include <kos/net.h> +#include "net_ipv4.h" + #ifdef PACKED #undef PACKED #endif @@ -46,7 +48,8 @@ int net_ipv6_send(netif_t *net, const uint8 *data, int data_size, int hop_limit, int proto, const struct in6_addr *src, const struct in6_addr *dst); -int net_ipv6_input(netif_t *src, const uint8 *pkt, int pktsize); +int net_ipv6_input(netif_t *src, const uint8 *pkt, int pktsize, + const eth_hdr_t *eth); uint16 net_ipv6_checksum_pseudo(const struct in6_addr *src, const struct in6_addr *dst, uint32 upper_len, uint8 next_hdr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-27 05:04:57
|
Revision: 781 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=781&view=rev Author: ljsebald Date: 2012-05-27 05:04:51 +0000 (Sun, 27 May 2012) Log Message: ----------- Make the network shutdown function so that it doesn't crash when called in an IRQ. Modified Paths: -------------- kos/kernel/fs/fs_socket.c kos/kernel/net/net_core.c kos/kernel/net/net_dhcp.c kos/kernel/net/net_ipv4_frag.c kos/kernel/net/net_thd.c kos/kernel/net/net_thd.h kos/kernel/net/net_udp.c Modified: kos/kernel/fs/fs_socket.c =================================================================== --- kos/kernel/fs/fs_socket.c 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/fs/fs_socket.c 2012-05-27 05:04:51 UTC (rev 781) @@ -32,7 +32,16 @@ static void fs_socket_close(void *hnd) { net_socket_t *sock = (net_socket_t *)hnd; - rlock_lock(list_rlock); + if(irq_inside_int()) { + if(rlock_trylock(list_rlock)) { + errno = EWOULDBLOCK; + return; + } + } + else { + rlock_lock(list_rlock); + } + LIST_REMOVE(sock, sock_list); rlock_unlock(list_rlock); @@ -128,24 +137,18 @@ if(initted == 0) return 0; - rlock_lock(list_rlock); c = LIST_FIRST(&sockets); while(c != NULL) { n = LIST_NEXT(c, sock_list); - fs_close(c->fd); - - free(c); c = n; } if(nmmgr_handler_remove(&vh.nmmgr) < 0) return -1; - rlock_unlock(list_rlock); rlock_destroy(list_rlock); - rlock_lock(proto_rlock); i = TAILQ_FIRST(&protocols); while(i != NULL) { j = TAILQ_NEXT(i, entry); @@ -153,7 +156,6 @@ i = j; } - rlock_unlock(proto_rlock); rlock_destroy(proto_rlock); list_rlock = NULL; Modified: kos/kernel/net/net_core.c =================================================================== --- kos/kernel/net/net_core.c 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/net/net_core.c 2012-05-27 05:04:51 UTC (rev 781) @@ -196,6 +196,11 @@ if(!net_initted) return; + /* Stop the network thread, since otherwise we might have problems down the + road here... This simplifies things greatly in shutting everything else + down in here. */ + net_thd_kill(); + /* Shut down DHCP */ net_dhcp_shutdown(); Modified: kos/kernel/net/net_dhcp.c =================================================================== --- kos/kernel/net/net_dhcp.c 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/net/net_dhcp.c 2012-05-27 05:04:51 UTC (rev 781) @@ -652,27 +652,14 @@ } void net_dhcp_shutdown() { - int old; - - /* Remove the callback first, otherwise it'll probably end up grabbing the - lock, which we don't want it to do! */ - if(dhcp_cbid != -1) { + if(dhcp_cbid != -1) net_thd_del_callback(dhcp_cbid); - } - /* This song and dance is to make sure nobody else is holding the lock, - otherwise, we can't destroy it! Granted, nobody should be able to be - holding the lock if we've deleted the dhcp callback already... */ + if(dhcp_sock != -1) + close(dhcp_sock); + if(dhcp_lock) { - rlock_lock(dhcp_lock); - old = irq_disable(); - rlock_unlock(dhcp_lock); rlock_destroy(dhcp_lock); dhcp_lock = NULL; - irq_restore(old); } - - if(dhcp_sock != -1) { - close(dhcp_sock); - } } Modified: kos/kernel/net/net_ipv4_frag.c =================================================================== --- kos/kernel/net/net_ipv4_frag.c 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/net/net_ipv4_frag.c 2012-05-27 05:04:51 UTC (rev 781) @@ -307,7 +307,8 @@ struct ip_frag *c, *n; if(frag_mutex) { - mutex_lock(frag_mutex); + if(cbid != -1) + net_thd_del_callback(cbid); c = TAILQ_FIRST(&frags); while(c) { @@ -317,11 +318,6 @@ c = n; } - if(cbid != -1) { - net_thd_del_callback(cbid); - } - - mutex_unlock(frag_mutex); mutex_destroy(frag_mutex); } Modified: kos/kernel/net/net_thd.c =================================================================== --- kos/kernel/net/net_thd.c 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/net/net_thd.c 2012-05-27 05:04:51 UTC (rev 781) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kernel/net/net_thd.c - Copyright (C) 2009 Lawrence Sebald + Copyright (C) 2009, 2012 Lawrence Sebald */ @@ -104,6 +104,20 @@ return thd_current == thd; } +void net_thd_kill() { + /* Do things gracefully, if we can... Otherwise, punt. */ + done = 1; + + if(!irq_inside_int()) { + thd_join(thd, NULL); + } + else { + thd_destroy(thd); + } + + thd = NULL; +} + int net_thd_init() { TAILQ_INIT(&cbs); done = 0; @@ -118,8 +132,9 @@ struct thd_cb *c, *n; /* Kill the thread. */ - done = 1; - thd_join(thd, NULL); + if(thd) { + net_thd_kill(); + } /* Free any handlers that we have laying around */ c = TAILQ_FIRST(&cbs); Modified: kos/kernel/net/net_thd.h =================================================================== --- kos/kernel/net/net_thd.h 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/net/net_thd.h 2012-05-27 05:04:51 UTC (rev 781) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kernel/net/net_thd.h - Copyright (C) 2009 Lawrence Sebald + Copyright (C) 2009, 2012 Lawrence Sebald */ @@ -19,6 +19,8 @@ int net_thd_is_current(); +void net_thd_kill(); + int net_thd_init(); void net_thd_shutdown(); Modified: kos/kernel/net/net_udp.c =================================================================== --- kos/kernel/net/net_udp.c 2012-05-27 04:39:08 UTC (rev 780) +++ kos/kernel/net/net_udp.c 2012-05-27 05:04:51 UTC (rev 781) @@ -142,8 +142,8 @@ /* See if we requested a specific port or not */ if(realaddr6.sin6_port != 0) { - /* Make sure we don't already have a socket bound to the - port specified */ + /* Make sure we don't already have a socket bound to the port + specified */ LIST_FOREACH(iter, &net_udp_sockets, sock_list) { if(iter == udpsock) continue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-27 04:39:14
|
Revision: 780 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=780&view=rev Author: ljsebald Date: 2012-05-27 04:39:08 +0000 (Sun, 27 May 2012) Log Message: ----------- Free packets attached to an ARP request when we shut down. Modified Paths: -------------- kos/kernel/net/net_arp.c Modified: kos/kernel/net/net_arp.c =================================================================== --- kos/kernel/net/net_arp.c 2012-05-27 04:25:24 UTC (rev 779) +++ kos/kernel/net/net_arp.c 2012-05-27 04:39:08 UTC (rev 780) @@ -339,6 +339,10 @@ a1 = LIST_FIRST(&net_arp_cache); while (a1 != NULL) { a2 = LIST_NEXT(a1, ac_list); + if(a1->pkt) { + free(a1->pkt); + free(a1->data); + } free(a1); a1 = a2; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-27 04:25:30
|
Revision: 779 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=779&view=rev Author: ljsebald Date: 2012-05-27 04:25:24 +0000 (Sun, 27 May 2012) Log Message: ----------- Treat destroying a recursive lock more like destroying any other sync primitive is. Modified Paths: -------------- kos/kernel/thread/recursive_lock.c Modified: kos/kernel/thread/recursive_lock.c =================================================================== --- kos/kernel/thread/recursive_lock.c 2012-05-26 03:35:17 UTC (rev 778) +++ kos/kernel/thread/recursive_lock.c 2012-05-27 04:25:24 UTC (rev 779) @@ -35,8 +35,13 @@ /* Destroy a recursive lock */ void rlock_destroy(recursive_lock_t *l) { assert(l); - assert(!l->count); + /* XXX Do something with queued threads */ + if(l->count) { + dbglog(DBG_WARNING, "Destroying a recursive lock that is currently " + "being held by a thread!\n"); + } + free(l); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-26 03:35:23
|
Revision: 778 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=778&view=rev Author: ljsebald Date: 2012-05-26 03:35:17 +0000 (Sat, 26 May 2012) Log Message: ----------- Make the make_banner.sh script show the SVN revision number on a copy of the repository checked out from SVN rather than the rather unhelpful ##version##. Modified Paths: -------------- kos/kernel/arch/dreamcast/kernel/make_banner.sh Modified: kos/kernel/arch/dreamcast/kernel/make_banner.sh =================================================================== --- kos/kernel/arch/dreamcast/kernel/make_banner.sh 2012-05-26 03:15:54 UTC (rev 777) +++ kos/kernel/arch/dreamcast/kernel/make_banner.sh 2012-05-26 03:35:17 UTC (rev 778) @@ -4,7 +4,14 @@ echo 'char banner[] = ' > banner.c -echo -n '"KallistiOS ##version##: ' >> banner.c +echo -n '"KallistiOS ' >> banner.c +if [ -d ".svn" ]; then + echo -n 'SVN r' >> banner.c + echo -n `svnversion` >> banner.c + echo -n ': ' >> banner.c +else + echo -n '##version##: ' >> banner.c +fi echo -n `date` >> banner.c echo '\n"' >> banner.c This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-26 03:16:01
|
Revision: 777 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=777&view=rev Author: ljsebald Date: 2012-05-26 03:15:54 +0000 (Sat, 26 May 2012) Log Message: ----------- A few networking things in this revision: 1. Fix a few fs_socket functions to be able to be called in an IRQ safely. 2. Add a new fs_socket_open_sock() function to open a socket without calling the protocol handler's socket() function. 3. Add SOMAXCONN to sys/socket.h. Modified Paths: -------------- kos/include/kos/fs_socket.h kos/include/sys/socket.h kos/kernel/fs/fs_socket.c kos/kernel/net/net_udp.c Modified: kos/include/kos/fs_socket.h =================================================================== --- kos/include/kos/fs_socket.h 2012-05-25 15:55:43 UTC (rev 776) +++ kos/include/kos/fs_socket.h 2012-05-26 03:15:54 UTC (rev 777) @@ -293,6 +293,24 @@ int fs_socket_shutdown(); /* \endcond */ +/** \brief Open a socket without calling the protocol initializer. + + This function creates a new socket, but does not call the protocol's + socket() function. This is meant to be used for things like accepting an + incoming connection, where calling the regular socket initializer could + cause issues. You shouldn't really have any need to call this function + unless you are implementing a new protocol handler. + + \param proto The protocol to use for the socket. + \return The newly created socket on success, NULL on failure. + + \par Error Conditions: + \em EWOULDBLOCK - if the function would block in an IRQ \n + \em ENOMEM - out of memory \n + \em EMFILE - too many files open +*/ +net_socket_t *fs_socket_open_sock(fs_socket_proto_t *proto); + /** \defgroup sock_flags Socket flags These are the available flags to set with the fs_socket_setflags() function. Modified: kos/include/sys/socket.h =================================================================== --- kos/include/sys/socket.h 2012-05-25 15:55:43 UTC (rev 776) +++ kos/include/sys/socket.h 2012-05-26 03:15:54 UTC (rev 777) @@ -117,6 +117,9 @@ /** \brief Disable further send and receive operations. */ #define SHUT_RDWR (SHUT_RD | SHUT_WR) +/** \brief Maximum backlog for a listening socket. */ +#define SOMAXCONN 32 + /** \brief Accept a new connection on a socket. This function extracts the first connection on the queue of connections of Modified: kos/kernel/fs/fs_socket.c =================================================================== --- kos/kernel/fs/fs_socket.c 2012-05-25 15:55:43 UTC (rev 776) +++ kos/kernel/fs/fs_socket.c 2012-05-26 03:15:54 UTC (rev 777) @@ -170,14 +170,26 @@ fs_socket_proto_t *i; int rv = -2; + if(!initted) + return -1; + /* Find the protocol handler and call its input function... */ - rlock_lock(proto_rlock); + if(irq_inside_int()) { + if(rlock_trylock(proto_rlock)) { + return -1; + } + } + else { + rlock_lock(proto_rlock); + } + TAILQ_FOREACH(i, &protocols, entry) { if(i->protocol == protocol) { rv = i->input(src, domain, hdr, data, size); break; } } + rlock_unlock(proto_rlock); return rv; @@ -202,7 +214,18 @@ } int fs_socket_proto_add(fs_socket_proto_t *proto) { - rlock_lock(proto_rlock); + if(!initted) + return -1; + + if(irq_inside_int()) { + if(rlock_trylock(proto_rlock)) { + return -1; + } + } + else { + rlock_lock(proto_rlock); + } + TAILQ_INSERT_TAIL(&protocols, proto, entry); rlock_unlock(proto_rlock); @@ -213,8 +236,19 @@ fs_socket_proto_t *i; int rv = -1; + if(!initted) + return -1; + /* Make sure its registered. */ - rlock_lock(proto_rlock); + if(irq_inside_int()) { + if(rlock_trylock(proto_rlock)) { + return -1; + } + } + else { + rlock_lock(proto_rlock); + } + TAILQ_FOREACH(i, &protocols, entry) { if(i == proto) { /* We've got it, remove it. */ @@ -223,6 +257,7 @@ break; } } + rlock_unlock(proto_rlock); return rv; @@ -238,7 +273,15 @@ return -1; } - rlock_lock(proto_rlock); + if(irq_inside_int()) { + if(rlock_trylock(proto_rlock)) { + errno = EWOULDBLOCK; + return -1; + } + } + else { + rlock_lock(proto_rlock); + } /* Look for a matching protocol entry. */ TAILQ_FOREACH(i, &protocols, entry) { @@ -247,11 +290,10 @@ } } - rlock_unlock(proto_rlock); - /* If i is NULL, we got through the whole list without finding anything. */ if(!i) { errno = EPROTONOSUPPORT; + rlock_unlock(proto_rlock); return -1; } @@ -259,6 +301,7 @@ sock = (net_socket_t *)malloc(sizeof(net_socket_t)); if(!sock) { errno = ENOMEM; + rlock_unlock(proto_rlock); return -1; } @@ -266,26 +309,77 @@ sock->fd = fs_open_handle(&vh, sock); if(sock->fd < 0) { free(sock); + rlock_unlock(proto_rlock); return -1; } /* Initialize protocol-specific data */ if(i->socket(sock, domain, type, protocol) == -1) { fs_close(sock->fd); + rlock_unlock(proto_rlock); return -1; } /* Finish initialization */ sock->protocol = i; + rlock_unlock(proto_rlock); /* Add this socket into the list of sockets, and return */ - rlock_lock(list_rlock); + if(irq_inside_int()) { + if(rlock_trylock(list_rlock)) { + free(sock); + errno = EWOULDBLOCK; + return -1; + } + } + else { + rlock_lock(list_rlock); + } + LIST_INSERT_HEAD(&sockets, sock, sock_list); rlock_unlock(list_rlock); return sock->fd; } +net_socket_t *fs_socket_open_sock(fs_socket_proto_t *proto) { + net_socket_t *sock; + + /* Allocate the socket structure, if we have the space */ + sock = (net_socket_t *)malloc(sizeof(net_socket_t)); + if(!sock) { + errno = ENOMEM; + return NULL; + } + + /* Attempt to get a handle for this socket */ + sock->fd = fs_open_handle(&vh, sock); + if(sock->fd < 0) { + free(sock); + return NULL; + } + + /* Initialize as much as we can */ + sock->protocol = proto; + + /* Add this socket into the list of sockets, and return */ + if(irq_inside_int()) { + if(rlock_trylock(list_rlock)) { + free(sock); + errno = EWOULDBLOCK; + return NULL; + } + } + else { + rlock_lock(list_rlock); + } + + LIST_INSERT_HEAD(&sockets, sock, sock_list); + rlock_unlock(list_rlock); + + return sock; +} + int accept(int sock, struct sockaddr *address, socklen_t *address_len) { net_socket_t *hnd; Modified: kos/kernel/net/net_udp.c =================================================================== --- kos/kernel/net/net_udp.c 2012-05-25 15:55:43 UTC (rev 776) +++ kos/kernel/net/net_udp.c 2012-05-26 03:15:54 UTC (rev 777) @@ -145,6 +145,9 @@ /* Make sure we don't already have a socket bound to the port specified */ LIST_FOREACH(iter, &net_udp_sockets, sock_list) { + if(iter == udpsock) + continue; + if(iter->local_addr.sin6_port == realaddr6.sin6_port) { mutex_unlock(udp_mutex); errno = EADDRINUSE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <los...@us...> - 2012-05-25 15:55:49
|
Revision: 776 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=776&view=rev Author: lostgeneration Date: 2012-05-25 15:55:43 +0000 (Fri, 25 May 2012) Log Message: ----------- Pull dreamcast specific ldscript from environ_base.sh Modified Paths: -------------- kos/environ_base.sh kos/environ_dreamcast.sh Modified: kos/environ_base.sh =================================================================== --- kos/environ_base.sh 2012-05-24 21:57:50 UTC (rev 775) +++ kos/environ_base.sh 2012-05-25 15:55:43 UTC (rev 776) @@ -31,7 +31,7 @@ case $GCCVER in 4*) - export KOS_LDFLAGS="${KOS_LDFLAGS} -T${KOS_BASE}/utils/ldscripts/shlelf.xc -nodefaultlibs ${KOS_LIB_PATHS}" ;; + export KOS_LDFLAGS="${KOS_LDFLAGS} ${KOS_LD_SCRIPT} -nodefaultlibs ${KOS_LIB_PATHS}" ;; *) export KOS_LDFLAGS="${KOS_LDFLAGS} -nostartfiles -nostdlib ${KOS_LIB_PATHS}" ;; esac Modified: kos/environ_dreamcast.sh =================================================================== --- kos/environ_dreamcast.sh 2012-05-24 21:57:50 UTC (rev 775) +++ kos/environ_dreamcast.sh 2012-05-25 15:55:43 UTC (rev 776) @@ -4,6 +4,8 @@ export KOS_CFLAGS="${KOS_CFLAGS} -ml -m4-single-only -fno-crossjumping" export KOS_AFLAGS="${KOS_AFLAGS} -little" export KOS_LDFLAGS="${KOS_LDFLAGS} -ml -m4-single-only -Wl,-Ttext=0x8c010000" +# Needed for GCC >= 4 +export KOS_LD_SCRIPT="-T${KOS_BASE}/utils/ldscripts/shlelf.xc" # If we're building for DC, we need the ARM compiler paths as well. if [ x${KOS_ARCH} = xdreamcast ]; then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 21:57:57
|
Revision: 775 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=775&view=rev Author: ljsebald Date: 2012-05-24 21:57:50 +0000 (Thu, 24 May 2012) Log Message: ----------- A bit of preliminary initial work on TCP. All this will do at the moment is send RST responses to any incoming TCP segments. That way, the other end will know immediately that there's nobody home on TCP to answer them. Modified Paths: -------------- kos/include/kos/net.h kos/kernel/net/Makefile kos/kernel/net/net_core.c Added Paths: ----------- kos/kernel/net/net_tcp.c Modified: kos/include/kos/net.h =================================================================== --- kos/include/kos/net.h 2012-05-24 20:50:51 UTC (rev 774) +++ kos/include/kos/net.h 2012-05-24 21:57:50 UTC (rev 775) @@ -2,7 +2,7 @@ include/kos/net.h Copyright (C) 2002 Dan Potter - Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Lawrence Sebald + Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Lawrence Sebald */ @@ -639,6 +639,16 @@ /** \brief Shutdown UDP. */ void net_udp_shutdown(); +/***** net_tcp.c **********************************************************/ + +/** \brief Init TCP. + \retval 0 On success (no error conditions defined). +*/ +int net_tcp_init(); + +/** \brief Shutdown TCP. */ +void net_tcp_shutdown(); + /***** net_crc.c **********************************************************/ /** \brief Calculate a "little-endian" CRC-32 over a block of data. Modified: kos/kernel/net/Makefile =================================================================== --- kos/kernel/net/Makefile 2012-05-24 20:50:51 UTC (rev 774) +++ kos/kernel/net/Makefile 2012-05-24 21:57:50 UTC (rev 775) @@ -6,7 +6,7 @@ OBJS = net_core.o net_arp.o net_input.o net_icmp.o net_ipv4.o net_udp.o OBJS += net_dhcp.o net_ipv4_frag.o net_thd.o net_ipv6.o net_icmp6.o net_crc.o -OBJS += net_ndp.o net_multicast.o +OBJS += net_ndp.o net_multicast.o net_tcp.o SUBDIRS = include $(KOS_BASE)/Makefile.prefab Modified: kos/kernel/net/net_core.c =================================================================== --- kos/kernel/net/net_core.c 2012-05-24 20:50:51 UTC (rev 774) +++ kos/kernel/net/net_core.c 2012-05-24 21:57:50 UTC (rev 775) @@ -49,50 +49,50 @@ /* Register a network device */ int net_reg_device(netif_t *device) { - /* Make sure it's not already registered */ - if (device->flags & NETIF_REGISTERED) { - dbglog(DBG_WARNING, "net_reg_device: '%s' is already registered\n", - device->name); - return -1; - } + /* Make sure it's not already registered */ + if (device->flags & NETIF_REGISTERED) { + dbglog(DBG_WARNING, "net_reg_device: '%s' is already registered\n", + device->name); + return -1; + } - /* Insert it into the interface list */ - LIST_INSERT_HEAD(&net_if_list, device, if_list); + /* Insert it into the interface list */ + LIST_INSERT_HEAD(&net_if_list, device, if_list); - /* Mark it as registered */ - device->flags |= NETIF_REGISTERED; + /* Mark it as registered */ + device->flags |= NETIF_REGISTERED; - /* We need to do more processing in here eventually like looking for - duplicate device IDs and assigning new indeces, but that can - wait until we're actually supporting a box with the possibility - of more than one network interface... which probably won't happen - any time soon... */ + /* We need to do more processing in here eventually like looking for + duplicate device IDs and assigning new indeces, but that can + wait until we're actually supporting a box with the possibility + of more than one network interface... which probably won't happen + any time soon... */ - /* Success */ - return 0; + /* Success */ + return 0; } /* Unregister a network device */ int net_unreg_device(netif_t *device) { - /* Make sure it really was registered */ - if (!(device->flags & NETIF_REGISTERED)) { - dbglog(DBG_WARNING, "net_unreg_device: '%s' isn't registered\n", - device->name); - return -1; - } + /* Make sure it really was registered */ + if (!(device->flags & NETIF_REGISTERED)) { + dbglog(DBG_WARNING, "net_unreg_device: '%s' isn't registered\n", + device->name); + return -1; + } - /* Remove it from the list */ - LIST_REMOVE(device, if_list); + /* Remove it from the list */ + LIST_REMOVE(device, if_list); - /* Mark it as unregistered */ - device->flags &= ~NETIF_REGISTERED; + /* Mark it as unregistered */ + device->flags &= ~NETIF_REGISTERED; - /* Success */ - return 0; + /* Success */ + return 0; } struct netif_list * net_get_if_list() { - return &net_if_list; + return &net_if_list; } /*****************************************************************************/ @@ -100,139 +100,141 @@ /* Set default */ netif_t *net_set_default(netif_t *n) { - netif_t *olddev = net_default_dev; + netif_t *olddev = net_default_dev; - net_default_dev = n; + net_default_dev = n; - return olddev; + return olddev; } /* Device detect / init */ int net_dev_init() { - int detected = 0; - netif_t *cur; + int detected = 0; + netif_t *cur; - LIST_FOREACH(cur, &net_if_list, if_list) { - /* Make sure we have one */ - if (cur->if_detect(cur) < 0) - continue; + LIST_FOREACH(cur, &net_if_list, if_list) { + /* Make sure we have one */ + if (cur->if_detect(cur) < 0) + continue; - /* Ok, we do -- initialize it */ - if (cur->if_init(cur) < 0) - continue; + /* Ok, we do -- initialize it */ + if (cur->if_init(cur) < 0) + continue; - /* It's initialized, so now enable it */ - if (cur->if_start(cur) < 0) { - cur->if_shutdown(cur); - continue; - } + /* It's initialized, so now enable it */ + if (cur->if_start(cur) < 0) { + cur->if_shutdown(cur); + continue; + } - /* Set the first detected device to be the default */ - if(net_default_dev == NULL) - net_set_default(cur); + /* Set the first detected device to be the default */ + if(net_default_dev == NULL) + net_set_default(cur); - detected++; - } + detected++; + } - dbglog(DBG_DEBUG, "net_dev_init: detected %d usable network device(s)\n", detected); + dbglog(DBG_DEBUG, "net_dev_init: detected %d usable network device(s)\n", detected); - return 0; + return 0; } /* Init */ int net_init() { - int rv = 0; + int rv = 0; - /* Make sure we haven't already done this */ - if(net_initted) - return 0; + /* Make sure we haven't already done this */ + if(net_initted) + return 0; - /* Detect and potentially initialize devices */ - if (net_dev_init() < 0) - return -1; + /* Detect and potentially initialize devices */ + if (net_dev_init() < 0) + return -1; - /* Initialize the network thread. */ - net_thd_init(); + /* Initialize the network thread. */ + net_thd_init(); - /* Initialize the ARP cache */ - net_arp_init(); + /* Initialize the ARP cache */ + net_arp_init(); - /* Initialize the NDP cache */ - net_ndp_init(); + /* Initialize the NDP cache */ + net_ndp_init(); - /* Initialize IPv4 fragmentation support */ - net_ipv4_frag_init(); + /* Initialize IPv4 fragmentation support */ + net_ipv4_frag_init(); /* Initialize multicast support */ net_multicast_init(); - /* Initialize IPv6 support */ - net_ipv6_init(); + /* Initialize IPv6 support */ + net_ipv6_init(); - /* Initialize the sockets-like interface */ - fs_socket_init(); + /* Initialize the sockets-like interface */ + fs_socket_init(); - /* Initialize the UDP system */ - net_udp_init(); + /* Initialize the UDP/TCP systems */ + net_udp_init(); + net_tcp_init(); - /* Initialize the DHCP system */ - net_dhcp_init(); + /* Initialize the DHCP system */ + net_dhcp_init(); - if(net_default_dev && !net_default_dev->ip_addr[0]) { - rv = net_dhcp_request(); - } + if(net_default_dev && !net_default_dev->ip_addr[0]) { + rv = net_dhcp_request(); + } - net_initted = 1; + net_initted = 1; - return rv; + return rv; } /* Shutdown */ void net_shutdown() { - netif_t *cur; + netif_t *cur; - /* Make sure we actually initialized the net stuff to begin with */ - if(!net_initted) - return; + /* Make sure we actually initialized the net stuff to begin with */ + if(!net_initted) + return; - /* Shut down DHCP */ - net_dhcp_shutdown(); + /* Shut down DHCP */ + net_dhcp_shutdown(); - /* Shut down the UDP system */ - net_udp_shutdown(); + /* Shut down the UDP/TCP systems */ + net_tcp_shutdown(); + net_udp_shutdown(); - /* Shut down the sockets-like interface */ - fs_socket_shutdown(); + /* Shut down the sockets-like interface */ + fs_socket_shutdown(); - /* Shut down IPv6 support */ - net_ipv6_shutdown(); + /* Shut down IPv6 support */ + net_ipv6_shutdown(); /* Shut down multicast support */ net_multicast_shutdown(); - /* Shut down IPv4 fragmentation support */ - net_ipv4_frag_shutdown(); + /* Shut down IPv4 fragmentation support */ + net_ipv4_frag_shutdown(); - /* Shut down the NDP cache */ - net_ndp_shutdown(); + /* Shut down the NDP cache */ + net_ndp_shutdown(); - /* Shut down the ARP cache */ - net_arp_shutdown(); + /* Shut down the ARP cache */ + net_arp_shutdown(); - /* Shut down the network thread */ - net_thd_shutdown(); + /* Shut down the network thread */ + net_thd_shutdown(); - /* Shut down all activated network devices */ - LIST_FOREACH(cur, &net_if_list, if_list) { - if (cur->flags & NETIF_RUNNING && cur->if_stop) - cur->if_stop(cur); - if (cur->flags & NETIF_INITIALIZED && cur->if_shutdown) - cur->if_shutdown(cur); - cur->flags &= ~NETIF_REGISTERED; - } + /* Shut down all activated network devices */ + LIST_FOREACH(cur, &net_if_list, if_list) { + if (cur->flags & NETIF_RUNNING && cur->if_stop) + cur->if_stop(cur); + if (cur->flags & NETIF_INITIALIZED && cur->if_shutdown) + cur->if_shutdown(cur); + cur->flags &= ~NETIF_REGISTERED; + } - /* Blank out the list */ - LIST_INIT(&net_if_list); + /* Blank out the list */ + LIST_INIT(&net_if_list); - net_initted = 0; + net_initted = 0; } Added: kos/kernel/net/net_tcp.c =================================================================== --- kos/kernel/net/net_tcp.c (rev 0) +++ kos/kernel/net/net_tcp.c 2012-05-24 21:57:50 UTC (rev 775) @@ -0,0 +1,200 @@ +/* KallistiOS ##version## + + kernel/net/net_tcp.c + Copyright (C) 2012 Lawrence Sebald + +*/ + +#include <errno.h> +#include <stdint.h> +#include <sys/socket.h> + +#include <kos/net.h> +#include <kos/fs_socket.h> + +#include "net_ipv4.h" +#include "net_ipv6.h" + +typedef struct tcp_hdr { + uint16_t src_port; + uint16_t dst_port; + uint32_t seq; + uint32_t ack; + uint16_t off_flags; + uint16_t wnd; + uint16_t checksum; + uint16_t urg; +} __attribute__((packed)) tcp_hdr_t; + +/* Flags that can be set in the off_flags field of the above struct */ +#define TCP_FLAG_FIN 0x01 +#define TCP_FLAG_SYN 0x02 +#define TCP_FLAG_RST 0x04 +#define TCP_FLAG_PSH 0x08 +#define TCP_FLAG_ACK 0x10 +#define TCP_FLAG_URG 0x20 + +#define TCP_GET_OFFSET(x) (((x) & 0xF000) >> 10) +#define TCP_OFFSET(y) (((y) & 0x0F) << 12) + +/* Sockets interface. These are all stubs at the moment. */ +static int net_tcp_socket(net_socket_t *hnd, int domain, int type, int proto) { + errno = EPROTONOSUPPORT; + return -1; +} + +static void net_tcp_close(net_socket_t *hnd) { + errno = EBADF; +} + +static int net_tcp_setflags(net_socket_t *hnd, uint32_t flags) { + errno = EBADF; + return -1; +} + +static int net_tcp_accept(net_socket_t *hnd, struct sockaddr *addr, + socklen_t *addr_len) { + errno = EBADF; + return -1; +} + +static int net_tcp_bind(net_socket_t *hnd, const struct sockaddr *addr, + socklen_t addr_len) { + errno = EBADF; + return -1; +} + +static int net_tcp_connect(net_socket_t *hnd, const struct sockaddr *addr, + socklen_t addr_len) { + errno = EBADF; + return -1; +} + +static int net_tcp_listen(net_socket_t *hnd, int backlog) { + errno = EBADF; + return -1; +} + +static ssize_t net_tcp_recvfrom(net_socket_t *hnd, void *buffer, size_t length, + int flags, struct sockaddr *addr, + socklen_t *addr_len) { + errno = EBADF; + return -1; +} + +static ssize_t net_tcp_sendto(net_socket_t *hnd, const void *message, + size_t length, int flags, + const struct sockaddr *addr, socklen_t addr_len) { + errno = EBADF; + return -1; +} + +static int net_tcp_shutdownsock(net_socket_t *hnd, int how) { + errno = EBADF; + return -1; +} + +static void tcp_send_rst(netif_t *net, const struct in6_addr *src, + const struct in6_addr *dst, const tcp_hdr_t *ohdr, + int size) { + tcp_hdr_t pkt; + uint16 cs; + uint16 flags = ntohs(ohdr->off_flags); + + /* Fill in the packet */ + pkt.src_port = ohdr->dst_port; + pkt.dst_port = ohdr->src_port; + + if(flags & TCP_FLAG_SYN) { + size += 1; + } + + if(flags & TCP_FLAG_ACK) { + pkt.seq = ohdr->ack; + pkt.ack = 0; + pkt.off_flags = TCP_FLAG_RST; + } + else { + pkt.seq = 0; + pkt.ack = htonl(ntohl(ohdr->seq) + size); + pkt.off_flags = TCP_FLAG_ACK | TCP_FLAG_RST; + } + + pkt.off_flags = htons(pkt.off_flags | TCP_OFFSET(5)); + pkt.wnd = 0; + pkt.checksum = 0; + pkt.urg = 0; + + cs = net_ipv6_checksum_pseudo(dst, src, IPPROTO_TCP, sizeof(tcp_hdr_t)); + pkt.checksum = net_ipv4_checksum((const uint8 *)&pkt, sizeof(tcp_hdr_t), + cs); + + net_ipv6_send(net, (const uint8 *)&pkt, sizeof(tcp_hdr_t), 0, IPPROTO_TCP, + dst, src); +} + +static int net_tcp_input(netif_t *src, int domain, const void *hdr, + const uint8 *data, int size) { + struct in6_addr srca, dsta; + const ip_hdr_t *ip4; + const ipv6_hdr_t *ip6; + const tcp_hdr_t *tcp; + uint16 flags; + + switch(domain) { + case AF_INET: + ip4 = (const ip_hdr_t *)hdr; + srca.__s6_addr.__s6_addr32[0] = srca.__s6_addr.__s6_addr32[1] = 0; + srca.__s6_addr.__s6_addr16[4] = 0; + srca.__s6_addr.__s6_addr16[5] = 0xFFFF; + srca.__s6_addr.__s6_addr32[3] = ip4->src; + dsta.__s6_addr.__s6_addr32[0] = dsta.__s6_addr.__s6_addr32[1] = 0; + dsta.__s6_addr.__s6_addr16[4] = 0; + dsta.__s6_addr.__s6_addr16[5] = 0xFFFF; + dsta.__s6_addr.__s6_addr32[3] = ip4->dest; + break; + + case AF_INET6: + ip6 = (const ipv6_hdr_t *)hdr; + srca = ip6->src_addr; + dsta = ip6->dst_addr; + break; + } + + /* Send a RST, since we don't actually support TCP just yet... */ + tcp = (const tcp_hdr_t *)data; + flags = ntohs(tcp->off_flags); + + if(!(flags & TCP_FLAG_RST)) { + tcp_send_rst(src, &srca, &dsta, tcp, size - TCP_GET_OFFSET(flags)); + } + + return 0; +} + +/* Protocol handler for fs_socket. */ +static fs_socket_proto_t proto = { + FS_SOCKET_PROTO_ENTRY, + PF_INET6, /* domain */ + SOCK_STREAM, /* type */ + IPPROTO_TCP, /* protocol */ + net_tcp_socket, /* socket */ + net_tcp_close, /* close */ + net_tcp_setflags, /* setflags */ + net_tcp_accept, /* accept */ + net_tcp_bind, /* bind */ + net_tcp_connect, /* connect */ + net_tcp_listen, /* listen */ + net_tcp_recvfrom, /* recvfrom */ + net_tcp_sendto, /* sendto */ + net_tcp_shutdownsock, /* shutdown */ + net_tcp_input /* input */ +}; + +int net_tcp_init() { + return fs_socket_proto_add(&proto); +} + +void net_tcp_shutdown() { + fs_socket_proto_remove(&proto); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 20:50:57
|
Revision: 774 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=774&view=rev Author: ljsebald Date: 2012-05-24 20:50:51 +0000 (Thu, 24 May 2012) Log Message: ----------- Rename the input function for UDP and add SOCK_STREAM to sys/socket.h. Modified Paths: -------------- kos/include/sys/socket.h kos/kernel/net/net_udp.c Modified: kos/include/sys/socket.h =================================================================== --- kos/include/sys/socket.h 2012-05-24 19:26:21 UTC (rev 773) +++ kos/include/sys/socket.h 2012-05-24 20:50:51 UTC (rev 774) @@ -81,18 +81,25 @@ /** \brief Datagram socket type. This socket type specifies that the socket in question transmits datagrams - that may or may not be reliably transmitted. With IPv4, this implies using - UDP as the underlying protocol. + that may or may not be reliably transmitted. With IP, this implies using UDP + as the underlying protocol. */ #define SOCK_DGRAM 1 +/** \brief Stream socket type. + + This socket type specifies that the socket in question acts like a stream + or pipe between the two endpoints. Sockets of this type can be assumed to be + reliable -- unless an error is returned, all packets will be received at the + other end in the order they are sent. With IP, this implies using TCP as the + underlying protocol. +*/ +#define SOCK_STREAM 2 + /** \brief Internet domain sockets for use with IPv4 addresses. */ #define AF_INET 1 -/** \brief Internet domain sockets for use with IPv6 addresses. - - Note, these are NOT supported just yet. -*/ +/** \brief Internet domain sockets for use with IPv6 addresses. */ #define AF_INET6 2 /** \brief Protocol family for Internet domain sockets (IPv4). */ Modified: kos/kernel/net/net_udp.c =================================================================== --- kos/kernel/net/net_udp.c 2012-05-24 19:26:21 UTC (rev 773) +++ kos/kernel/net/net_udp.c 2012-05-24 20:50:51 UTC (rev 774) @@ -802,8 +802,8 @@ return -1; } -static int net_udp_real_input(netif_t *src, int domain, const void *hdr, - const uint8 *data, int size) { +static int net_udp_input(netif_t *src, int domain, const void *hdr, + const uint8 *data, int size) { if(!udp_mutex) return -1; @@ -912,7 +912,7 @@ net_udp_recvfrom, net_udp_sendto, net_udp_shutdownsock, - net_udp_real_input + net_udp_input }; int net_udp_init() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 19:26:30
|
Revision: 773 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=773&view=rev Author: ljsebald Date: 2012-05-24 19:26:21 +0000 (Thu, 24 May 2012) Log Message: ----------- Remove pointless (and illegal) cast. Modified Paths: -------------- dcload/dcload-serial/target-src/dcload/dcload.c Modified: dcload/dcload-serial/target-src/dcload/dcload.c =================================================================== --- dcload/dcload-serial/target-src/dcload/dcload.c 2012-05-24 03:14:55 UTC (rev 772) +++ dcload/dcload-serial/target-src/dcload/dcload.c 2012-05-24 19:26:21 UTC (rev 773) @@ -284,7 +284,7 @@ ok = 'G'; scif_putchar(ok); total -= newsize; - (unsigned char *) data += newsize; + data += newsize; } else { ok = 'B'; scif_putchar(ok); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 03:15:01
|
Revision: 772 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=772&view=rev Author: ljsebald Date: 2012-05-24 03:14:55 +0000 (Thu, 24 May 2012) Log Message: ----------- Add simple example of IPv6 UDP sockets. Modified Paths: -------------- kos/examples/dreamcast/network/Makefile Added Paths: ----------- kos/examples/dreamcast/network/udpecho6/ kos/examples/dreamcast/network/udpecho6/Makefile kos/examples/dreamcast/network/udpecho6/echo.c Modified: kos/examples/dreamcast/network/Makefile =================================================================== --- kos/examples/dreamcast/network/Makefile 2012-05-24 03:12:20 UTC (rev 771) +++ kos/examples/dreamcast/network/Makefile 2012-05-24 03:14:55 UTC (rev 772) @@ -9,6 +9,7 @@ $(KOS_MAKE) -C httpd $(KOS_MAKE) -C ping $(KOS_MAKE) -C ping6 + $(KOS_MAKE) -C udpecho6 # $(KOS_MAKE) -C dcload-ip-lwip-test clean: @@ -16,6 +17,7 @@ $(KOS_MAKE) -C httpd clean $(KOS_MAKE) -C ping clean $(KOS_MAKE) -C ping6 clean + $(KOS_MAKE) -C udpecho6 clean # $(KOS_MAKE) -C dcload-ip-lwip-test clean dist: @@ -23,6 +25,7 @@ $(KOS_MAKE) -C httpd dist $(KOS_MAKE) -C ping dist $(KOS_MAKE) -C ping6 dist + $(KOS_MAKE) -C udpecho6 dist # $(KOS_MAKE) -C dcload-ip-lwip-test dist Added: kos/examples/dreamcast/network/udpecho6/Makefile =================================================================== --- kos/examples/dreamcast/network/udpecho6/Makefile (rev 0) +++ kos/examples/dreamcast/network/udpecho6/Makefile 2012-05-24 03:14:55 UTC (rev 772) @@ -0,0 +1,32 @@ +# +# Basic KallistiOS skeleton / test program +# (c)2001 Dan Potter +# + +# Put the filename of the output binary here +TARGET = echo.elf + +# List all of your C files here, but change the extension to ".o" +OBJS = echo.o + +all: rm-elf $(TARGET) + +include $(KOS_BASE)/Makefile.rules + +clean: + -rm -f $(TARGET) $(OBJS) + +rm-elf: + -rm -f $(TARGET) + +$(TARGET): $(OBJS) + $(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \ + $(OBJS) $(OBJEXTRA) $(KOS_LIBS) + +run: $(TARGET) + $(KOS_LOADER) $(TARGET) -n + +dist: + rm -f $(OBJS) + $(KOS_STRIP) $(TARGET) + Added: kos/examples/dreamcast/network/udpecho6/echo.c =================================================================== --- kos/examples/dreamcast/network/udpecho6/echo.c (rev 0) +++ kos/examples/dreamcast/network/udpecho6/echo.c 2012-05-24 03:14:55 UTC (rev 772) @@ -0,0 +1,116 @@ +/* KallistiOS ##version## + + echo.c + Copyright (C) 2012 Lawrence Sebald + + This example is a very simple UDP/IPv6 server that simply echos whatever is + sent to it to the screen. Nothing really fancy here at all, but it does + provide a nice test program for making sure that sockets work right. + + This example also shows how to display things on the framebuffer with the + "fb" device for dbgio. + + To interact with this, you'll probably want to use the "nc" or "netcat" + program on your PC. On Mac OS X, I did something like this to test it out: + nc -6 -u [Dreamcast's IPv6 address] 1337 + Then, whatever you type should echo over on the screen hooked up to the DC. + +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include <arch/arch.h> +#include <kos/net.h> +#include <kos/thread.h> +#include <kos/dbgio.h> +#include <dc/maple/controller.h> + +KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET); + +#define DATA_SIZE 1280 +#define ECHO_PORT 1337 + +#define ERR_EXIT() { thd_sleep(2000); exit(EXIT_FAILURE); } + +int main(int argc, char *argv[]) { + /* The address to ping... */ + uint8 data[DATA_SIZE]; + char str1[INET6_ADDRSTRLEN]; + int i, sock; + struct sockaddr_in6 addr; + ssize_t sz; + socklen_t alen; + + /* Set a callback to exit when start is pressed */ + cont_btn_callback(0, CONT_START, (cont_btn_callback_t)arch_exit); + + dbgio_dev_select("fb"); + + /* Send out a router solicitation so that we get a global prefix. */ + printf("Attempting to solicit a router\n"); + net_icmp6_send_rsol(net_default_dev); + thd_sleep(10000); + + if(!net_default_dev->ip6_addr_count) { + printf("Couldn't get a global prefix!\n"); + } + else { + inet_ntop(AF_INET6, &net_default_dev->ip6_addrs[0], str1, + INET6_ADDRSTRLEN); + printf("Global address: %s\n", str1); + } + + inet_ntop(AF_INET6, &net_default_dev->ip6_lladdr, str1, INET6_ADDRSTRLEN); + printf("Link-local address: %s\n", str1); + + sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); + if(sock < 0) { + perror("socket"); + ERR_EXIT(); + } + + memset(&addr, 0, sizeof(struct sockaddr_in6)); + addr.sin6_family = AF_INET6; + addr.sin6_addr = in6addr_any; + addr.sin6_port = htons(ECHO_PORT); + + if(bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6))) { + perror("bind"); + ERR_EXIT(); + } + + printf("Bound to IPv6 port %d\n", ECHO_PORT); + + for(;;) { + alen = sizeof(struct sockaddr_in6); + if((sz = recvfrom(sock, data, DATA_SIZE, 0, (struct sockaddr *)&addr, + &alen)) < 0) { + perror("recvfrom"); + ERR_EXIT(); + } + + inet_ntop(AF_INET6, &addr.sin6_addr, str1, INET6_ADDRSTRLEN); + printf("Data from %s:\n", str1); + + for(i = 0; i < sz; ++i) { + printf("%c", data[i]); + } + + printf("\n\n"); + + /* If they send the magic word, exit */ + if(!memcmp(data, "QUIT", 4)) { + break; + } + } + + close(sock); + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 03:12:26
|
Revision: 771 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=771&view=rev Author: ljsebald Date: 2012-05-24 03:12:20 +0000 (Thu, 24 May 2012) Log Message: ----------- Make it so you can receive packets on UDP over IPv6. Modified Paths: -------------- kos/kernel/net/net_ipv6.c kos/kernel/net/net_udp.c Modified: kos/kernel/net/net_ipv6.c =================================================================== --- kos/kernel/net/net_ipv6.c 2012-05-24 01:47:49 UTC (rev 770) +++ kos/kernel/net/net_ipv6.c 2012-05-24 03:12:20 UTC (rev 771) @@ -8,6 +8,7 @@ #include <string.h> #include <netinet/in.h> #include <kos/net.h> +#include <kos/fs_socket.h> #include <errno.h> #include "net_ipv6.h" @@ -170,7 +171,7 @@ int net_ipv6_input(netif_t *src, const uint8 *pkt, int pktsize) { ipv6_hdr_t *ip; uint8 next_hdr; - int pos, len; + int pos, len, rv; if(pktsize < sizeof(ipv6_hdr_t)) { /* This is obviously a bad packet, drop it */ @@ -198,10 +199,20 @@ return net_icmp6_input(src, ip, pkt + sizeof(ipv6_hdr_t), len); default: - /* We don't know what to do with this packet, so send an ICMPv6 - message indicating that. */ - return net_icmp6_send_param_prob(src, ICMP6_PARAM_PROB_UNK_HEADER, - 6, pkt, pktsize); + rv = fs_socket_input(src, AF_INET6, next_hdr, pkt, + pkt + sizeof(ipv6_hdr_t), len); + + if(rv == -2) { + /* We don't know what to do with this packet, so send an ICMPv6 + message indicating that. */ + ++ipv6_stats.pkt_recv_bad_proto; + return net_icmp6_send_param_prob(src, + ICMP6_PARAM_PROB_UNK_HEADER, 6, + pkt, pktsize); + } + + ++ipv6_stats.pkt_recv; + return rv; } return 0; Modified: kos/kernel/net/net_udp.c =================================================================== --- kos/kernel/net/net_udp.c 2012-05-24 01:47:49 UTC (rev 770) +++ kos/kernel/net/net_udp.c 2012-05-24 03:12:20 UTC (rev 771) @@ -711,6 +711,97 @@ return -1; } +static int net_udp_input6(netif_t *src, const ipv6_hdr_t *ip, const uint8 *data, + int size) { + udp_hdr_t *hdr = (udp_hdr_t *)data; + uint16 cs; + struct udp_sock *sock; + struct udp_pkt *pkt; + + if(!udp_mutex) + return -1; + + if(size <= sizeof(udp_hdr_t)) { + /* Discard the packet, since it is too short to be of any interest. */ + ++udp_stats.pkt_recv_bad_size; + return -1; + } + + if(hdr->checksum != 0) { + cs = net_ipv6_checksum_pseudo(&ip->src_addr, &ip->dst_addr, + IPPROTO_UDP, size); + + /* If the checksum is right, we'll get zero back from the checksum + function */ + if(net_ipv4_checksum(data, size, cs)) { + /* The checksum was wrong, bail out */ + ++udp_stats.pkt_recv_bad_chksum; + return -1; + } + } + + if(mutex_trylock(udp_mutex)) + /* Considering this function is usually called in an IRQ, if the + mutex is locked, there isn't much that can be done. */ + return -1; + + LIST_FOREACH(sock, &net_udp_sockets, sock_list) { + /* Don't even bother looking at IPv4 sockets */ + if(sock->domain == AF_INET) + continue; + + /* If the ports don't match, don't look any further */ + if(sock->local_addr.sin6_port != hdr->dst_port) + continue; + + /* If the socket has a remote port set and it isn't the one that this + packet came from, bail */ + if(sock->remote_addr.sin6_port != 0 && + sock->remote_addr.sin6_port != hdr->src_port) + continue; + + /* If we have a address specified and it is not the address this packet + came from, bail out */ + if(!IN6_IS_ADDR_UNSPECIFIED(&sock->remote_addr.sin6_addr) && + memcmp(&sock->remote_addr.sin6_addr, &ip->src_addr, + sizeof(struct in6_addr))) + continue; + + if(!(pkt = (struct udp_pkt *)malloc(sizeof(struct udp_pkt)))) { + mutex_unlock(udp_mutex); + return -1; + } + + memset(pkt, 0, sizeof(struct udp_pkt)); + + pkt->datasize = size - sizeof(udp_hdr_t); + if(!(pkt->data = (uint8 *)malloc(pkt->datasize))) { + free(pkt); + mutex_unlock(udp_mutex); + return -1; + } + + pkt->from.sin6_family = AF_INET6; + pkt->from.sin6_addr = ip->src_addr; + pkt->from.sin6_port = hdr->src_port; + + memcpy(pkt->data, data + sizeof(udp_hdr_t), pkt->datasize); + + TAILQ_INSERT_TAIL(&sock->packets, pkt, pkt_queue); + + ++udp_stats.pkt_recv; + genwait_wake_one(sock); + mutex_unlock(udp_mutex); + + return 0; + } + + ++udp_stats.pkt_recv_no_sock; + mutex_unlock(udp_mutex); + + return -1; +} + static int net_udp_real_input(netif_t *src, int domain, const void *hdr, const uint8 *data, int size) { if(!udp_mutex) @@ -719,6 +810,9 @@ switch(domain) { case AF_INET: return net_udp_input4(src, (const ip_hdr_t *)hdr, data, size); + + case AF_INET6: + return net_udp_input6(src, (const ipv6_hdr_t *)hdr, data, size); } return -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 01:47:56
|
Revision: 770 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=770&view=rev Author: ljsebald Date: 2012-05-24 01:47:49 +0000 (Thu, 24 May 2012) Log Message: ----------- Don't send spurrious protocol unreachable messages from IPv4... Modified Paths: -------------- kos/kernel/net/net_ipv4.c Modified: kos/kernel/net/net_ipv4.c =================================================================== --- kos/kernel/net/net_ipv4.c 2012-05-24 00:59:36 UTC (rev 769) +++ kos/kernel/net/net_ipv4.c 2012-05-24 01:47:49 UTC (rev 770) @@ -245,8 +245,10 @@ default: rv = fs_socket_input(src, AF_INET, ip->protocol, ip, data, datalen); - if(rv > -2) + if(rv > -2) { ++ipv4_stats.pkt_recv; + return rv; + } } /* There's no handler for this packet type, send an ICMP Destination This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 00:59:46
|
Revision: 769 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=769&view=rev Author: ljsebald Date: 2012-05-24 00:59:36 +0000 (Thu, 24 May 2012) Log Message: ----------- A few changes to how the internal networking stack works (some are quite major): 1. Add a input function to the fs_socket interface, which is used to input a packet into the protocol. This way, new protocols can be added without actually changing anything internally (if someone really wants to). 2. Change fs_socket_setflags() to take a uint32, and define some flags for it. If you were using this before with O_NONBLOCK, you should change that to FS_SOCKET_NONBLOCK now. 3. Change net_ipv4_input_proto() to use the new fs_socket_input() function for any protocols it doesn't handle internally. 4. Fix DHCP so that it doesn't crash if the DHCP thread is running when you shutdown. 5. Change UDP to use IPv6 for everything internally. The IPv6 code will automatically call down to the IPv4 stuff if appropriate, so this makes things a lot easier internally. 6. Make it so that you can create IPv6 UDP sockets. Note that you can't actually receive IPv6 UDP packets yet, but you should be able to send them just fine. Modified Paths: -------------- kos/include/kos/fs_socket.h kos/kernel/fs/fs_socket.c kos/kernel/net/net_dhcp.c kos/kernel/net/net_ipv4.c kos/kernel/net/net_udp.c Removed Paths: ------------- kos/kernel/net/net_udp.h Modified: kos/include/kos/fs_socket.h =================================================================== --- kos/include/kos/fs_socket.h 2012-05-24 00:50:27 UTC (rev 768) +++ kos/include/kos/fs_socket.h 2012-05-24 00:59:36 UTC (rev 769) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kos/fs_socket.h - Copyright (C) 2006, 2009, 2010 Lawrence Sebald + Copyright (C) 2006, 2009, 2010, 2012 Lawrence Sebald */ @@ -13,16 +13,11 @@ doesn't export any files there, so that point is largely irrelevant. The filesystem is designed to be extensible, making it possible to add additional socket family handlers at runtime. Currently, the kernel only - implements UDP sockets over IPv4, but as mentioned, this can be extended in - a fairly straightforward manner. In general, as a user of KallistiOS - (someone not interested in adding additional socket family drivers), there's - very little in this file that will be of interest. + implements UDP sockets over IPv4 and IPv6, but as mentioned, this can be + extended in a fairly straightforward manner. In general, as a user of + KallistiOS (someone not interested in adding additional socket family + drivers), there's very little in this file that will be of interest. - Also, note, that currently there is no way to get input into a network - protocol added with this functionality only. At some point, I will add - protocol registration with net_ipv4 for that, however, I haven't had the - time to do so just yet. - \author Lawrence Sebald */ @@ -36,8 +31,10 @@ #include <arch/types.h> #include <kos/limits.h> #include <kos/fs.h> +#include <kos/net.h> #include <sys/queue.h> #include <sys/socket.h> +#include <stdint.h> struct fs_socket_proto; @@ -154,7 +151,7 @@ \retval 0 On success \see fs_socket_setflags */ - int (*setflags)(net_socket_t *s, int flags); + int (*setflags)(net_socket_t *s, uint32_t flags); /** \brief Accept a connection on a socket created with the protocol. @@ -265,6 +262,26 @@ \retval 0 On success */ int (*shutdownsock)(net_socket_t *s, int how); + + /** \brief Input a packet into a protocol. + + This function should read in the packet specified by the arguments and + sort out what exactly to do with it. This usually involves checking if + there is an open socket with the source address and adding it to a + packet queue if there is. + + \param src The interface the packet was input on + \param domain The low-level protocol used (AF_INET or AF_INET6) + \param hdr The low-level protocol header + \param data The packet itself, including any protcol headers, + but not any from lower-level protocols + \param size The size of the packet, not including any lower- + level protocol headers + \retval -1 On error (the packet is discarded) + \retval 0 On success + */ + int (*input)(netif_t *src, int domain, const void *hdr, const uint8 *data, + int size); } fs_socket_proto_t; /** \brief Initializer for the entry field in the fs_socket_proto_t struct. */ @@ -276,26 +293,61 @@ int fs_socket_shutdown(); /* \endcond */ +/** \defgroup sock_flags Socket flags + + These are the available flags to set with the fs_socket_setflags() function. + + Every flag after FS_SOCKET_FAM_MAX is for internal-use only, and should + never be passed into any functions. + @{ +*/ +#define FS_SOCKET_NONBLOCK 0x00000001 /** \brief Non-blocking operations */ +#define FS_SOCKET_V6ONLY 0x00000002 /** \brief IPv6 Only */ + +#define FS_SOCKET_GEN_MAX 0x00008000 /** \brief Maximum generic flag */ +#define FS_SOCKET_FAM_MAX 0x00800000 /** \brief Maximum family flag */ +/** @} */ + +/** \brief Input a packet into some socket family handler. + + This function is used by the lower-level network protocol handlers to input + packets for further processing by upper-level protocols. This will call the + input function on the family handler, if one is found. + + \param src The network interface the packet came in on + \param domain The low-level protocol used (AF_INET or AF_INET6) + \param protocol The upper-level protocol that we're looking for + \param hdr The low-level protocol header + \param data The upper-level packet, without any lower-level protocol + headers, but with the upper-level ones intact + \param size The size of the packet (the data parameter) + \retval -2 The protocol is not known + \retval -1 Protocol-level error processing packet + \retval 0 On success +*/ +int fs_socket_input(netif_t *src, int domain, int protocol, const void *hdr, + const uint8 *data, int size); + /** \brief Set flags on a socket file descriptor. This function can be used to set various flags on a socket file descriptor, similar to what one would use fcntl or ioctl on a normal system for. The - flags available for use here are largely protocol dependent, and for UDP - the only flag available is O_NONBLOCK. + flags available for use here are largely protocol dependent. \param sock The socket to operate on (returned from a call to the function socket()) \param flags The flags to set on the socket. \retval -1 On error, and sets errno as appropriate \retval 0 On success + \see sock_flags \par Error Conditions: \em EWOULDBLOCK - if the function would block while inappropriate to \n \em EBADF - if passed an invalid file descriptor \n \em ENOTSOCK - if passed a file descriptor other than a socket \n - \em EINVAL - if an invalid flag was passed in + \em EINVAL - if an invalid flag (or combination) was passed in */ -int fs_socket_setflags(int sock, int flags); +int fs_socket_setflags(int sock, uint32_t flags); /** \brief Add a new protocol for use with fs_socket. Modified: kos/kernel/fs/fs_socket.c =================================================================== --- kos/kernel/fs/fs_socket.c 2012-05-24 00:50:27 UTC (rev 768) +++ kos/kernel/fs/fs_socket.c 2012-05-24 00:59:36 UTC (rev 769) @@ -1,7 +1,7 @@ /* KallistiOS ##version## fs_socket.c - Copyright (C) 2006, 2009 Lawrence Sebald + Copyright (C) 2006, 2009, 2012 Lawrence Sebald */ @@ -18,9 +18,6 @@ #include <netinet/in.h> #include <arpa/inet.h> -#include "../net/net_ipv4.h" -#include "../net/net_udp.h" - /* Define the protocol list type */ TAILQ_HEAD(proto_list, fs_socket_proto); @@ -33,7 +30,7 @@ static recursive_lock_t *list_rlock = NULL; static void fs_socket_close(void *hnd) { - net_socket_t *sock = (net_socket_t *) hnd; + net_socket_t *sock = (net_socket_t *)hnd; rlock_lock(list_rlock); LIST_REMOVE(sock, sock_list); @@ -168,10 +165,28 @@ return 0; } -int fs_socket_setflags(int sock, int flags) { +int fs_socket_input(netif_t *src, int domain, int protocol, const void *hdr, + const uint8 *data, int size) { + fs_socket_proto_t *i; + int rv = -2; + + /* Find the protocol handler and call its input function... */ + rlock_lock(proto_rlock); + TAILQ_FOREACH(i, &protocols, entry) { + if(i->protocol == protocol) { + rv = i->input(src, domain, hdr, data, size); + break; + } + } + rlock_unlock(proto_rlock); + + return rv; +} + +int fs_socket_setflags(int sock, uint32_t flags) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -217,8 +232,8 @@ net_socket_t *sock; fs_socket_proto_t *i; - /* We only support IPv4 sockets for now. */ - if(domain != PF_INET) { + /* We only support IPv4 and IPv6 sockets for now. */ + if(domain != PF_INET && domain != PF_INET6) { errno = EAFNOSUPPORT; return -1; } @@ -241,8 +256,8 @@ } /* Allocate the socket structure, if we have the space */ - sock = (net_socket_t *) malloc(sizeof(net_socket_t)); - if(!sock) { + sock = (net_socket_t *)malloc(sizeof(net_socket_t)); + if(!sock) { errno = ENOMEM; return -1; } @@ -274,7 +289,7 @@ int accept(int sock, struct sockaddr *address, socklen_t *address_len) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -292,7 +307,7 @@ int bind(int sock, const struct sockaddr *address, socklen_t address_len) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -310,7 +325,7 @@ int connect(int sock, const struct sockaddr *address, socklen_t address_len) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -328,7 +343,7 @@ int listen(int sock, int backlog) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -346,7 +361,7 @@ ssize_t recv(int sock, void *buffer, size_t length, int flags) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -365,7 +380,7 @@ struct sockaddr *address, socklen_t *address_len) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -384,7 +399,7 @@ ssize_t send(int sock, const void *message, size_t length, int flags) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -403,7 +418,7 @@ const struct sockaddr *dest_addr, socklen_t dest_len) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; @@ -422,7 +437,7 @@ int shutdown(int sock, int how) { net_socket_t *hnd; - hnd = (net_socket_t *) fs_get_handle(sock); + hnd = (net_socket_t *)fs_get_handle(sock); if(hnd == NULL) { errno = EBADF; return -1; Modified: kos/kernel/net/net_dhcp.c =================================================================== --- kos/kernel/net/net_dhcp.c 2012-05-24 00:50:27 UTC (rev 768) +++ kos/kernel/net/net_dhcp.c 2012-05-24 00:59:36 UTC (rev 769) @@ -643,7 +643,7 @@ memset(srv_addr.sin_zero, 0, sizeof(addr.sin_zero)); /* Make the socket non-blocking */ - fs_socket_setflags(dhcp_sock, O_NONBLOCK); + fs_socket_setflags(dhcp_sock, FS_SOCKET_NONBLOCK); /* Create the callback for processing DHCP packets */ dhcp_cbid = net_thd_add_callback(&net_dhcp_thd, NULL, 50); @@ -652,20 +652,27 @@ } void net_dhcp_shutdown() { - int old = irq_disable(); + int old; + /* Remove the callback first, otherwise it'll probably end up grabbing the + lock, which we don't want it to do! */ + if(dhcp_cbid != -1) { + net_thd_del_callback(dhcp_cbid); + } + + /* This song and dance is to make sure nobody else is holding the lock, + otherwise, we can't destroy it! Granted, nobody should be able to be + holding the lock if we've deleted the dhcp callback already... */ if(dhcp_lock) { + rlock_lock(dhcp_lock); + old = irq_disable(); + rlock_unlock(dhcp_lock); rlock_destroy(dhcp_lock); dhcp_lock = NULL; + irq_restore(old); } - irq_restore(old); - if(dhcp_sock != -1) { close(dhcp_sock); } - - if(dhcp_cbid != -1) { - net_thd_del_callback(dhcp_cbid); - } } Modified: kos/kernel/net/net_ipv4.c =================================================================== --- kos/kernel/net/net_ipv4.c 2012-05-24 00:50:27 UTC (rev 768) +++ kos/kernel/net/net_ipv4.c 2012-05-24 00:59:36 UTC (rev 769) @@ -2,7 +2,7 @@ kernel/net/net_ipv4.c - Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Lawrence Sebald + Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Lawrence Sebald Portions adapted from KOS' old net_icmp.c file: Copyright (c) 2002 Dan Potter @@ -15,9 +15,10 @@ #include <errno.h> #include <arpa/inet.h> #include <kos/net.h> +#include <kos/fs_socket.h> + #include "net_ipv4.h" #include "net_icmp.h" -#include "net_udp.h" static net_ipv4_stats_t ipv4_stats = { 0 }; @@ -232,16 +233,20 @@ int net_ipv4_input_proto(netif_t *src, ip_hdr_t *ip, const uint8 *data) { int hdrlen = (ip->version_ihl & 0x0F) << 2; + int datalen = ntohs(ip->length) - hdrlen; + int rv; /* Send the packet along to the appropriate protocol. */ switch(ip->protocol) { case IPPROTO_ICMP: ++ipv4_stats.pkt_recv; - return net_icmp_input(src, ip, data, ntohs(ip->length) - hdrlen); + return net_icmp_input(src, ip, data, datalen); - case IPPROTO_UDP: - ++ipv4_stats.pkt_recv; - return net_udp_input(src, ip, data, ntohs(ip->length) - hdrlen); + default: + rv = fs_socket_input(src, AF_INET, ip->protocol, ip, data, datalen); + + if(rv > -2) + ++ipv4_stats.pkt_recv; } /* There's no handler for this packet type, send an ICMP Destination Modified: kos/kernel/net/net_udp.c =================================================================== --- kos/kernel/net/net_udp.c 2012-05-24 00:50:27 UTC (rev 768) +++ kos/kernel/net/net_udp.c 2012-05-24 00:59:36 UTC (rev 769) @@ -1,7 +1,7 @@ /* KallistiOS ##version## kernel/net/net_udp.c - Copyright (C) 2005, 2006, 2007, 2008, 2009 Lawrence Sebald + Copyright (C) 2005, 2006, 2007, 2008, 2009, 2012 Lawrence Sebald */ @@ -20,7 +20,6 @@ #include "net_ipv4.h" #include "net_ipv6.h" -#include "net_udp.h" #define packed __attribute__((packed)) typedef struct { @@ -33,7 +32,7 @@ struct udp_pkt { TAILQ_ENTRY(udp_pkt) pkt_queue; - struct sockaddr_in from; + struct sockaddr_in6 from; uint8 *data; uint16 datasize; }; @@ -42,10 +41,11 @@ struct udp_sock { LIST_ENTRY(udp_sock) sock_list; - struct sockaddr_in local_addr; - struct sockaddr_in remote_addr; + struct sockaddr_in6 local_addr; + struct sockaddr_in6 remote_addr; - int flags; + uint32 flags; + int domain; struct udp_pkt_queue packets; }; @@ -56,8 +56,8 @@ static mutex_t *udp_mutex = NULL; static net_udp_stats_t udp_stats = { 0 }; -static int net_udp_send_raw(netif_t *net, uint32 src_ip, uint16 src_port, - uint32 dst_ip, uint16 dst_port, const uint8 *data, +static int net_udp_send_raw(netif_t *net, const struct sockaddr_in6 *src, + const struct sockaddr_in6 *dst, const uint8 *data, int size, int flags); static int net_udp_accept(net_socket_t *hnd, struct sockaddr *addr, @@ -69,22 +69,52 @@ static int net_udp_bind(net_socket_t *hnd, const struct sockaddr *addr, socklen_t addr_len) { struct udp_sock *udpsock, *iter; - struct sockaddr_in *realaddr; + struct sockaddr_in *realaddr4; + struct sockaddr_in6 realaddr6; /* Verify the parameters sent in first */ if(addr == NULL) { - errno = EFAULT; + errno = EDESTADDRREQ; return -1; } - if(addr->sa_family != AF_INET) { - errno = EAFNOSUPPORT; - return -1; + switch(addr->sa_family) { + case AF_INET: + if(addr_len != sizeof(struct sockaddr_in)) { + errno = EINVAL; + return -1; + } + + /* Grab the IPv4 address struct and convert it to IPv6 */ + realaddr4 = (struct sockaddr_in *)addr; + memset(&realaddr6, 0, sizeof(struct sockaddr_in6)); + realaddr6.sin6_family = AF_INET6; + realaddr6.sin6_port = realaddr4->sin_port; + + if(realaddr4->sin_addr.s_addr != INADDR_ANY) { + realaddr6.sin6_addr.__s6_addr.__s6_addr16[5] = 0xFFFF; + realaddr6.sin6_addr.__s6_addr.__s6_addr32[3] = + realaddr4->sin_addr.s_addr; + } + else { + realaddr6.sin6_addr = in6addr_any; + } + break; + + case AF_INET6: + if(addr_len != sizeof(struct sockaddr_in6)) { + errno = EINVAL; + return -1; + } + + realaddr6 = *((struct sockaddr_in6 *)addr); + break; + + default: + errno = EAFNOSUPPORT; + return -1; } - /* Get the sockaddr_in structure, rather than the sockaddr one */ - realaddr = (struct sockaddr_in *) addr; - if(irq_inside_int()) { if(mutex_trylock(udp_mutex) == -1) { errno = EWOULDBLOCK; @@ -102,20 +132,27 @@ return -1; } + /* Make sure the address family we're binding to matches that which is set + on the socket itself */ + if(addr->sa_family != udpsock->domain) { + mutex_unlock(udp_mutex); + errno = EINVAL; + return -1; + } + /* See if we requested a specific port or not */ - if(realaddr->sin_port != 0) { + if(realaddr6.sin6_port != 0) { /* Make sure we don't already have a socket bound to the port specified */ - LIST_FOREACH(iter, &net_udp_sockets, sock_list) { - if(iter->local_addr.sin_port == realaddr->sin_port) { + if(iter->local_addr.sin6_port == realaddr6.sin6_port) { mutex_unlock(udp_mutex); errno = EADDRINUSE; return -1; } } - udpsock->local_addr = *realaddr; + udpsock->local_addr = realaddr6; } else { uint16 port = 1024, tmp = 0; @@ -125,15 +162,15 @@ tmp = port; LIST_FOREACH(iter, &net_udp_sockets, sock_list) { - if(iter->local_addr.sin_port == port) { + if(iter->local_addr.sin6_port == port) { ++port; break; } } } - udpsock->local_addr = *realaddr; - udpsock->local_addr.sin_port = htons(port); + udpsock->local_addr = realaddr6; + udpsock->local_addr.sin6_port = htons(port); } mutex_unlock(udp_mutex); @@ -144,16 +181,49 @@ static int net_udp_connect(net_socket_t *hnd, const struct sockaddr *addr, socklen_t addr_len) { struct udp_sock *udpsock; - struct sockaddr_in *realaddr; + struct sockaddr_in *realaddr4; + struct sockaddr_in6 realaddr6; if(addr == NULL) { - errno = EFAULT; + errno = EDESTADDRREQ; return -1; } - if(addr->sa_family != AF_INET) { - errno = EAFNOSUPPORT; - return -1; + switch(addr->sa_family) { + case AF_INET: + if(addr_len != sizeof(struct sockaddr_in)) { + errno = EINVAL; + return -1; + } + + /* Grab the IPv4 address struct and convert it to IPv6 */ + realaddr4 = (struct sockaddr_in *)addr; + + if(realaddr4->sin_addr.s_addr == INADDR_ANY) { + errno = EADDRNOTAVAIL; + return -1; + } + + memset(&realaddr6, 0, sizeof(struct sockaddr_in6)); + realaddr6.sin6_family = AF_INET6; + realaddr6.sin6_port = realaddr4->sin_port; + realaddr6.sin6_addr.__s6_addr.__s6_addr16[5] = 0xFFFF; + realaddr6.sin6_addr.__s6_addr.__s6_addr32[3] = + realaddr4->sin_addr.s_addr; + break; + + case AF_INET6: + if(addr_len != sizeof(struct sockaddr_in6)) { + errno = EINVAL; + return -1; + } + + realaddr6 = *((struct sockaddr_in6 *)addr); + break; + + default: + errno = EAFNOSUPPORT; + return -1; } if(irq_inside_int()) { @@ -173,21 +243,31 @@ return -1; } - if(udpsock->remote_addr.sin_addr.s_addr != INADDR_ANY) { + /* Make sure the address family we're binding to matches that which is set + on the socket itself */ + if(addr->sa_family != udpsock->domain) { mutex_unlock(udp_mutex); + errno = EINVAL; + return -1; + } + + /* Make sure the socket isn't already connected */ + if(!IN6_IS_ADDR_UNSPECIFIED(&udpsock->remote_addr.sin6_addr)) { + mutex_unlock(udp_mutex); errno = EISCONN; return -1; } - realaddr = (struct sockaddr_in *) addr; - if(realaddr->sin_port == 0 || realaddr->sin_addr.s_addr == INADDR_ANY) { + /* Make sure we have a valid address to connect to */ + if(IN6_IS_ADDR_UNSPECIFIED(&realaddr6.sin6_addr) || + realaddr6.sin6_port == 0) { mutex_unlock(udp_mutex); errno = EADDRNOTAVAIL; return -1; } - udpsock->remote_addr.sin_addr.s_addr = realaddr->sin_addr.s_addr; - udpsock->remote_addr.sin_port = realaddr->sin_port; + /* "Connect" to the specified address */ + udpsock->remote_addr = realaddr6; mutex_unlock(udp_mutex); @@ -222,7 +302,7 @@ return -1; } - if(udpsock->flags & SHUT_RD) { + if(udpsock->flags & (SHUT_RD << 24)) { mutex_unlock(udp_mutex); return 0; } @@ -233,8 +313,8 @@ return -1; } - if(TAILQ_EMPTY(&udpsock->packets) && ((udpsock->flags & O_NONBLOCK) || - irq_inside_int())) { + if(TAILQ_EMPTY(&udpsock->packets) && + ((udpsock->flags & FS_SOCKET_NONBLOCK) || irq_inside_int())) { mutex_unlock(udp_mutex); errno = EWOULDBLOCK; return -1; @@ -257,19 +337,38 @@ } if(addr != NULL) { - struct sockaddr_in realaddr; + if(udpsock->domain == AF_INET) { + struct sockaddr_in realaddr; - realaddr.sin_family = AF_INET; - realaddr.sin_addr.s_addr = pkt->from.sin_addr.s_addr; - realaddr.sin_port = pkt->from.sin_port; - memset(realaddr.sin_zero, 0, 8); + memset(&realaddr, 0, sizeof(struct sockaddr_in)); + realaddr.sin_family = AF_INET; + realaddr.sin_addr.s_addr = + pkt->from.sin6_addr.__s6_addr.__s6_addr32[3]; + realaddr.sin_port = pkt->from.sin6_port; - if(*addr_len < sizeof(struct sockaddr_in)) { - memcpy(addr, &realaddr, *addr_len); + if(*addr_len < sizeof(struct sockaddr_in)) { + memcpy(addr, &realaddr, *addr_len); + } + else { + memcpy(addr, &realaddr, sizeof(struct sockaddr_in)); + *addr_len = sizeof(struct sockaddr_in); + } } - else { - memcpy(addr, &realaddr, sizeof(struct sockaddr_in)); - *addr_len = sizeof(struct sockaddr_in); + else if(udpsock->domain == AF_INET6) { + struct sockaddr_in6 realaddr6; + + memset(&realaddr6, 0, sizeof(struct sockaddr_in6)); + realaddr6.sin6_family = AF_INET6; + realaddr6.sin6_addr = pkt->from.sin6_addr; + realaddr6.sin6_port = pkt->from.sin6_port; + + if(*addr_len < sizeof(struct sockaddr_in6)) { + memcpy(addr, &realaddr6, *addr_len); + } + else { + memcpy(addr, &realaddr6, sizeof(struct sockaddr_in6)); + *addr_len = sizeof(struct sockaddr_in6); + } } } @@ -287,6 +386,9 @@ const struct sockaddr *addr, socklen_t addr_len) { struct udp_sock *udpsock; struct sockaddr_in *realaddr; + struct sockaddr_in6 realaddr6; + uint32_t sflags; + struct sockaddr_in6 local_addr; if(irq_inside_int()) { if(mutex_trylock(udp_mutex) == -1) { @@ -304,34 +406,62 @@ goto err; } - if(udpsock->flags & SHUT_WR) { + if(udpsock->flags & (SHUT_WR << 24)) { errno = EPIPE; goto err; } - if(udpsock->remote_addr.sin_addr.s_addr != INADDR_ANY && - udpsock->remote_addr.sin_port != 0) { + if(!IN6_IS_ADDR_UNSPECIFIED(&udpsock->remote_addr.sin6_addr) && + udpsock->remote_addr.sin6_port != 0) { if(addr) { errno = EISCONN; goto err; } - realaddr = &udpsock->remote_addr; + realaddr6 = udpsock->remote_addr; } else if(addr == NULL) { errno = EDESTADDRREQ; goto err; } - else { + else if(addr->sa_family != udpsock->domain) { + errno = EAFNOSUPPORT; + goto err; + } + else if(udpsock->domain == AF_INET6) { + if(addr_len != sizeof(struct sockaddr_in6)) { + errno = EINVAL; + goto err; + } + + realaddr6 = *((struct sockaddr_in6 *)addr); + } + else if(udpsock->domain == AF_INET) { + if(addr_len != sizeof(struct sockaddr_in)) { + errno = EINVAL; + goto err; + } + realaddr = (struct sockaddr_in *)addr; + memset(&realaddr6, 0, sizeof(struct sockaddr_in6)); + realaddr6.sin6_family = AF_INET6; + realaddr6.sin6_addr.__s6_addr.__s6_addr16[5] = 0xFFFF; + realaddr6.sin6_addr.__s6_addr.__s6_addr32[3] = + realaddr->sin_addr.s_addr; + realaddr6.sin6_port = realaddr->sin_port; } + else { + /* Shouldn't be able to get here... */ + errno = EBADF; + goto err; + } if(message == NULL) { errno = EFAULT; goto err; } - if(udpsock->local_addr.sin_port == 0) { + if(udpsock->local_addr.sin6_port == 0) { uint16 port = 1024, tmp = 0; struct udp_sock *iter; @@ -340,22 +470,22 @@ tmp = port; LIST_FOREACH(iter, &net_udp_sockets, sock_list) { - if(iter->local_addr.sin_port == port) { + if(iter->local_addr.sin6_port == port) { ++port; break; } } } - udpsock->local_addr.sin_port = htons(port); + udpsock->local_addr.sin6_port = htons(port); } + local_addr = udpsock->local_addr; + sflags = udpsock->flags; mutex_unlock(udp_mutex); - return net_udp_send_raw(NULL, udpsock->local_addr.sin_addr.s_addr, - udpsock->local_addr.sin_port, - realaddr->sin_addr.s_addr, realaddr->sin_port, - (uint8 *) message, length, udpsock->flags); + return net_udp_send_raw(NULL, &local_addr, &realaddr6, + (const uint8 *)message, length, sflags); err: mutex_unlock(udp_mutex); return -1; @@ -387,7 +517,7 @@ return -1; } - udpsock->flags |= how; + udpsock->flags |= (how << 24); mutex_unlock(udp_mutex); @@ -397,23 +527,15 @@ static int net_udp_socket(net_socket_t *hnd, int domain, int type, int proto) { struct udp_sock *udpsock; - udpsock = (struct udp_sock *) malloc(sizeof(struct udp_sock)); + udpsock = (struct udp_sock *)malloc(sizeof(struct udp_sock)); if(udpsock == NULL) { errno = ENOMEM; return -1; } - udpsock->remote_addr.sin_family = AF_INET; - udpsock->remote_addr.sin_addr.s_addr = INADDR_ANY; - udpsock->remote_addr.sin_port = 0; - - udpsock->local_addr.sin_family = AF_INET; - udpsock->local_addr.sin_addr.s_addr = INADDR_ANY; - udpsock->local_addr.sin_port = 0; - - udpsock->flags = 0; - + memset(udpsock, 0, sizeof(struct udp_sock)); TAILQ_INIT(&udpsock->packets); + udpsock->domain = domain; if(irq_inside_int()) { if(mutex_trylock(udp_mutex) == -1) { @@ -427,10 +549,9 @@ } LIST_INSERT_HEAD(&net_udp_sockets, udpsock, sock_list); + hnd->data = udpsock; mutex_unlock(udp_mutex); - hnd->data = udpsock; - return 0; } @@ -467,7 +588,7 @@ mutex_unlock(udp_mutex); } -static int net_udp_setflags(net_socket_t *hnd, int flags) { +static int net_udp_setflags(net_socket_t *hnd, uint32_t flags) { struct udp_sock *udpsock; if(irq_inside_int()) { @@ -487,7 +608,7 @@ return -1; } - if(flags & (~O_NONBLOCK)) { + if(flags & (~FS_SOCKET_NONBLOCK)) { mutex_unlock(udp_mutex); errno = EINVAL; return -1; @@ -499,21 +620,25 @@ return 0; } -int net_udp_input(netif_t *src, ip_hdr_t *ip, const uint8 *data, int size) { +static int net_udp_input4(netif_t *src, const ip_hdr_t *ip, const uint8 *data, + int size) { udp_hdr_t *hdr = (udp_hdr_t *)data; uint16 cs; struct udp_sock *sock; struct udp_pkt *pkt; - if(size <= sizeof(udp_hdr_t)) { + if(!udp_mutex) + return -1; + + if(size <= sizeof(udp_hdr_t)) { /* Discard the packet, since it is too short to be of any interest. */ ++udp_stats.pkt_recv_bad_size; return -1; } - cs = net_ipv4_checksum_pseudo(ip->src, ip->dest, ip->protocol, size); + if(hdr->checksum != 0) { + cs = net_ipv4_checksum_pseudo(ip->src, ip->dest, ip->protocol, size); - if(hdr->checksum != 0) { /* If the checksum is right, we'll get zero back from the checksum function */ if(net_ipv4_checksum(data, size, cs)) { @@ -523,56 +648,90 @@ } } - if(mutex_trylock(udp_mutex)) { + if(mutex_trylock(udp_mutex)) /* Considering this function is usually called in an IRQ, if the mutex is locked, there isn't much that can be done. */ return -1; - } LIST_FOREACH(sock, &net_udp_sockets, sock_list) { - /* See if we have a socket matching the description provided */ - if(sock->local_addr.sin_port == hdr->dst_port && - ((sock->remote_addr.sin_port == hdr->src_port && - sock->remote_addr.sin_addr.s_addr == ip->src) || - (sock->remote_addr.sin_port == 0 && - sock->remote_addr.sin_addr.s_addr == INADDR_ANY))) { - pkt = (struct udp_pkt *) malloc(sizeof(struct udp_pkt)); + /* Don't even bother looking at IPv6-only sockets */ + if(sock->domain == AF_INET6 && (sock->flags & FS_SOCKET_V6ONLY)) + continue; - pkt->datasize = size - sizeof(udp_hdr_t); - pkt->data = (uint8 *) malloc(pkt->datasize); + /* If the ports don't match, don't look any further */ + if(sock->local_addr.sin6_port != hdr->dst_port) + continue; - pkt->from.sin_family = AF_INET; - pkt->from.sin_addr.s_addr = ip->src; - pkt->from.sin_port = hdr->src_port; + /* If the socket has a remote port set and it isn't the one that this + packet came from, bail */ + if(sock->remote_addr.sin6_port != 0 && + sock->remote_addr.sin6_port != hdr->src_port) + continue; - memcpy(pkt->data, data + sizeof(udp_hdr_t), pkt->datasize); + /* If we have a address specified, and its not v4-mapped or its not the + address this packet came from, bail out */ + if(!IN6_IS_ADDR_UNSPECIFIED(&sock->remote_addr.sin6_addr) && + (!IN6_IS_ADDR_V4MAPPED(&sock->remote_addr.sin6_addr) || + sock->remote_addr.sin6_addr.__s6_addr.__s6_addr32[3] != ip->src)) + continue; - TAILQ_INSERT_TAIL(&sock->packets, pkt, pkt_queue); + if(!(pkt = (struct udp_pkt *)malloc(sizeof(struct udp_pkt)))) { + mutex_unlock(udp_mutex); + return -1; + } - genwait_wake_one(sock); + memset(pkt, 0, sizeof(struct udp_pkt)); + pkt->datasize = size - sizeof(udp_hdr_t); + if(!(pkt->data = (uint8 *)malloc(pkt->datasize))) { + free(pkt); mutex_unlock(udp_mutex); + return -1; + } - ++udp_stats.pkt_recv; + pkt->from.sin6_family = AF_INET6; + pkt->from.sin6_addr.__s6_addr.__s6_addr16[5] = 0xFFFF; + pkt->from.sin6_addr.__s6_addr.__s6_addr32[3] = ip->src; + pkt->from.sin6_port = hdr->src_port; - return 0; - } + memcpy(pkt->data, data + sizeof(udp_hdr_t), pkt->datasize); + + TAILQ_INSERT_TAIL(&sock->packets, pkt, pkt_queue); + + ++udp_stats.pkt_recv; + genwait_wake_one(sock); + mutex_unlock(udp_mutex); + + return 0; } + ++udp_stats.pkt_recv_no_sock; mutex_unlock(udp_mutex); - ++udp_stats.pkt_recv_no_sock; + return -1; +} +static int net_udp_real_input(netif_t *src, int domain, const void *hdr, + const uint8 *data, int size) { + if(!udp_mutex) + return -1; + + switch(domain) { + case AF_INET: + return net_udp_input4(src, (const ip_hdr_t *)hdr, data, size); + } + return -1; } -static int net_udp_send_raw(netif_t *net, uint32 src_ip, uint16 src_port, - uint32 dst_ip, uint16 dst_port, const uint8 *data, +static int net_udp_send_raw(netif_t *net, const struct sockaddr_in6 *src, + const struct sockaddr_in6 *dst, const uint8 *data, int size, int flags) { uint8 buf[size + sizeof(udp_hdr_t)]; udp_hdr_t *hdr = (udp_hdr_t *)buf; uint16 cs; int err; + struct in6_addr srcaddr = src->sin6_addr; if(!net) { net = net_default_dev; @@ -584,28 +743,51 @@ } } - if(src_ip == INADDR_ANY) { - src_ip = htonl(net_ipv4_address(net->ip_addr)); + if(IN6_IS_ADDR_UNSPECIFIED(&src->sin6_addr)) { + if(IN6_IS_ADDR_V4MAPPED(&dst->sin6_addr)) { + srcaddr.__s6_addr.__s6_addr16[5] = 0xFFFF; + srcaddr.__s6_addr.__s6_addr32[3] = + htonl(net_ipv4_address(net->ip_addr)); - if(src_ip == INADDR_ANY) { - errno = ENETDOWN; - ++udp_stats.pkt_send_failed; - return -1; + if(srcaddr.__s6_addr.__s6_addr32[3] == INADDR_ANY) { + errno = ENETDOWN; + ++udp_stats.pkt_send_failed; + return -1; + } } + else { + if(IN6_IS_ADDR_LOOPBACK(&dst->sin6_addr)) { + srcaddr = in6addr_loopback; + } + else if(IN6_IS_ADDR_LINKLOCAL(&dst->sin6_addr) || + IN6_IS_ADDR_MC_LINKLOCAL(&dst->sin6_addr)) { + srcaddr = net->ip6_lladdr; + } + else if(net->ip6_addr_count) { + /* Punt and pick the first non-link-local address */ + srcaddr = net->ip6_addrs[0]; + } + else { + errno = ENETDOWN; + ++udp_stats.pkt_send_failed; + return -1; + } + } } memcpy(buf + sizeof(udp_hdr_t), data, size); size += sizeof(udp_hdr_t); - cs = net_ipv4_checksum_pseudo(src_ip, dst_ip, IPPROTO_UDP, size); + cs = net_ipv6_checksum_pseudo(&srcaddr, &dst->sin6_addr, IPPROTO_UDP, size); - hdr->src_port = src_port; - hdr->dst_port = dst_port; - hdr->length = size; + hdr->src_port = src->sin6_port; + hdr->dst_port = dst->sin6_port; + hdr->length = htons(size); hdr->checksum = 0; hdr->checksum = net_ipv4_checksum(buf, size, cs); /* Pass everything off to the network layer to do the rest. */ - err = net_ipv4_send(net, buf, size, -1, 64, IPPROTO_UDP, src_ip, dst_ip); + err = net_ipv6_send(net, buf, size, 0, IPPROTO_UDP, &srcaddr, + &dst->sin6_addr); if(err < 0) { ++udp_stats.pkt_send_failed; return -1; @@ -623,7 +805,7 @@ /* Protocol handler for fs_socket. */ static fs_socket_proto_t proto = { FS_SOCKET_PROTO_ENTRY, - PF_INET, /* domain */ + PF_INET6, /* domain */ SOCK_DGRAM, /* type */ IPPROTO_UDP, /* protocol */ net_udp_socket, @@ -635,7 +817,8 @@ net_udp_listen, net_udp_recvfrom, net_udp_sendto, - net_udp_shutdownsock + net_udp_shutdownsock, + net_udp_real_input }; int net_udp_init() { Deleted: kos/kernel/net/net_udp.h =================================================================== --- kos/kernel/net/net_udp.h 2012-05-24 00:50:27 UTC (rev 768) +++ kos/kernel/net/net_udp.h 2012-05-24 00:59:36 UTC (rev 769) @@ -1,16 +0,0 @@ -/* KallistiOS ##version## - - kernel/net/net_udp.h - Copyright (C) 2005, 2006, 2007, 2008 Lawrence Sebald - -*/ - -#ifndef __LOCAL_NET_UDP_H -#define __LOCAL_NET_UDP_H - -#include <sys/socket.h> -#include <kos/fs_socket.h> - -int net_udp_input(netif_t *src, ip_hdr_t *ih, const uint8 *data, int size); - -#endif /* __LOCAL_NET_UDP_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ljs...@us...> - 2012-05-24 00:50:33
|
Revision: 768 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=768&view=rev Author: ljsebald Date: 2012-05-24 00:50:27 +0000 (Thu, 24 May 2012) Log Message: ----------- Use dbgio_enable() and dbgio_disable() around fs_dclsocket, rather than doing things the hacky way they were done before. Modified Paths: -------------- kos/kernel/arch/dreamcast/fs/fs_dclsocket.c kos/kernel/arch/dreamcast/kernel/init.c Modified: kos/kernel/arch/dreamcast/fs/fs_dclsocket.c =================================================================== --- kos/kernel/arch/dreamcast/fs/fs_dclsocket.c 2012-05-24 00:48:37 UTC (rev 767) +++ kos/kernel/arch/dreamcast/fs/fs_dclsocket.c 2012-05-24 00:50:27 UTC (rev 768) @@ -793,7 +793,7 @@ /* Disable the console first of all */ if(!strcmp(dbgio_dev_get(), "fs_dclsocket")) - dbgio_dev_select("null"); + dbgio_disable(); /* Send dc-tool an exit packet */ memcpy(cmd.id, "DC00", 4); Modified: kos/kernel/arch/dreamcast/kernel/init.c =================================================================== --- kos/kernel/arch/dreamcast/kernel/init.c 2012-05-24 00:48:37 UTC (rev 767) +++ kos/kernel/arch/dreamcast/kernel/init.c 2012-05-24 00:50:27 UTC (rev 768) @@ -121,7 +121,7 @@ /* Check if the dcload-ip console is up, and if so, disable it, otherwise we'll crash when we attempt to bring up the BBA */ if(!(__kos_init_flags & INIT_NO_DCLOAD) && dcload_type == DCLOAD_TYPE_IP) { - dbgio_dev_select("scif"); + dbgio_disable(); } net_init(); /* Enable networking (and drivers) */ @@ -130,6 +130,7 @@ fs_dclsocket_init_console(); if(!fs_dclsocket_init()) { dbgio_dev_select("fs_dclsocket"); + dbgio_enable(); dbglog(DBG_INFO, "fs_dclsocket console support enabled\n"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |