From 8a880b1eff3e3a0cb3acab00a7e7d1e48b5973a4 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Wed, 22 Feb 2012 13:30:17 +0000 Subject: [PATCH] Trying to fix the makefile for new stack (added missing files) git-svn-id: svn://kolibrios.org@2376 a494cfbc-eb01-0410-851d-a64ba20cac60 --- data/new-stack/docs/STACK.TXT | 203 ++++++++++++++++++++++++++++++++++ data/new-stack/doexe2.asm | 68 ++++++++++++ 2 files changed, 271 insertions(+) create mode 100644 data/new-stack/docs/STACK.TXT create mode 100644 data/new-stack/doexe2.asm diff --git a/data/new-stack/docs/STACK.TXT b/data/new-stack/docs/STACK.TXT new file mode 100644 index 0000000000..645f6ef488 --- /dev/null +++ b/data/new-stack/docs/STACK.TXT @@ -0,0 +1,203 @@ +eax = 74 - Work directly with network interface +ebx = -1 (Get number of active network devices) + + out: + eax = number of active network devices + +bh = device number, for all following functions ! + +bl = 0 (Get device type) + + out: + eax = device type number + +bl = 1 (Get device name) + + in: + ecx = pointer to 64 byte buffer + out: + name is copied into the buffer + eax = -1 on error + +bl = 2 (Reset the device) + + in + none + out + eax = -1 on error + +bl = 3 (Stop device) + + in + none + out + eax = -1 on error + +TO BE FIGURED OUT + +eax = 75 - Work with Sockets + +These functions work like the ones found in UNIX (and windows) +for more info, please read http://beej.us/guide/bgnet/ + +bl = 0 (Open Socket) + + in: + ecx = domain + edx = type + esi = protocol + out: + eax = socket number, -1 on error + +bl = 1 (Close Socket) + + in: + ecx = socket number + out: + eax = -1 on error + +bl = 2 (Bind) + + in: + ecx = socket number + edx = pointer to sockaddr structure + esi = length of sockaddr structure + out: + eax = -1 on error + +bl = 3 (Listen) + + in: + ecx = socket number + edx = backlog + out: + eax = -1 on error + +bl = 4 (connect) + + in: + ecx = socket number + edx = pointer to sockaddr structure + esi = length of sockaddr structure + out: + eax = -1 on error + +bl = 5 (accept) + + in: + ecx = socket number + edx = pointer to sockaddr structure + esi = length of sockaddr structure + out: + eax = socket number, -1 on error + +bl = 6 (send) + + in: + ecx = socket number + edx = pointer to buffer + esi = length of buffer + edi = flags + out: + eax = -1 on error + +bl = 7 (receive) + + in: + ecx = socket number + edx = pointer to buffer + esi = length of buffer + edi = flags + out: + eax = number of bytes copied, -1 on error + +bl = 8 (set socket options) + + in: + ecx = socket number + edx = level + esi = optionname + edi = ptr to buffer + +The buffer's first dword is the length of the buffer, minus the first dword offcourse + + out: + eax = -1 on error + +bl = 9 (get socket options + + in: + ecx = socket number + edx = level + esi = optionname + edi = ptr to buffer + +The buffer's first dword is the length of the buffer, minus the first dword offcourse + + out: + eax = -1 on error, socket option otherwise + +TIP + +when you import 'network.inc' and 'macros.inc' into your source code, you can use the following syntax to work with sockets: + + +for example, to open a socket + +mcall socket, AF_INET, SOCK_DGRAM,0 +mov [socketnum], eax + +then to connect to a server + +mcall connect, [socketnum], sockaddr, 18 + + +eax = 76 - Work with protocols + +high half of ebx = protocol number (for all subfunctions!) +bh = device number (for all subfunctions!) +bl = subfunction number, depends on protocol type + +For Ethernet protocol + +0 - Read # Packets send +1 - Read # Packets received +2 - Read # Bytes send +3 - Read # Bytes received +4 - Read MAC +5 - Write MAC +6 - Read IN-QUEUE size +7 - Read OUT-QUEUE size +For IPv4 protocol + +0 - Read # IP packets send +1 - Read # IP packets received +2 - Read IP +3 - Write IP +4 - Read DNS +5 - Write DNS +6 - Read subnet +7 - Write subnet +8 - Read gateway +9 - Write gateway +For ARP protocol + +0 - Read # ARP packets send +1 - Read # ARP packets received +2 - Get # ARP entry's +3 - Read ARP entry +4 - Add static ARP entry +5 - Remove ARP entry (-1 = remove all) +For ICMP protocol + +0 - Read # ICMP packets send +1 - Read # ICMP packets received +3 - enable/disable ICMP echo reply +For UDP protocol + +0 - Read # UDP packets send +1 - Read # UDP packets received +For TCP protocol + +0 - Read # TCP packets send +1 - Read # TCP packets received \ No newline at end of file diff --git a/data/new-stack/doexe2.asm b/data/new-stack/doexe2.asm new file mode 100644 index 0000000000..eaebd8aaf8 --- /dev/null +++ b/data/new-stack/doexe2.asm @@ -0,0 +1,68 @@ +filename equ '%EXENAME%' + +virtual at 0 +file filename:3Ch,4 +load pehea dword from 0 +file filename:pehea,0F8h+28h*3 +load NumberOfSections word from 4+6 +load SizeOfOptionalHeader word from 4+14h +if NumberOfSections<>3 +error Expected three sections, .text, .bss and .reloc +end if +if SizeOfOptionalHeader<>0E0h +error Nonstandard PE header +end if +load RelocsRVA dword from 4+0A0h +load RelocsSize dword from 4+0A4h +load ImageBase dword from 4+34h +load TextRVA dword from 4+0F8h+0Ch +load TextSize dword from 4+0F8h+8 +load TextOffs dword from 4+0F8h+14h +load BSSSize dword from 4+0F8h+28h+10h +load RelocRVA dword from 4+0F8h+28h*2+0Ch +load RelocOffs dword from 4+0F8h+28h*2+14h +if BSSSize +error Second section expected to be .bss +end if +if RelocRVA<>RelocsRVA +error Third section expected to be .reloc +end if +;file 'test.exe':pehea+0F8h,28h +;load physofs dword from 4+14h +;load mem dword from 4+8 +;file 'test.exe':physofs+16,4 +;load sz dword from $-4 +end virtual + +file filename:TextOffs,TextSize + +while RelocsSize>8 +virtual at 0 +file filename:RelocOffs,8 +load CurRelocPage dword from 0 +load CurRelocChunkSize dword from 4 +end virtual +RelocsSize=RelocsSize-CurRelocChunkSize +CurRelocChunkSize = CurRelocChunkSize-8 +RelocOffs=RelocOffs+8 +while CurRelocChunkSize +virtual at 0 +file filename:RelocOffs,2 +RelocOffs=RelocOffs+2 +CurRelocChunkSize=CurRelocChunkSize-2 +load s word from 0 +end virtual +CurRelocType = s shr 12 +RelocItem = CurRelocPage + (s and 0xFFF) +if CurRelocType=0 +else if CurRelocType=3 +load z dword from RelocItem-TextRVA +store dword z-(TextRVA+ImageBase) at RelocItem-TextRVA +else +error Unexpected relocation type +end if +end while +end while + +store dword TextSize at 10h +store dword RelocRVA-TextRVA at 14h