Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / lib / libveth / veth.code
1 /******************************************************************************
2  * Copyright (c) 2013 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 /*
14  * libveth Forth wrapper
15  */
16
17 #include <veth.h>
18
19 // : libveth-open  ( mac-addr-str len reg-str len -- false | [ driver true ] )
20 PRIM(LIBVETH_X2d_OPEN)
21 {
22         int reg_len = TOS.u; POP;
23         char *reg = TOS.a; POP;
24         int len = TOS.u; POP;
25         char *mac_addr = TOS.a;
26
27         net_driver_t *net_driver = libveth_open(mac_addr, len, reg, reg_len);
28         if (net_driver) {
29                 TOS.u = (unsigned long)net_driver; PUSH;
30                 TOS.n = -1;
31         } else
32                 TOS.n = 0;
33 }
34 MIRP
35
36 // : libveth-close  ( driver -- )
37 PRIM(LIBVETH_X2d_CLOSE)
38 {
39         net_driver_t *driver = TOS.a; POP;
40         libveth_close(driver);
41 }
42 MIRP
43
44
45 // : libveth-read  ( addr len driver -- actual )
46 PRIM(LIBVETH_X2d_READ)
47 {
48         net_driver_t *driver = TOS.a; POP;
49         int len = TOS.u; POP;
50         TOS.n = libveth_read(TOS.a, len, driver);
51 }
52 MIRP
53
54 // : libveth-write  ( addr len driver -- actual )
55 PRIM(LIBVETH_X2d_WRITE)
56 {
57         net_driver_t *driver = TOS.a; POP;
58         int len = TOS.u; POP;
59         TOS.n = libveth_write(TOS.a, len, driver);
60 }
61 MIRP