Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / netinet / udp-reqs.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: udp-reqs.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)udp-reqs.fth 1.1 04/09/07
43purpose: UDP socket interface
44copyright: Copyright 2004 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
490 value udp-last-port# \ Last UDP port number assigned
50
51: udp-next-port ( -- port# )
52 udp-last-port# 1+ dup d# 32768 d# 65535 between 0= if
53 drop d# 32768
54 then dup to udp-last-port#
55;
56
57\ Allocate/initialize protocol control blocks and link structures together.
58: udp-soattach ( sockaddr -- )
59 udp-inpcb-list inpcb-alloc ( sockaddr inpcb )
60 ucb-alloc ( sockaddr inpcb ucb )
61 2dup >ucb-inpcb ! over >in-ppcb ! ( sockaddr inpcb )
62 2dup >in-socket ! swap >so-inpcb ! ( )
63;
64
65\ Deallocate Internet PCB and UDP control blocks.
66: udp-sodetach ( sockaddr -- )
67 dup so>inpcb ( sockaddr inpcb )
68 dup inpcb>ucb ucb-free ( sockaddr inpcb )
69 inpcb-free ( sockaddr )
70 0 swap >so-inpcb ! ( )
71;
72
73\ Bind local address and port number to socket.
74: udp-sobind ( sockaddr addr addrlen -- )
75 drop insock>addr,port dup 0= if ( sockaddr addr port )
76 drop udp-next-port ( sockaddr addr lport )
77 then ( sockaddr addr lport )
78 rot so>inpcb -rot inpcb-bind ( )
79;
80
81\ Send data to specified endpoint. The unconnected socket is temporarily
82\ connected to the specified destination.
83: udp-sosendto ( sockaddr buf nbytes flags toaddr tolen -- #sent | error# )
84 drop nip ( sockaddr buf nbytes toaddr )
85 >r rot so>inpcb r> ( buf nbytes inpcb toaddr )
86 over swap insock>addr,port inpcb-connect ( buf nbytes inpcb )
87 dup 2swap udp-output ( inpcb #sent )
88 swap inpcb-disconnect ( #sent )
89;
90
91\ Copy data from the datagram to the user buffer.
92: udp-getdata ( pkt buf nbytes -- nread )
93 rot dup ip-len@ ( buf len pkt pktlen )
94 /udpip-header encapsulated-data ( buf len data datalen )
95 2swap rot min dup >r move r> ( len' )
96;
97
98\ Get source of the message.
99: udp-getpeeraddr ( pkt peeraddr addrlen -- )
100 /insock swap l! ( pkt peeraddr )
101 swap dup >ip-src swap >udp-sport ntohw@ insock-init ( )
102;
103
104\ Receive a message on the UDP socket. The entire message should be read
105\ in one single operation. If the message is longer than the size of
106\ the buffer, excess data will be discarded. If the source of the
107\ message is requested, get that information from the datagram.
108
109: udp-sorecvfrom ( sockaddr buf nbytes flags from fromlen -- nread )
110 >r >r drop ( sockaddr buf nbytes )
111 rot so>ucb ( buf nbytes ucb )
112 dup >ucb-dgramq queue-empty? if ( buf nbytes ucb )
113 udp-poll ( buf nbytes ucb )
114 then ( buf nbytes ucb )
115 >ucb-dgramq pkt-dequeue ?dup if ( buf nbytes pkt )
116 dup 2swap udp-getdata ( pkt nread )
117 over r> r> over if ( pkt nread pkt from fromlen )
118 udp-getpeeraddr ( pkt nread )
119 else ( pkt nread pkt from fromlen )
120 3drop ( pkt nread )
121 then ( pkt nread )
122 swap pkt-free ( nread )
123 else ( buf nbytes )
124 2drop r> r> 2drop 0 ( 0 ) ( r: )
125 then ( nread )
126;
127
128\ Process a UDP user request.
129: udp-prreq-execute ( ?? req# -- ?? )
130 case
131 PRREQ_RECVFROM of udp-sorecvfrom endof
132 PRREQ_SENDTO of udp-sosendto endof
133 PRREQ_ATTACH of udp-soattach endof
134 PRREQ_DETACH of udp-sodetach endof
135 PRREQ_BIND of udp-sobind endof
136 PRREQ_CONNECT of 3drop EOPNOTSUPP endof \ Not supported
137 PRREQ_SEND of 2drop 2drop EOPNOTSUPP endof \ Not supported
138 PRREQ_RECV of 2drop 2drop EOPNOTSUPP endof \ Not supported
139 PRREQ_LISTEN of 2drop EOPNOTSUPP endof \ Not applicable
140 PRREQ_ACCEPT of 3drop EOPNOTSUPP endof \ Not applicable
141 endcase
142;
143
144headers