summaryrefslogtreecommitdiff
path: root/toolchain/musl/patches/1.1.14/musl.xtensa
blob: dbb25ebc6e3fc342ed48c1041f4e0cdadb418b45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
From be7942d8dbce223ed6a75dfdf8d2cd1beb04e2eb Mon Sep 17 00:00:00 2001
From: Max Filippov <jcmvbkbc@gmail.com>
Date: Tue, 22 Mar 2016 02:35:58 +0300
Subject: [PATCH 242/242] xtensa: add port

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
---
 arch/xtensa/atomic_arch.h             |  30 ++
 arch/xtensa/bits/alltypes.h.in        |  30 ++
 arch/xtensa/bits/endian.h             |   7 +
 arch/xtensa/bits/float.h              |  16 +
 arch/xtensa/bits/ioctl.h              | 227 ++++++++++++
 arch/xtensa/bits/limits.h             |   7 +
 arch/xtensa/bits/mman.h               |  57 +++
 arch/xtensa/bits/posix.h              |   2 +
 arch/xtensa/bits/reg.h                |   2 +
 arch/xtensa/bits/setjmp.h             |   1 +
 arch/xtensa/bits/signal.h             |  88 +++++
 arch/xtensa/bits/stat.h               |  21 ++
 arch/xtensa/bits/stdint.h             |  20 +
 arch/xtensa/bits/syscall.h            | 679 ++++++++++++++++++++++++++++++++++
 arch/xtensa/bits/termios.h            | 168 +++++++++
 arch/xtensa/bits/user.h               |   4 +
 arch/xtensa/bits/xtensa-config.h      |  46 +++
 arch/xtensa/crt_arch.h                |  26 ++
 arch/xtensa/pthread_arch.h            |  11 +
 arch/xtensa/reloc.h                   |  21 ++
 arch/xtensa/syscall_arch.h            | 102 +++++
 configure                             |   1 +
 crt/xtensa/crti.s                     |  11 +
 crt/xtensa/crtn.s                     |   5 +
 include/elf.h                         |  58 +++
 ldso/dlstart.c                        |  13 +-
 ldso/dynlink.c                        |  41 +-
 src/internal/xtensa/syscall.s         |  15 +
 src/ldso/xtensa/tlsdesc.s             |  22 ++
 src/setjmp/xtensa/longjmp.s           |  73 ++++
 src/setjmp/xtensa/setjmp.s            |  13 +
 src/signal/xtensa/restore.s           |  10 +
 src/signal/xtensa/sigsetjmp.s         |  69 ++++
 src/signal/xtensa/windowspill.s       |  78 ++++
 src/thread/xtensa/__set_thread_area.s |   8 +
 src/thread/xtensa/__unmapself.s       |  10 +
 src/thread/xtensa/clone.s             |  39 ++
 src/thread/xtensa/syscall_cp.s        |  37 ++
 38 files changed, 2066 insertions(+), 2 deletions(-)
 create mode 100644 arch/xtensa/atomic_arch.h
 create mode 100644 arch/xtensa/bits/alltypes.h.in
 create mode 100644 arch/xtensa/bits/endian.h
 create mode 100644 arch/xtensa/bits/float.h
 create mode 100644 arch/xtensa/bits/ioctl.h
 create mode 100644 arch/xtensa/bits/limits.h
 create mode 100644 arch/xtensa/bits/mman.h
 create mode 100644 arch/xtensa/bits/posix.h
 create mode 100644 arch/xtensa/bits/reg.h
 create mode 100644 arch/xtensa/bits/setjmp.h
 create mode 100644 arch/xtensa/bits/signal.h
 create mode 100644 arch/xtensa/bits/stat.h
 create mode 100644 arch/xtensa/bits/stdint.h
 create mode 100644 arch/xtensa/bits/syscall.h
 create mode 100644 arch/xtensa/bits/termios.h
 create mode 100644 arch/xtensa/bits/user.h
 create mode 100644 arch/xtensa/bits/xtensa-config.h
 create mode 100644 arch/xtensa/crt_arch.h
 create mode 100644 arch/xtensa/pthread_arch.h
 create mode 100644 arch/xtensa/reloc.h
 create mode 100644 arch/xtensa/syscall_arch.h
 create mode 100644 crt/xtensa/crti.s
 create mode 100644 crt/xtensa/crtn.s
 create mode 100644 src/internal/xtensa/syscall.s
 create mode 100644 src/ldso/xtensa/tlsdesc.s
 create mode 100644 src/setjmp/xtensa/longjmp.s
 create mode 100644 src/setjmp/xtensa/setjmp.s
 create mode 100644 src/signal/xtensa/restore.s
 create mode 100644 src/signal/xtensa/sigsetjmp.s
 create mode 100644 src/signal/xtensa/windowspill.s
 create mode 100644 src/thread/xtensa/__set_thread_area.s
 create mode 100644 src/thread/xtensa/__unmapself.s
 create mode 100644 src/thread/xtensa/clone.s
 create mode 100644 src/thread/xtensa/syscall_cp.s

diff --git a/arch/xtensa/atomic_arch.h b/arch/xtensa/atomic_arch.h
new file mode 100644
index 0000000..476814b
--- /dev/null
+++ b/arch/xtensa/atomic_arch.h
@@ -0,0 +1,30 @@
+#ifndef _INTERNAL_ATOMIC_H
+#define _INTERNAL_ATOMIC_H
+
+#include <stdint.h>
+
+#define a_cas a_cas
+static inline int a_cas(volatile int *p, int t, int s)
+{
+	__asm__ __volatile__(
+		"	wsr	%1, scompare1\n"
+		"	s32c1i	%0, %2, 0\n"
+		: "+a"(s)
+		: "a"(t), "a"(p)
+		: "memory" );
+        return s;
+}
+
+#define a_barrier a_barrier
+static inline void a_barrier()
+{
+	__asm__ __volatile__ ("memw" : : : "memory");
+}
+
+#define a_crash a_crash
+static inline void a_crash()
+{
+	__asm__ __volatile__ ("ill" : : : "memory");
+}
+
+#endif
diff --git a/arch/xtensa/bits/alltypes.h.in b/arch/xtensa/bits/alltypes.h.in
new file mode 100644
index 0000000..1e2a8c1
--- /dev/null
+++ b/arch/xtensa/bits/alltypes.h.in
@@ -0,0 +1,30 @@
+#define _Addr int
+#define _Int64 long long
+#define _Reg int
+
+TYPEDEF __builtin_va_list va_list;
+TYPEDEF __builtin_va_list __isoc_va_list;
+
+#ifndef __cplusplus
+#ifdef __WCHAR_TYPE__
+TYPEDEF __WCHAR_TYPE__ wchar_t;
+#else
+TYPEDEF unsigned wchar_t;
+#endif
+#endif
+
+TYPEDEF float float_t;
+TYPEDEF double double_t;
+
+TYPEDEF struct { long long __ll; long double __ld; } max_align_t;
+
+TYPEDEF long time_t;
+TYPEDEF long suseconds_t;
+
+TYPEDEF struct { union { int __i[9]; volatile int __vi[9]; unsigned __s[9]; } __u; } pthread_attr_t;
+TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t;
+TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t;
+TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } pthread_cond_t;
+TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } cnd_t;
+TYPEDEF struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t;
+TYPEDEF struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t;
diff --git a/arch/xtensa/bits/endian.h b/arch/xtensa/bits/endian.h
new file mode 100644
index 0000000..d719907
--- /dev/null
+++ b/arch/xtensa/bits/endian.h
@@ -0,0 +1,7 @@
+#if __XTENSA_EB__
+#define __BYTE_ORDER __BIG_ENDIAN
+#elif __XTENSA_EL__
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#else
+#error Unknown endianness
+#endif
diff --git a/arch/xtensa/bits/float.h b/arch/xtensa/bits/float.h
new file mode 100644
index 0000000..c4a655e
--- /dev/null
+++ b/arch/xtensa/bits/float.h
@@ -0,0 +1,16 @@
+#define FLT_EVAL_METHOD 0
+
+#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
+#define LDBL_MIN 2.22507385850720138309e-308L
+#define LDBL_MAX 1.79769313486231570815e+308L
+#define LDBL_EPSILON 2.22044604925031308085e-16L
+
+#define LDBL_MANT_DIG 53
+#define LDBL_MIN_EXP (-1021)
+#define LDBL_MAX_EXP 1024
+
+#define LDBL_DIG 15
+#define LDBL_MIN_10_EXP (-307)
+#define LDBL_MAX_10_EXP 308
+
+#define DECIMAL_DIG 17
diff --git a/arch/xtensa/bits/ioctl.h b/arch/xtensa/bits/ioctl.h
new file mode 100644
index 0000000..e1ab80e
--- /dev/null
+++ b/arch/xtensa/bits/ioctl.h
@@ -0,0 +1,227 @@
+#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
+#define _IOC_NONE  0U
+#define _IOC_READ  2U
+#define _IOC_WRITE 1U
+
+#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
+#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
+#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
+#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
+
+#define FIOCLEX		_IO('f', 1)
+#define FIONCLEX	_IO('f', 2)
+#define FIOASYNC	_IOW('f', 125, int)
+#define FIONBIO		_IOW('f', 126, int)
+#define FIONREAD	_IOR('f', 127, int)
+#define TIOCINQ		FIONREAD
+#define FIOQSIZE	_IOR('f', 128, loff_t)
+
+#define TCGETS		0x5401
+#define TCSETS		0x5402
+#define TCSETSW		0x5403
+#define TCSETSF		0x5404
+
+#define TCGETA		0x80127417	/* _IOR('t', 23, struct termio) */
+#define TCSETA		0x40127418	/* _IOW('t', 24, struct termio) */
+#define TCSETAW		0x40127419	/* _IOW('t', 25, struct termio) */
+#define TCSETAF		0x4012741C	/* _IOW('t', 28, struct termio) */
+
+#define TCSBRK		_IO('t', 29)
+#define TCXONC		_IO('t', 30)
+#define TCFLSH		_IO('t', 31)
+
+#define TIOCSWINSZ	0x40087467	/* _IOW('t', 103, struct winsize) */
+#define TIOCGWINSZ	0x80087468	/* _IOR('t', 104, struct winsize) */
+#define	TIOCSTART	_IO('t', 110)		/* start output, like ^Q */
+#define	TIOCSTOP	_IO('t', 111)		/* stop output, like ^S */
+#define TIOCOUTQ        _IOR('t', 115, int)     /* output queue size */
+
+#define TIOCSPGRP	_IOW('t', 118, int)
+#define TIOCGPGRP	_IOR('t', 119, int)
+
+#define TIOCEXCL	_IO('T', 12)
+#define TIOCNXCL	_IO('T', 13)
+#define TIOCSCTTY	_IO('T', 14)
+
+#define TIOCSTI		_IOW('T', 18, char)
+#define TIOCMGET	_IOR('T', 21, unsigned int)
+#define TIOCMBIS	_IOW('T', 22, unsigned int)
+#define TIOCMBIC	_IOW('T', 23, unsigned int)
+#define TIOCMSET	_IOW('T', 24, unsigned int)
+# define TIOCM_LE	0x001
+# define TIOCM_DTR	0x002
+# define TIOCM_RTS	0x004
+# define TIOCM_ST	0x008
+# define TIOCM_SR	0x010
+# define TIOCM_CTS	0x020
+# define TIOCM_CAR	0x040
+# define TIOCM_RNG	0x080
+# define TIOCM_DSR	0x100
+# define TIOCM_CD	TIOCM_CAR
+# define TIOCM_RI	TIOCM_RNG
+
+#define TIOCGSOFTCAR	_IOR('T', 25, unsigned int)
+#define TIOCSSOFTCAR	_IOW('T', 26, unsigned int)
+#define TIOCLINUX	_IOW('T', 28, char)
+#define TIOCCONS	_IO('T', 29)
+#define TIOCGSERIAL	0x803C541E	/*_IOR('T', 30, struct serial_struct)*/
+#define TIOCSSERIAL	0x403C541F	/*_IOW('T', 31, struct serial_struct)*/
+#define TIOCPKT		_IOW('T', 32, int)
+# define TIOCPKT_DATA		 0
+# define TIOCPKT_FLUSHREAD	 1
+# define TIOCPKT_FLUSHWRITE	 2
+# define TIOCPKT_STOP		 4
+# define TIOCPKT_START		 8
+# define TIOCPKT_NOSTOP		16
+# define TIOCPKT_DOSTOP		32
+# define TIOCPKT_IOCTL		64
+
+
+#define TIOCNOTTY	_IO('T', 34)
+#define TIOCSETD	_IOW('T', 35, int)
+#define TIOCGETD	_IOR('T', 36, int)
+#define TCSBRKP		_IOW('T', 37, int)   /* Needed for POSIX tcsendbreak()*/
+#define TIOCSBRK	_IO('T', 39) 	     /* BSD compatibility */
+#define TIOCCBRK	_IO('T', 40)	     /* BSD compatibility */
+#define TIOCGSID	_IOR('T', 41, pid_t) /* Return the session ID of FD*/
+#define TCGETS2		_IOR('T', 42, struct termios2)
+#define TCSETS2		_IOW('T', 43, struct termios2)
+#define TCSETSW2	_IOW('T', 44, struct termios2)
+#define TCSETSF2	_IOW('T', 45, struct termios2)
+#define TIOCGRS485	_IOR('T', 46, struct serial_rs485)
+#define TIOCSRS485	_IOWR('T', 47, struct serial_rs485)
+#define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
+#define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
+#define TIOCSIG		_IOW('T',0x36, int)  /* Generate signal on Pty slave */
+#define TIOCVHANGUP	_IO('T', 0x37)
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
+
+#define TIOCSERCONFIG	_IO('T', 83)
+#define TIOCSERGWILD	_IOR('T', 84,  int)
+#define TIOCSERSWILD	_IOW('T', 85,  int)
+#define TIOCGLCKTRMIOS	0x5456
+#define TIOCSLCKTRMIOS	0x5457
+#define TIOCSERGSTRUCT	0x5458		     /* For debugging only */
+#define TIOCSERGETLSR   _IOR('T', 89, unsigned int) /* Get line status reg. */
+  /* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+# define TIOCSER_TEMT    0x01		     /* Transmitter physically empty */
+#define TIOCSERGETMULTI 0x80a8545a /* Get multiport config  */
+			/* _IOR('T', 90, struct serial_multiport_struct) */
+#define TIOCSERSETMULTI 0x40a8545b /* Set multiport config */
+			/* _IOW('T', 91, struct serial_multiport_struct) */
+
+#define TIOCMIWAIT	_IO('T', 92) /* wait for a change on serial input line(s) */
+#define TIOCGICOUNT	0x545D	/* read serial port inline interrupt counts */
+
+struct winsize {
+	unsigned short ws_row;
+	unsigned short ws_col;
+	unsigned short ws_xpixel;
+	unsigned short ws_ypixel;
+};
+
+#define TIOCM_LE        0x001
+#define TIOCM_DTR       0x002
+#define TIOCM_RTS       0x004
+#define TIOCM_ST        0x008
+#define TIOCM_SR        0x010
+#define TIOCM_CTS       0x020
+#define TIOCM_CAR       0x040
+#define TIOCM_RNG       0x080
+#define TIOCM_DSR       0x100
+#define TIOCM_CD        TIOCM_CAR
+#define TIOCM_RI        TIOCM_RNG
+#define TIOCM_OUT1      0x2000
+#define TIOCM_OUT2      0x4000
+#define TIOCM_LOOP      0x8000
+#define TIOCM_MODEM_BITS TIOCM_OUT2
+
+#define N_TTY           0
+#define N_SLIP          1
+#define N_MOUSE         2
+#define N_PPP           3
+#define N_STRIP         4
+#define N_AX25          5
+#define N_X25           6
+#define N_6PACK         7
+#define N_MASC          8
+#define N_R3964         9
+#define N_PROFIBUS_FDL  10
+#define N_IRDA          11
+#define N_SMSBLOCK      12
+#define N_HDLC          13
+#define N_SYNC_PPP      14
+#define N_HCI           15
+
+#define FIOGETOWN	_IOR('f', 123, int)
+#define FIOSETOWN 	_IOW('f', 124, int)
+#define SIOCATMARK	_IOR('s', 7, int)
+#define SIOCSPGRP	_IOW('s', 8, pid_t)
+#define SIOCGPGRP	_IOR('s', 9, pid_t)
+#define SIOCGSTAMP	0x8906		/* Get stamp (timeval) */
+#define SIOCGSTAMPNS	0x8907		/* Get stamp (timespec) */
+
+#define SIOCADDRT       0x890B
+#define SIOCDELRT       0x890C
+#define SIOCRTMSG       0x890D
+
+#define SIOCGIFNAME     0x8910
+#define SIOCSIFLINK     0x8911
+#define SIOCGIFCONF     0x8912
+#define SIOCGIFFLAGS    0x8913
+#define SIOCSIFFLAGS    0x8914
+#define SIOCGIFADDR     0x8915
+#define SIOCSIFADDR     0x8916
+#define SIOCGIFDSTADDR  0x8917
+#define SIOCSIFDSTADDR  0x8918
+#define SIOCGIFBRDADDR  0x8919
+#define SIOCSIFBRDADDR  0x891a
+#define SIOCGIFNETMASK  0x891b
+#define SIOCSIFNETMASK  0x891c
+#define SIOCGIFMETRIC   0x891d
+#define SIOCSIFMETRIC   0x891e
+#define SIOCGIFMEM      0x891f
+#define SIOCSIFMEM      0x8920
+#define SIOCGIFMTU      0x8921
+#define SIOCSIFMTU      0x8922
+#define SIOCSIFHWADDR   0x8924
+#define SIOCGIFENCAP    0x8925
+#define SIOCSIFENCAP    0x8926
+#define SIOCGIFHWADDR   0x8927
+#define SIOCGIFSLAVE    0x8929
+#define SIOCSIFSLAVE    0x8930
+#define SIOCADDMULTI    0x8931
+#define SIOCDELMULTI    0x8932
+#define SIOCGIFINDEX    0x8933
+#define SIOGIFINDEX     SIOCGIFINDEX
+#define SIOCSIFPFLAGS   0x8934
+#define SIOCGIFPFLAGS   0x8935
+#define SIOCDIFADDR     0x8936
+#define SIOCSIFHWBROADCAST 0x8937
+#define SIOCGIFCOUNT    0x8938
+
+#define SIOCGIFBR       0x8940
+#define SIOCSIFBR       0x8941
+
+#define SIOCGIFTXQLEN   0x8942
+#define SIOCSIFTXQLEN   0x8943
+
+#define SIOCDARP        0x8953
+#define SIOCGARP        0x8954
+#define SIOCSARP        0x8955
+
+#define SIOCDRARP       0x8960
+#define SIOCGRARP       0x8961
+#define SIOCSRARP       0x8962
+
+#define SIOCGIFMAP      0x8970
+#define SIOCSIFMAP      0x8971
+
+#define SIOCADDDLCI     0x8980
+#define SIOCDELDLCI     0x8981
+
+#define SIOCDEVPRIVATE		0x89F0
+#define SIOCPROTOPRIVATE	0x89E0
diff --git a/arch/xtensa/bits/limits.h b/arch/xtensa/bits/limits.h
new file mode 100644
index 0000000..fbc6d23
--- /dev/null
+++ b/arch/xtensa/bits/limits.h
@@ -0,0 +1,7 @@
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define LONG_BIT 32
+#endif
+
+#define LONG_MAX  0x7fffffffL
+#define LLONG_MAX  0x7fffffffffffffffLL
diff --git a/arch/xtensa/bits/mman.h b/arch/xtensa/bits/mman.h
new file mode 100644
index 0000000..3125fc2
--- /dev/null
+++ b/arch/xtensa/bits/mman.h
@@ -0,0 +1,57 @@
+#define MAP_FAILED ((void *) -1)
+
+#define	PROT_NONE      0
+#define	PROT_READ      1
+#define	PROT_WRITE     2
+#define	PROT_EXEC      4
+#define	PROT_GROWSDOWN 0x01000000
+#define	PROT_GROWSUP   0x02000000
+
+#define	MAP_SHARED     0x01
+#define	MAP_PRIVATE    0x02
+#define	MAP_FIXED      0x10
+
+#define MAP_TYPE       0x0f
+#define MAP_FILE       0x00
+#define MAP_ANON       0x800
+#define MAP_ANONYMOUS  MAP_ANON
+#define MAP_NORESERVE  0x0400
+#define MAP_GROWSDOWN  0x1000
+#define MAP_DENYWRITE  0x2000
+#define MAP_EXECUTABLE 0x4000
+#define MAP_LOCKED     0x8000
+#define MAP_POPULATE   0x10000
+#define MAP_NONBLOCK   0x20000
+#define MAP_STACK      0x40000
+#define MAP_HUGETLB    0x80000
+
+#define POSIX_MADV_NORMAL       0
+#define POSIX_MADV_RANDOM       1
+#define POSIX_MADV_SEQUENTIAL   2
+#define POSIX_MADV_WILLNEED     3
+#define POSIX_MADV_DONTNEED     0
+
+#define MS_ASYNC        1
+#define MS_INVALIDATE   2
+#define MS_SYNC         4
+
+#define MCL_CURRENT     1
+#define MCL_FUTURE      2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define MADV_NORMAL      0
+#define MADV_RANDOM      1
+#define MADV_SEQUENTIAL  2
+#define MADV_WILLNEED    3
+#define MADV_DONTNEED    4
+#define MADV_REMOVE      9
+#define MADV_DONTFORK    10
+#define MADV_DOFORK      11
+#define MADV_MERGEABLE   12
+#define MADV_UNMERGEABLE 13
+#define MADV_HUGEPAGE    14
+#define MADV_NOHUGEPAGE  15
+#define MADV_DONTDUMP    16
+#define MADV_DODUMP      17
+#define MADV_HWPOISON    100
+#endif
diff --git a/arch/xtensa/bits/posix.h b/arch/xtensa/bits/posix.h
new file mode 100644
index 0000000..30a3871
--- /dev/null
+++ b/arch/xtensa/bits/posix.h
@@ -0,0 +1,2 @@
+#define _POSIX_V6_ILP32_OFFBIG  1
+#define _POSIX_V7_ILP32_OFFBIG  1
diff --git a/arch/xtensa/bits/reg.h b/arch/xtensa/bits/reg.h
new file mode 100644
index 0000000..0192a29
--- /dev/null
+++ b/arch/xtensa/bits/reg.h
@@ -0,0 +1,2 @@
+#undef __WORDSIZE
+#define __WORDSIZE 32
diff --git a/arch/xtensa/bits/setjmp.h b/arch/xtensa/bits/setjmp.h
new file mode 100644
index 0000000..b2bd974
--- /dev/null
+++ b/arch/xtensa/bits/setjmp.h
@@ -0,0 +1 @@
+typedef unsigned long __jmp_buf[18];
diff --git a/arch/xtensa/bits/signal.h b/arch/xtensa/bits/signal.h
new file mode 100644
index 0000000..545ffd3
--- /dev/null
+++ b/arch/xtensa/bits/signal.h
@@ -0,0 +1,88 @@
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define MINSIGSTKSZ 2048
+#define SIGSTKSZ 8192
+#endif
+
+typedef struct sigcontext
+{
+	unsigned long sc_pc;
+	unsigned long sc_ps;
+	unsigned long sc_lbeg;
+	unsigned long sc_lend;
+	unsigned long sc_lcount;
+	unsigned long sc_sar;
+	unsigned long sc_acclo;
+	unsigned long sc_acchi;
+	unsigned long sc_a[16];
+	void *sc_xtregs;
+} mcontext_t;
+
+struct sigaltstack {
+	void *ss_sp;
+	int ss_flags;
+	size_t ss_size;
+};
+
+typedef struct __ucontext {
+	unsigned long uc_flags;
+	struct __ucontext *uc_link;
+	stack_t uc_stack;
+	mcontext_t uc_mcontext;
+	sigset_t uc_sigmask;
+} ucontext_t;
+
+#define SA_NOCLDSTOP	0x00000001
+#define SA_NOCLDWAIT	0x00000002 /* not supported yet */
+#define SA_SIGINFO	0x00000004
+#define SA_ONSTACK	0x08000000
+#define SA_RESTART	0x10000000
+#define SA_NODEFER	0x40000000
+#define SA_RESETHAND	0x80000000
+
+#define SA_NOMASK	SA_NODEFER
+#define SA_ONESHOT	SA_RESETHAND
+
+#define SA_RESTORER	0x04000000
+
+#endif
+
+#define SIGHUP		 1
+#define SIGINT		 2
+#define SIGQUIT		 3
+#define SIGILL		 4
+#define SIGTRAP		 5
+#define SIGABRT		 6
+#define SIGIOT		 6
+#define SIGBUS		 7
+#define SIGFPE		 8
+#define SIGKILL		 9
+#define SIGUSR1		10
+#define SIGSEGV		11
+#define SIGUSR2		12
+#define SIGPIPE		13
+#define SIGALRM		14
+#define SIGTERM		15
+#define SIGSTKFLT	16
+#define SIGCHLD		17
+#define SIGCONT		18
+#define SIGSTOP		19
+#define SIGTSTP		20
+#define SIGTTIN		21
+#define SIGTTOU		22
+#define SIGURG		23
+#define SIGXCPU		24
+#define SIGXFSZ		25
+#define SIGVTALRM	26
+#define SIGPROF		27
+#define SIGWINCH	28
+#define SIGIO		29
+#define SIGPOLL		SIGIO
+/* #define SIGLOST		29 */
+#define SIGPWR		30
+#define SIGSYS		31
+#define	SIGUNUSED	31
+
+#define _NSIG 64
diff --git a/arch/xtensa/bits/stat.h b/arch/xtensa/bits/stat.h
new file mode 100644
index 0000000..24231f8
--- /dev/null
+++ b/arch/xtensa/bits/stat.h
@@ -0,0 +1,21 @@
+/* copied from kernel definition, but with padding replaced
+ * by the corresponding correctly-sized userspace types. */
+
+struct stat
+{
+	dev_t st_dev;
+	ino_t st_ino;
+	mode_t st_mode;
+	nlink_t st_nlink;
+	uid_t st_uid;
+	gid_t st_gid;
+	dev_t st_rdev;
+	off_t st_size;
+	blksize_t st_blksize;
+	long __st_padding1;
+	blkcnt_t st_blocks;
+	struct timespec st_atim;
+	struct timespec st_mtim;
+	struct timespec st_ctim;
+        long __st_padding2[2];
+};
diff --git a/arch/xtensa/bits/stdint.h b/arch/xtensa/bits/stdint.h
new file mode 100644
index 0000000..d1b2712
--- /dev/null
+++ b/arch/xtensa/bits/stdint.h
@@ -0,0 +1,20 @@
+typedef int32_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef uint32_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+
+#define INT_FAST16_MIN  INT32_MIN
+#define INT_FAST32_MIN  INT32_MIN
+
+#define INT_FAST16_MAX  INT32_MAX
+#define INT_FAST32_MAX  INT32_MAX
+
+#define UINT_FAST16_MAX UINT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INTPTR_MIN      INT32_MIN
+#define INTPTR_MAX      INT32_MAX
+#define UINTPTR_MAX     UINT32_MAX
+#define PTRDIFF_MIN     INT32_MIN
+#define PTRDIFF_MAX     INT32_MAX
+#define SIZE_MAX        UINT32_MAX
diff --git a/arch/xtensa/bits/syscall.h b/arch/xtensa/bits/syscall.h
new file mode 100644
index 0000000..df8c2ab
--- /dev/null
+++ b/arch/xtensa/bits/syscall.h
@@ -0,0 +1,679 @@
+#define __NR_spill				  0
+#define __NR_xtensa				  1
+#define __NR_available4				  2
+#define __NR_available5				  3
+#define __NR_available6				  4
+#define __NR_available7				  5
+#define __NR_available8				  6
+#define __NR_available9				  7
+#define __NR_open				  8
+#define __NR_close				  9
+#define __NR_dup				 10
+#define __NR_dup2				 11
+#define __NR_read				 12
+#define __NR_write				 13
+#define __NR_select				 14
+#define __NR_lseek				 15
+#define __NR_poll				 16
+#define __NR__llseek				 17
+#define __NR_epoll_wait				 18
+#define __NR_epoll_ctl				 19
+#define __NR_epoll_create			 20
+#define __NR_creat				 21
+#define __NR_truncate				 22
+#define __NR_ftruncate				 23
+#define __NR_readv				 24
+#define __NR_writev				 25
+#define __NR_fsync				 26
+#define __NR_fdatasync				 27
+#define __NR_truncate64				 28
+#define __NR_ftruncate64			 29
+#define __NR_pread64				 30
+#define __NR_pwrite64				 31
+#define __NR_link				 32
+#define __NR_rename				 33
+#define __NR_symlink				 34
+#define __NR_readlink				 35
+#define __NR_mknod				 36
+#define __NR_pipe				 37
+#define __NR_unlink				 38
+#define __NR_rmdir				 39
+#define __NR_mkdir				 40
+#define __NR_chdir				 41
+#define __NR_fchdir				 42
+#define __NR_getcwd				 43
+#define __NR_chmod				 44
+#define __NR_chown				 45
+#define __NR_stat				 46
+#define __NR_stat64				 47
+#define __NR_lchown				 48
+#define __NR_lstat				 49
+#define __NR_lstat64				 50
+#define __NR_available51			 51
+#define __NR_fchmod				 52
+#define __NR_fchown				 53
+#define __NR_fstat				 54
+#define __NR_fstat64				 55
+#define __NR_flock				 56
+#define __NR_access				 57
+#define __NR_umask				 58
+#define __NR_getdents				 59
+#define __NR_getdents64				 60
+#define __NR_fcntl64				 61
+#define __NR_fallocate				 62
+#define __NR_fadvise64_64			 63
+#define __NR_utime				 64	/* glibc 2.3.3 ?? */
+#define __NR_utimes				 65
+#define __NR_ioctl				 66
+#define __NR_fcntl				 67
+#define __NR_setxattr				 68
+#define __NR_getxattr				 69
+#define __NR_listxattr				 70
+#define __NR_removexattr			 71
+#define __NR_lsetxattr				 72
+#define __NR_lgetxattr				 73
+#define __NR_llistxattr				 74
+#define __NR_lremovexattr			 75
+#define __NR_fsetxattr				 76
+#define __NR_fgetxattr				 77
+#define __NR_flistxattr				 78
+#define __NR_fremovexattr			 79
+#define __NR_mmap2				 80
+#define __NR_munmap				 81
+#define __NR_mprotect				 82
+#define __NR_brk				 83
+#define __NR_mlock				 84
+#define __NR_munlock				 85
+#define __NR_mlockall				 86
+#define __NR_munlockall				 87
+#define __NR_mremap				 88
+#define __NR_msync				 89
+#define __NR_mincore				 90
+#define __NR_madvise				 91
+#define __NR_shmget				 92
+#define __NR_shmat				 93
+#define __NR_shmctl				 94
+#define __NR_shmdt				 95
+#define __NR_socket				 96
+#define __NR_setsockopt				 97
+#define __NR_getsockopt				 98
+#define __NR_shutdown				 99
+#define __NR_bind				100
+#define __NR_connect				101
+#define __NR_listen				102
+#define __NR_accept				103
+#define __NR_getsockname			104
+#define __NR_getpeername			105
+#define __NR_sendmsg				106
+#define __NR_recvmsg				107
+#define __NR_send				108
+#define __NR_recv				109
+#define __NR_sendto				110
+#define __NR_recvfrom				111
+#define __NR_socketpair				112
+#define __NR_sendfile				113
+#define __NR_sendfile64				114
+#define __NR_sendmmsg				115
+#define __NR_clone				116
+#define __NR_execve				117
+#define __NR_exit				118
+#define __NR_exit_group				119
+#define __NR_getpid				120
+#define __NR_wait4				121
+#define __NR_waitid				122
+#define __NR_kill				123
+#define __NR_tkill				124
+#define __NR_tgkill				125
+#define __NR_set_tid_address			126
+#define __NR_gettid				127
+#define __NR_setsid				128
+#define __NR_getsid				129
+#define __NR_prctl				130
+#define __NR_personality			131
+#define __NR_getpriority			132
+#define __NR_setpriority			133
+#define __NR_setitimer				134
+#define __NR_getitimer				135
+#define __NR_setuid				136
+#define __NR_getuid				137
+#define __NR_setgid				138
+#define __NR_getgid				139
+#define __NR_geteuid				140
+#define __NR_getegid				141
+#define __NR_setreuid				142
+#define __NR_setregid				143
+#define __NR_setresuid				144
+#define __NR_getresuid				145
+#define __NR_setresgid				146
+#define __NR_getresgid				147
+#define __NR_setpgid				148
+#define __NR_getpgid				149
+#define __NR_getppid				150
+#define __NR_getpgrp				151
+#define __NR_reserved152			152	/* set_thread_area */
+#define __NR_reserved153			153	/* get_thread_area */
+#define __NR_times				154
+#define __NR_acct				155
+#define __NR_sched_setaffinity			156
+#define __NR_sched_getaffinity			157
+#define __NR_capget				158
+#define __NR_capset				159
+#define __NR_ptrace				160
+#define __NR_semtimedop				161
+#define __NR_semget				162
+#define __NR_semop				163
+#define __NR_semctl				164
+#define __NR_available165			165
+#define __NR_msgget				166
+#define __NR_msgsnd				167
+#define __NR_msgrcv				168
+#define __NR_msgctl				169
+#define __NR_available170			170
+#define __NR_umount2				171
+#define __NR_mount				172
+#define __NR_swapon				173
+#define __NR_chroot				174
+#define __NR_pivot_root				175
+#define __NR_umount				176
+#define __NR_swapoff				177
+#define __NR_sync				178
+#define __NR_syncfs				179
+#define __NR_setfsuid				180
+#define __NR_setfsgid				181
+#define __NR_sysfs				182
+#define __NR_ustat				183
+#define __NR_statfs				184
+#define __NR_fstatfs				185
+#define __NR_statfs64				186
+#define __NR_fstatfs64				187
+#define __NR_setrlimit				188
+#define __NR_getrlimit				189
+#define __NR_getrusage				190
+#define __NR_futex				191
+#define __NR_gettimeofday			192
+#define __NR_settimeofday			193
+#define __NR_adjtimex				194
+#define __NR_nanosleep				195
+#define __NR_getgroups				196
+#define __NR_setgroups				197
+#define __NR_sethostname			198
+#define __NR_setdomainname			199
+#define __NR_syslog				200
+#define __NR_vhangup				201
+#define __NR_uselib				202
+#define __NR_reboot				203
+#define __NR_quotactl				204
+#define __NR_nfsservctl				205
+#define __NR__sysctl				206
+#define __NR_bdflush				207
+#define __NR_uname				208
+#define __NR_sysinfo				209
+#define __NR_init_module			210
+#define __NR_delete_module			211
+#define __NR_sched_setparam			212
+#define __NR_sched_getparam			213
+#define __NR_sched_setscheduler			214
+#define __NR_sched_getscheduler			215
+#define __NR_sched_get_priority_max		216
+#define __NR_sched_get_priority_min		217
+#define __NR_sched_rr_get_interval		218
+#define __NR_sched_yield			219
+#define __NR_available222			222
+#define __NR_restart_syscall			223
+#define __NR_sigaltstack			224
+#define __NR_rt_sigreturn			225
+#define __NR_rt_sigaction			226
+#define __NR_rt_sigprocmask			227
+#define __NR_rt_sigpending			228
+#define __NR_rt_sigtimedwait			229
+#define __NR_rt_sigqueueinfo			230
+#define __NR_rt_sigsuspend			231
+#define __NR_mq_open				232
+#define __NR_mq_unlink				233
+#define __NR_mq_timedsend			234
+#define __NR_mq_timedreceive			235
+#define __NR_mq_notify				236
+#define __NR_mq_getsetattr			237
+#define __NR_available238			238
+#define __NR_io_setup				239
+#define __NR_io_destroy				240
+#define __NR_io_submit				241
+#define __NR_io_getevents			242
+#define __NR_io_cancel				243
+#define __NR_clock_settime			244
+#define __NR_clock_gettime			245
+#define __NR_clock_getres			246
+#define __NR_clock_nanosleep			247
+#define __NR_timer_create			248
+#define __NR_timer_delete			249
+#define __NR_timer_settime			250
+#define __NR_timer_gettime			251
+#define __NR_timer_getoverrun			252
+#define __NR_reserved253			253
+#define __NR_lookup_dcookie			254
+#define __NR_available255			255
+#define __NR_add_key				256
+#define __NR_request_key			257
+#define __NR_keyctl				258
+#define __NR_available259			259
+#define __NR_readahead				260
+#define __NR_remap_file_pages			261
+#define __NR_migrate_pages			262
+#define __NR_mbind				263
+#define __NR_get_mempolicy			264
+#define __NR_set_mempolicy			265
+#define __NR_unshare				266
+#define __NR_move_pages				267
+#define __NR_splice				268
+#define __NR_tee				269
+#define __NR_vmsplice				270
+#define __NR_available271			271
+#define __NR_pselect6				272
+#define __NR_ppoll				273
+#define __NR_epoll_pwait			274
+#define __NR_epoll_create1			275
+#define __NR_inotify_init			276
+#define __NR_inotify_add_watch			277
+#define __NR_inotify_rm_watch			278
+#define __NR_inotify_init1			279
+#define __NR_getcpu				280
+#define __NR_kexec_load				281
+#define __NR_ioprio_set				282
+#define __NR_ioprio_get				283
+#define __NR_set_robust_list			284
+#define __NR_get_robust_list			285
+#define __NR_available286			286
+#define __NR_available287			287
+#define __NR_openat				288
+#define __NR_mkdirat				289
+#define __NR_mknodat				290
+#define __NR_unlinkat				291
+#define __NR_renameat				292
+#define __NR_linkat				293
+#define __NR_symlinkat				294
+#define __NR_readlinkat				295
+#define __NR_utimensat				296
+#define __NR_fchownat				297
+#define __NR_futimesat				298
+#define __NR_fstatat64				299
+#define __NR_fchmodat				300
+#define __NR_faccessat				301
+#define __NR_available302			302
+#define __NR_available303			303
+#define __NR_signalfd				304
+#define __NR_eventfd				306
+#define __NR_recvmmsg				307
+#define __NR_setns				308
+#define __NR_signalfd4				309
+#define __NR_dup3				310
+#define __NR_pipe2				311
+#define __NR_timerfd_create			312
+#define __NR_timerfd_settime			313
+#define __NR_timerfd_gettime			314
+#define __NR_available315			315
+#define __NR_eventfd2				316
+#define __NR_preadv				317
+#define __NR_pwritev				318
+#define __NR_available319			319
+#define __NR_fanotify_init			320
+#define __NR_fanotify_mark			321
+#define __NR_process_vm_readv			322
+#define __NR_process_vm_writev			323
+#define __NR_name_to_handle_at			324
+#define __NR_open_by_handle_at			325
+#define __NR_sync_file_range2			326
+#define __NR_perf_event_open			327
+#define __NR_rt_tgsigqueueinfo			328
+#define __NR_clock_adjtime			329
+#define __NR_prlimit64				330
+#define __NR_kcmp				331
+#define __NR_finit_module			332
+#define __NR_accept4				333
+#define __NR_sched_setattr			334
+#define __NR_sched_getattr			335
+#define __NR_renameat2				336
+#define __NR_seccomp				337
+#define __NR_getrandom				338
+#define __NR_memfd_create			339
+#define __NR_bpf				340
+#define __NR_execveat				341
+
+#define SYS_spill				  0
+#define SYS_xtensa				  1
+#define SYS_available4				  2
+#define SYS_available5				  3
+#define SYS_available6				  4
+#define SYS_available7				  5
+#define SYS_available8				  6
+#define SYS_available9				  7
+#define SYS_open				  8
+#define SYS_close				  9
+#define SYS_dup					 10
+#define SYS_dup2				 11
+#define SYS_read				 12
+#define SYS_write				 13
+#define SYS_select				 14
+#define SYS_lseek				 15
+#define SYS_poll				 16
+#define SYS__llseek				 17
+#define SYS_epoll_wait				 18
+#define SYS_epoll_ctl				 19
+#define SYS_epoll_create			 20
+#define SYS_creat				 21
+#define SYS_truncate				 22
+#define SYS_ftruncate				 23
+#define SYS_readv				 24
+#define SYS_writev				 25
+#define SYS_fsync				 26
+#define SYS_fdatasync				 27
+#define SYS_truncate64				 28
+#define SYS_ftruncate64				 29
+#define SYS_pread64				 30
+#define SYS_pwrite64				 31
+#define SYS_link				 32
+#define SYS_rename				 33
+#define SYS_symlink				 34
+#define SYS_readlink				 35
+#define SYS_mknod				 36
+#define SYS_pipe				 37
+#define SYS_unlink				 38
+#define SYS_rmdir				 39
+#define SYS_mkdir				 40
+#define SYS_chdir				 41
+#define SYS_fchdir				 42
+#define SYS_getcwd				 43
+#define SYS_chmod				 44
+#define SYS_chown				 45
+#define SYS_stat				 46
+#define SYS_stat64				 47
+#define SYS_lchown				 48
+#define SYS_lstat				 49
+#define SYS_lstat64				 50
+#define SYS_available51				 51
+#define SYS_fchmod				 52
+#define SYS_fchown				 53
+#define SYS_fstat				 54
+#define SYS_fstat64				 55
+#define SYS_flock				 56
+#define SYS_access				 57
+#define SYS_umask				 58
+#define SYS_getdents				 59
+#define SYS_getdents64				 60
+#define SYS_fcntl64				 61
+#define SYS_fallocate				 62
+#define SYS_fadvise64_64			 63
+#define SYS_utime				 64	/* glibc 2.3.3 ?? */
+#define SYS_utimes				 65
+#define SYS_ioctl				 66
+#define SYS_fcntl				 67
+#define SYS_setxattr				 68
+#define SYS_getxattr				 69
+#define SYS_listxattr				 70
+#define SYS_removexattr				 71
+#define SYS_lsetxattr				 72
+#define SYS_lgetxattr				 73
+#define SYS_llistxattr				 74
+#define SYS_lremovexattr			 75
+#define SYS_fsetxattr				 76
+#define SYS_fgetxattr				 77
+#define SYS_flistxattr				 78
+#define SYS_fremovexattr			 79
+#define SYS_mmap2				 80
+#define SYS_munmap				 81
+#define SYS_mprotect				 82
+#define SYS_brk					 83
+#define SYS_mlock				 84
+#define SYS_munlock				 85
+#define SYS_mlockall				 86
+#define SYS_munlockall				 87
+#define SYS_mremap				 88
+#define SYS_msync				 89
+#define SYS_mincore				 90
+#define SYS_madvise				 91
+#define SYS_shmget				 92
+#define SYS_shmat				 93
+#define SYS_shmctl				 94
+#define SYS_shmdt				 95
+#define SYS_socket				 96
+#define SYS_setsockopt				 97
+#define SYS_getsockopt				 98
+#define SYS_shutdown				 99
+#define SYS_bind				100
+#define SYS_connect				101
+#define SYS_listen				102
+#define SYS_accept				103
+#define SYS_getsockname				104
+#define SYS_getpeername				105
+#define SYS_sendmsg				106
+#define SYS_recvmsg				107
+#define SYS_send				108
+#define SYS_recv				109
+#define SYS_sendto				110
+#define SYS_recvfrom				111
+#define SYS_socketpair				112
+#define SYS_sendfile				113
+#define SYS_sendfile64				114
+#define SYS_sendmmsg				115
+#define SYS_clone				116
+#define SYS_execve				117
+#define SYS_exit				118
+#define SYS_exit_group				119
+#define SYS_getpid				120
+#define SYS_wait4				121
+#define SYS_waitid				122
+#define SYS_kill				123
+#define SYS_tkill				124
+#define SYS_tgkill				125
+#define SYS_set_tid_address			126
+#define SYS_gettid				127
+#define SYS_setsid				128
+#define SYS_getsid				129
+#define SYS_prctl				130
+#define SYS_personality				131
+#define SYS_getpriority				132
+#define SYS_setpriority				133
+#define SYS_setitimer				134
+#define SYS_getitimer				135
+#define SYS_setuid				136
+#define SYS_getuid				137
+#define SYS_setgid				138
+#define SYS_getgid				139
+#define SYS_geteuid				140
+#define SYS_getegid				141
+#define SYS_setreuid				142
+#define SYS_setregid				143
+#define SYS_setresuid				144
+#define SYS_getresuid				145
+#define SYS_setresgid				146
+#define SYS_getresgid				147
+#define SYS_setpgid				148
+#define SYS_getpgid				149
+#define SYS_getppid				150
+#define SYS_getpgrp				151
+#define SYS_reserved152				152	/* set_thread_area */
+#define SYS_reserved153				153	/* get_thread_area */
+#define SYS_times				154
+#define SYS_acct				155
+#define SYS_sched_setaffinity			156
+#define SYS_sched_getaffinity			157
+#define SYS_capget				158
+#define SYS_capset				159
+#define SYS_ptrace				160
+#define SYS_semtimedop				161
+#define SYS_semget				162
+#define SYS_semop				163
+#define SYS_semctl				164
+#define SYS_available165			165
+#define SYS_msgget				166
+#define SYS_msgsnd				167
+#define SYS_msgrcv				168
+#define SYS_msgctl				169
+#define SYS_available170			170
+#define SYS_umount2				171
+#define SYS_mount				172
+#define SYS_swapon				173
+#define SYS_chroot				174
+#define SYS_pivot_root				175
+#define SYS_umount				176
+#define SYS_swapoff				177
+#define SYS_sync				178
+#define SYS_syncfs				179
+#define SYS_setfsuid				180
+#define SYS_setfsgid				181
+#define SYS_sysfs				182
+#define SYS_ustat				183
+#define SYS_statfs				184
+#define SYS_fstatfs				185
+#define SYS_statfs64				186
+#define SYS_fstatfs64				187
+#define SYS_setrlimit				188
+#define SYS_getrlimit				189
+#define SYS_getrusage				190
+#define SYS_futex				191
+#define SYS_gettimeofday			192
+#define SYS_settimeofday			193
+#define SYS_adjtimex				194
+#define SYS_nanosleep				195
+#define SYS_getgroups				196
+#define SYS_setgroups				197
+#define SYS_sethostname				198
+#define SYS_setdomainname			199
+#define SYS_syslog				200
+#define SYS_vhangup				201
+#define SYS_uselib				202
+#define SYS_reboot				203
+#define SYS_quotactl				204
+#define SYS_nfsservctl				205
+#define SYS__sysctl				206
+#define SYS_bdflush				207
+#define SYS_uname				208
+#define SYS_sysinfo				209
+#define SYS_init_module				210
+#define SYS_delete_module			211
+#define SYS_sched_setparam			212
+#define SYS_sched_getparam			213
+#define SYS_sched_setscheduler			214
+#define SYS_sched_getscheduler			215
+#define SYS_sched_get_priority_max		216
+#define SYS_sched_get_priority_min		217
+#define SYS_sched_rr_get_interval		218
+#define SYS_sched_yield				219
+#define SYS_available222			222
+#define SYS_restart_syscall			223
+#define SYS_sigaltstack				224
+#define SYS_rt_sigreturn			225
+#define SYS_rt_sigaction			226
+#define SYS_rt_sigprocmask			227
+#define SYS_rt_sigpending			228
+#define SYS_rt_sigtimedwait			229
+#define SYS_rt_sigqueueinfo			230
+#define SYS_rt_sigsuspend			231
+#define SYS_mq_open				232
+#define SYS_mq_unlink				233
+#define SYS_mq_timedsend			234
+#define SYS_mq_timedreceive			235
+#define SYS_mq_notify				236
+#define SYS_mq_getsetattr			237
+#define SYS_available238			238
+#define SYS_io_setup				239
+#define SYS_io_destroy				240
+#define SYS_io_submit				241
+#define SYS_io_getevents			242
+#define SYS_io_cancel				243
+#define SYS_clock_settime			244
+#define SYS_clock_gettime			245
+#define SYS_clock_getres			246
+#define SYS_clock_nanosleep			247
+#define SYS_timer_create			248
+#define SYS_timer_delete			249
+#define SYS_timer_settime			250
+#define SYS_timer_gettime			251
+#define SYS_timer_getoverrun			252
+#define SYS_reserved253				253
+#define SYS_lookup_dcookie			254
+#define SYS_available255			255
+#define SYS_add_key				256
+#define SYS_request_key				257
+#define SYS_keyctl				258
+#define SYS_available259			259
+#define SYS_readahead				260
+#define SYS_remap_file_pages			261
+#define SYS_migrate_pages			262
+#define SYS_mbind				263
+#define SYS_get_mempolicy			264
+#define SYS_set_mempolicy			265
+#define SYS_unshare				266
+#define SYS_move_pages				267
+#define SYS_splice				268
+#define SYS_tee					269
+#define SYS_vmsplice				270
+#define SYS_available271			271
+#define SYS_pselect6				272
+#define SYS_ppoll				273
+#define SYS_epoll_pwait				274
+#define SYS_epoll_create1			275
+#define SYS_inotify_init			276
+#define SYS_inotify_add_watch			277
+#define SYS_inotify_rm_watch			278
+#define SYS_inotify_init1			279
+#define SYS_getcpu				280
+#define SYS_kexec_load				281
+#define SYS_ioprio_set				282
+#define SYS_ioprio_get				283
+#define SYS_set_robust_list			284
+#define SYS_get_robust_list			285
+#define SYS_available286			286
+#define SYS_available287			287
+#define SYS_openat				288
+#define SYS_mkdirat				289
+#define SYS_mknodat				290
+#define SYS_unlinkat				291
+#define SYS_renameat				292
+#define SYS_linkat				293
+#define SYS_symlinkat				294
+#define SYS_readlinkat				295
+#define SYS_utimensat				296
+#define SYS_fchownat				297
+#define SYS_futimesat				298
+#define SYS_fstatat64				299
+#define SYS_fchmodat				300
+#define SYS_faccessat				301
+#define SYS_available302			302
+#define SYS_available303			303
+#define SYS_signalfd				304
+#define SYS_eventfd				306
+#define SYS_recvmmsg				307
+#define SYS_setns				308
+#define SYS_signalfd4				309
+#define SYS_dup3				310
+#define SYS_pipe2				311
+#define SYS_timerfd_create			312
+#define SYS_timerfd_settime			313
+#define SYS_timerfd_gettime			314
+#define SYS_available315			315
+#define SYS_eventfd2				316
+#define SYS_preadv				317
+#define SYS_pwritev				318
+#define SYS_available319			319
+#define SYS_fanotify_init			320
+#define SYS_fanotify_mark			321
+#define SYS_process_vm_readv			322
+#define SYS_process_vm_writev			323
+#define SYS_name_to_handle_at			324
+#define SYS_open_by_handle_at			325
+#define SYS_sync_file_range2			326
+#define SYS_perf_event_open			327
+#define SYS_rt_tgsigqueueinfo			328
+#define SYS_clock_adjtime			329
+#define SYS_prlimit64				330
+#define SYS_kcmp				331
+#define SYS_finit_module			332
+#define SYS_accept4				333
+#define SYS_sched_setattr			334
+#define SYS_sched_getattr			335
+#define SYS_renameat2				336
+#define SYS_seccomp				337
+#define SYS_getrandom				338
+#define SYS_memfd_create			339
+#define SYS_bpf					340
+#define SYS_execveat				341
diff --git a/arch/xtensa/bits/termios.h b/arch/xtensa/bits/termios.h
new file mode 100644
index 0000000..f1b32e0
--- /dev/null
+++ b/arch/xtensa/bits/termios.h
@@ -0,0 +1,168 @@
+struct termios
+{
+	tcflag_t c_iflag;
+	tcflag_t c_oflag;
+	tcflag_t c_cflag;
+	tcflag_t c_lflag;
+	cc_t c_line;
+	cc_t c_cc[NCCS];
+	speed_t __c_ispeed;
+	speed_t __c_ospeed;
+};
+
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+#define IGNBRK	0000001
+#define BRKINT	0000002
+#define IGNPAR	0000004
+#define PARMRK	0000010
+#define INPCK	0000020
+#define ISTRIP	0000040
+#define INLCR	0000100
+#define IGNCR	0000200
+#define ICRNL	0000400
+#define IUCLC	0001000
+#define IXON	0002000
+#define IXANY	0004000
+#define IXOFF	0010000
+#define IMAXBEL	0020000
+#define IUTF8	0040000
+
+#define OPOST	0000001
+#define OLCUC	0000002
+#define ONLCR	0000004
+#define OCRNL	0000010
+#define ONOCR	0000020
+#define ONLRET	0000040
+#define OFILL	0000100
+#define OFDEL	0000200
+#define NLDLY	0000400
+#define   NL0	0000000
+#define   NL1	0000400
+#define CRDLY	0003000
+#define   CR0	0000000
+#define   CR1	0001000
+#define   CR2	0002000
+#define   CR3	0003000
+#define TABDLY	0014000
+#define   TAB0	0000000
+#define   TAB1	0004000
+#define   TAB2	0010000
+#define   TAB3	0014000
+#define   XTABS	0014000
+#define BSDLY	0020000
+#define   BS0	0000000
+#define   BS1	0020000
+#define VTDLY	0040000
+#define   VT0	0000000
+#define   VT1	0040000
+#define FFDLY	0100000
+#define   FF0	0000000
+#define   FF1	0100000
+
+#define B0       0000000
+#define B50      0000001
+#define B75      0000002
+#define B110     0000003
+#define B134     0000004
+#define B150     0000005
+#define B200     0000006
+#define B300     0000007
+#define B600     0000010
+#define B1200    0000011
+#define B1800    0000012
+#define B2400    0000013
+#define B4800    0000014
+#define B9600    0000015
+#define B19200   0000016
+#define B38400   0000017
+#define EXTA     0000016
+#define EXTB     0000017
+
+#define BOTHER   0010000
+#define B57600   0010001
+#define B115200  0010002
+#define B230400  0010003
+#define B460800  0010004
+#define B500000  0010005
+#define B576000  0010006
+#define B921600  0010007
+#define B1000000 0010010
+#define B1152000 0010011
+#define B1500000 0010012
+#define B2000000 0010013
+#define B2500000 0010014
+#define B3000000 0010015
+#define B3500000 0010016
+#define B4000000 0010017
+
+#define CBAUD    0010017
+
+#define CSIZE  0000060
+#define CS5    0000000
+#define CS6    0000020
+#define CS7    0000040
+#define CS8    0000060
+#define CSTOPB 0000100
+#define CREAD  0000200
+#define PARENB 0000400
+#define PARODD 0001000
+#define HUPCL  0002000
+#define CLOCAL 0004000
+
+#define ISIG	0000001
+#define ICANON	0000002
+#define XCASE	0000004
+#define ECHO	0000010
+#define ECHOE	0000020
+#define ECHOK	0000040
+#define ECHONL	0000100
+#define NOFLSH	0000200
+#define TOSTOP	0000400
+#define ECHOCTL	0001000
+#define ECHOPRT	0002000
+#define ECHOKE	0004000
+#define FLUSHO	0010000
+#define PENDIN	0040000
+#define IEXTEN	0100000
+#define EXTPROC	0200000
+
+#define TCOOFF 0
+#define TCOON  1
+#define TCIOFF 2
+#define TCION  3
+
+#define TCIFLUSH  0
+#define TCOFLUSH  1
+#define TCIOFLUSH 2
+
+#define TCSANOW   0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX 0010000
+#define CIBAUD   002003600000
+#define IBSHIFT 16
+#define CMSPAR   010000000000
+#define CRTSCTS  020000000000
+#define EXTPROC 0200000
+#define XTABS  0014000
+#define TIOCSER_TEMT 1
+#endif
diff --git a/arch/xtensa/bits/user.h b/arch/xtensa/bits/user.h
new file mode 100644
index 0000000..8ac7526
--- /dev/null
+++ b/arch/xtensa/bits/user.h
@@ -0,0 +1,4 @@
+#define ELF_NGREG 128
+#define ELF_NFPREG 18
+typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];
+typedef unsigned int elf_fpreg_t, elf_fpregset_t[ELF_NFPREG];
diff --git a/arch/xtensa/bits/xtensa-config.h b/arch/xtensa/bits/xtensa-config.h
new file mode 100644
index 0000000..2e60af9
--- /dev/null
+++ b/arch/xtensa/bits/xtensa-config.h
@@ -0,0 +1,46 @@
+/* Xtensa configuration settings.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Free Software Foundation, Inc.
+   Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef XTENSA_CONFIG_H
+#define XTENSA_CONFIG_H
+
+/* The macros defined here match those with the same names in the Xtensa
+   compile-time HAL (Hardware Abstraction Layer).  Please refer to the
+   Xtensa System Software Reference Manual for documentation of these
+   macros.  */
+
+/* The following macros reflect the default expectations for Xtensa
+   processor configurations that can run glibc.  If you want to try
+   building glibc for an Xtensa configuration that is missing these
+   options, you will at least need to change the values of these
+   macros.  */
+
+#undef XCHAL_HAVE_NSA
+#define XCHAL_HAVE_NSA			1
+
+#undef XCHAL_HAVE_LOOPS
+#define XCHAL_HAVE_LOOPS		1
+
+/* Assume the maximum number of AR registers.  This currently only affects
+   the __window_spill function, and it is always safe to flush extra.  */
+
+#undef XCHAL_NUM_AREGS
+#define XCHAL_NUM_AREGS			64
+
+#endif /* !XTENSA_CONFIG_H */
diff --git a/arch/xtensa/crt_arch.h b/arch/xtensa/crt_arch.h
new file mode 100644
index 0000000..dc6ddaa
--- /dev/null
+++ b/arch/xtensa/crt_arch.h
@@ -0,0 +1,26 @@
+__asm__(
+".begin no-transform\n"
+".text \n"
+".global _" START "\n"
+".global " START "\n"
+".type   _" START ", @function\n"
+".type   " START ", @function\n"
+"_" START ":\n"
+"" START ":\n"
+"	call0	2f\n"
+"1:\n"
+".align 4\n"
+".weak _DYNAMIC\n"
+".hidden _DYNAMIC\n"
+"	.literal .L0, _DYNAMIC\n"
+"	.literal .L1, 1b\n"
+"2:\n"
+"	mov	a6, a1\n"
+"	l32r	a7, .L0\n"
+"	l32r	a5, .L1\n"
+"	add	a7, a7, a0\n"
+"	sub	a7, a7, a5\n"
+"	movi	a0, 0\n"
+"	call4	" START "_c\n"
+".end no-transform\n"
+);
diff --git a/arch/xtensa/pthread_arch.h b/arch/xtensa/pthread_arch.h
new file mode 100644
index 0000000..35c752e
--- /dev/null
+++ b/arch/xtensa/pthread_arch.h
@@ -0,0 +1,11 @@
+static inline struct pthread *__pthread_self()
+{
+	register char *tp;
+	__asm__ __volatile__ ("rur %0, threadptr" : "=r" (tp));
+	return (pthread_t)(tp + 8 - sizeof(struct pthread));
+}
+
+#define TLS_ABOVE_TP
+#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8)
+
+#define MC_PC sc_pc
diff --git a/arch/xtensa/reloc.h b/arch/xtensa/reloc.h
new file mode 100644
index 0000000..bae93a5
--- /dev/null
+++ b/arch/xtensa/reloc.h
@@ -0,0 +1,21 @@
+#include <endian.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define ENDIAN_SUFFIX "eb"
+#else
+#define ENDIAN_SUFFIX ""
+#endif
+
+#define LDSO_ARCH "xtensa" ENDIAN_SUFFIX
+
+#define TPOFF_K 8
+
+#define REL_PLT         R_XTENSA_JMP_SLOT
+#define REL_RELATIVE    R_XTENSA_RELATIVE
+#define REL_GOT         R_XTENSA_GLOB_DAT
+#define REL_COPY        R_XTENSA_32
+#define REL_TPOFF       R_XTENSA_TLS_TPOFF
+//#define REL_TLSDESC     R_XTENSA_TLSDESC_FN
+
+#define CRTJMP(pc,sp) __asm__ __volatile__( \
+	"movsp a1, %1 ; jx %0" : : "a"(pc), "a"(sp) : "memory" )
diff --git a/arch/xtensa/syscall_arch.h b/arch/xtensa/syscall_arch.h
new file mode 100644
index 0000000..380ce17
--- /dev/null
+++ b/arch/xtensa/syscall_arch.h
@@ -0,0 +1,102 @@
+#define __SYSCALL_LL_E(x) \
+((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
+((union { long long ll; long l[2]; }){ .ll = x }).l[1]
+#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
+
+static inline long __syscall0(long n)
+{
+	register long a2 __asm__("a2") = n;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      :
+			      : "memory");
+	return a2;
+}
+
+static inline long __syscall1(long n, long a)
+{
+	register long a2 __asm__("a2") = n;
+	register long a6 __asm__("a6") = a;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      : "a"(a6)
+			      : "memory");
+	return a2;
+}
+
+static inline long __syscall2(long n, long a, long b)
+{
+	register long a2 __asm__("a2") = n;
+	register long a6 __asm__("a6") = a;
+	register long a3 __asm__("a3") = b;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      : "a"(a6), "a"(a3)
+			      : "memory");
+	return a2;
+}
+
+static inline long __syscall3(long n, long a, long b, long c)
+{
+	register long a2 __asm__("a2") = n;
+	register long a6 __asm__("a6") = a;
+	register long a3 __asm__("a3") = b;
+	register long a4 __asm__("a4") = c;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      : "a"(a6), "a"(a3), "a"(a4)
+			      : "memory");
+	return a2;
+}
+
+static inline long __syscall4(long n, long a, long b, long c, long d)
+{
+	register long a2 __asm__("a2") = n;
+	register long a6 __asm__("a6") = a;
+	register long a3 __asm__("a3") = b;
+	register long a4 __asm__("a4") = c;
+	register long a5 __asm__("a5") = d;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      : "a"(a6), "a"(a3), "a"(a4), "a"(a5)
+			      : "memory");
+	return a2;
+}
+
+static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+{
+	register long a2 __asm__("a2") = n;
+	register long a6 __asm__("a6") = a;
+	register long a3 __asm__("a3") = b;
+	register long a4 __asm__("a4") = c;
+	register long a5 __asm__("a5") = d;
+	register long a8 __asm__("a8") = e;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      : "a"(a6), "a"(a3), "a"(a4), "a"(a5), "a"(a8)
+			      : "memory");
+	return a2;
+}
+
+static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+{
+	register long a2 __asm__("a2") = n;
+	register long a6 __asm__("a6") = a;
+	register long a3 __asm__("a3") = b;
+	register long a4 __asm__("a4") = c;
+	register long a5 __asm__("a5") = d;
+	register long a8 __asm__("a8") = e;
+	register long a9 __asm__("a9") = f;
+
+	__asm__ __volatile__ ("syscall"
+			      : "+&a"(a2)
+			      : "a"(a6), "a"(a3), "a"(a4), "a"(a5), "a"(a8), "a"(a9)
+			      : "memory");
+	return a2;
+}
diff --git a/configure b/configure
index 0955ce6..2c56cab 100755
--- a/configure
+++ b/configure
@@ -312,6 +312,7 @@ microblaze*) ARCH=microblaze ;;
 or1k*) ARCH=or1k ;;
 powerpc*) ARCH=powerpc ;;
 sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
+xtensa*) ARCH=xtensa ;;
 unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
 *) fail "$0: unknown or unsupported target \"$target\"" ;;
 esac
diff --git a/crt/xtensa/crti.s b/crt/xtensa/crti.s
new file mode 100644
index 0000000..6565656
--- /dev/null
+++ b/crt/xtensa/crti.s
@@ -0,0 +1,11 @@
+.section .init
+.global  _init
+.type    _init, @function
+_init:
+	entry	a1, 32
+
+.section .fini
+.global  _fini
+.type    _fini, @function
+_fini:
+	entry	a1, 32
diff --git a/crt/xtensa/crtn.s b/crt/xtensa/crtn.s
new file mode 100644
index 0000000..7e9a014
--- /dev/null
+++ b/crt/xtensa/crtn.s
@@ -0,0 +1,5 @@
+.section .init
+	retw
+
+.section .fini
+	retw
diff --git a/include/elf.h b/include/elf.h
index 8b3cd3e..8168cf1 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -2819,6 +2819,64 @@ typedef Elf32_Addr Elf32_Conflict;
 #define R_OR1K_TLS_DTPOFF	33
 #define R_OR1K_TLS_DTPMOD	34
 
+
+#define DT_XTENSA_GOT_LOC_OFF	(DT_LOPROC + 0)
+#define DT_XTENSA_GOT_LOC_SZ	(DT_LOPROC + 1)
+#define DT_XTENSA_NUM		2
+
+#define R_XTENSA_NONE		0
+#define R_XTENSA_32		1
+#define R_XTENSA_RTLD		2
+#define R_XTENSA_GLOB_DAT	3
+#define R_XTENSA_JMP_SLOT	4
+#define R_XTENSA_RELATIVE	5
+#define R_XTENSA_PLT		6
+#define R_XTENSA_OP0		8
+#define R_XTENSA_OP1		9
+#define R_XTENSA_OP2		10
+#define R_XTENSA_ASM_EXPAND	11
+#define R_XTENSA_ASM_SIMPLIFY	12
+#define R_XTENSA_GNU_VTINHERIT	15
+#define R_XTENSA_GNU_VTENTRY	16
+#define R_XTENSA_DIFF8		17
+#define R_XTENSA_DIFF16		18
+#define R_XTENSA_DIFF32		19
+#define R_XTENSA_SLOT0_OP	20
+#define R_XTENSA_SLOT1_OP	21
+#define R_XTENSA_SLOT2_OP	22
+#define R_XTENSA_SLOT3_OP	23
+#define R_XTENSA_SLOT4_OP	24
+#define R_XTENSA_SLOT5_OP	25
+#define R_XTENSA_SLOT6_OP	26
+#define R_XTENSA_SLOT7_OP	27
+#define R_XTENSA_SLOT8_OP	28
+#define R_XTENSA_SLOT9_OP	29
+#define R_XTENSA_SLOT10_OP	30
+#define R_XTENSA_SLOT11_OP	31
+#define R_XTENSA_SLOT12_OP	32
+#define R_XTENSA_SLOT13_OP	33
+#define R_XTENSA_SLOT14_OP	34
+#define R_XTENSA_SLOT0_ALT	35
+#define R_XTENSA_SLOT1_ALT	36
+#define R_XTENSA_SLOT2_ALT	37
+#define R_XTENSA_SLOT3_ALT	38
+#define R_XTENSA_SLOT4_ALT	39
+#define R_XTENSA_SLOT5_ALT	40
+#define R_XTENSA_SLOT6_ALT	41
+#define R_XTENSA_SLOT7_ALT	42
+#define R_XTENSA_SLOT8_ALT	43
+#define R_XTENSA_SLOT9_ALT	44
+#define R_XTENSA_SLOT10_ALT	45
+#define R_XTENSA_SLOT11_ALT	46
+#define R_XTENSA_SLOT12_ALT	47
+#define R_XTENSA_SLOT13_ALT	48
+#define R_XTENSA_SLOT14_ALT	49
+#define R_XTENSA_TLSDESC_FN	50
+#define R_XTENSA_TLSDESC_ARG	51
+#define R_XTENSA_TLS_TPOFF	53
+
+#define R_XTENSA_NUM		54
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/ldso/dlstart.c b/ldso/dlstart.c
index 4dbe178..0249937 100644
--- a/ldso/dlstart.c
+++ b/ldso/dlstart.c
@@ -22,6 +22,7 @@ void _dlstart_c(size_t *sp, size_t *dynv)
 {
 	size_t i, aux[AUX_CNT], dyn[DYN_CNT];
 	size_t *rel, rel_size, base;
+	unsigned long addr = 1;
 
 	int argc = *sp;
 	char **argv = (void *)(sp+1);
@@ -138,7 +139,17 @@ void _dlstart_c(size_t *sp, size_t *dynv)
 	for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
 		if (!IS_RELATIVE(rel[1], 0)) continue;
 		size_t *rel_addr = (void *)(base + rel[0]);
-		*rel_addr = base + rel[2];
+		if (((unsigned long)rel_addr & -4096) != addr) {
+			addr = (unsigned long)rel_addr & -4096;
+			__asm__ __volatile__ ("movi a2, 82\n\t"
+					      "mov a6, %0\n\t"
+					      "mov a3, %1\n\t"
+					      "mov a4, %2\n\t"
+					      "syscall"
+					      :: "a"(addr), "a"(4096), "a"(7)
+					      : "a2", "a3", "a4", "a6", "memory");
+		}
+		*rel_addr += base + rel[2];
 	}
 #endif
 
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 87f3b7f..1927097 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -314,6 +314,7 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 	size_t tls_val;
 	size_t addend;
 	int skip_relative = 0, reuse_addends = 0, save_slot = 0;
+	unsigned long addr = 1;
 
 	if (dso == &ldso) {
 		/* Only ldso's REL table needs addend saving/reuse. */
@@ -328,6 +329,10 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 		if (type == REL_NONE) continue;
 		sym_index = R_SYM(rel[1]);
 		reloc_addr = laddr(dso, rel[0]);
+		if (((unsigned long)reloc_addr & -4096) != addr) {
+			addr = (unsigned long)reloc_addr & -4096;
+			mprotect((void *)addr, 4096, 7);
+		}
 		if (sym_index) {
 			sym = syms + sym_index;
 			name = strings + sym->st_name;
@@ -377,7 +382,7 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 			*reloc_addr = sym_val + addend;
 			break;
 		case REL_RELATIVE:
-			*reloc_addr = (size_t)base + addend;
+			*reloc_addr += (size_t)base + addend;
 			break;
 		case REL_SYM_OR_REL:
 			if (sym) *reloc_addr = sym_val + addend;
@@ -444,6 +449,40 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 #endif
 			}
 			break;
+		case R_XTENSA_RTLD:
+			break;
+		case R_XTENSA_TLSDESC_FN:
+			if (runtime && def.dso->tls_id >= static_tls_cnt) {
+				reloc_addr[0] = (size_t)__tlsdesc_dynamic;
+			} else {
+				reloc_addr[0] = (size_t)__tlsdesc_static;
+			}
+			break;
+		case R_XTENSA_TLSDESC_ARG:
+			if (stride<3) addend = reloc_addr[1];
+			if (runtime && def.dso->tls_id >= static_tls_cnt) {
+				struct td_index *new = malloc(sizeof *new);
+				if (!new) {
+					error(
+					"Error relocating %s: cannot allocate TLSDESC for %s",
+					dso->name, sym ? name : "(local)" );
+					longjmp(*rtld_fail, 1);
+				}
+				new->next = dso->td_index;
+				dso->td_index = new;
+				new->args[0] = def.dso->tls_id;
+				new->args[1] = tls_val + addend;
+				reloc_addr[0] = (size_t)new;
+			} else {
+#ifdef TLS_ABOVE_TP
+				reloc_addr[0] = tls_val + def.dso->tls.offset
+					+ TPOFF_K + addend;
+#else
+				reloc_addr[0] = tls_val - def.dso->tls.offset
+					+ addend;
+#endif
+			}
+			break;
 		default:
 			error("Error relocating %s: unsupported relocation type %d",
 				dso->name, type);
diff --git a/src/internal/xtensa/syscall.s b/src/internal/xtensa/syscall.s
new file mode 100644
index 0000000..6dc584b
--- /dev/null
+++ b/src/internal/xtensa/syscall.s
@@ -0,0 +1,15 @@
+.global __syscall
+.hidden __syscall
+.type   __syscall,@function
+.align 4
+__syscall:
+	entry	a1, 16
+	mov	a8, a3
+	mov	a3, a4
+	mov	a4, a5
+	mov	a5, a6
+	mov	a6, a8
+	mov	a8, a7
+	l32i	a9, a1, 16
+	syscall
+	retw
diff --git a/src/ldso/xtensa/tlsdesc.s b/src/ldso/xtensa/tlsdesc.s
new file mode 100644
index 0000000..5fa846d
--- /dev/null
+++ b/src/ldso/xtensa/tlsdesc.s
@@ -0,0 +1,22 @@
+.global __tlsdesc_static
+.hidden __tlsdesc_static
+.type __tlsdesc_static,@function
+.align 4
+__tlsdesc_static:
+	entry	a1, 16
+	rur	a3, threadptr
+	add	a2, a2, a3
+	retw
+
+.hidden __tls_get_new
+
+.global __tlsdesc_dynamic
+.hidden __tlsdesc_dynamic
+.type __tlsdesc_dynamic,@function
+.align 4
+__tlsdesc_dynamic:
+	entry	a1, 16
+	mov	a6, a2
+	call4	__tls_get_addr
+	mov	a2, a6
+	retw
diff --git a/src/setjmp/xtensa/longjmp.s b/src/setjmp/xtensa/longjmp.s
new file mode 100644
index 0000000..0b49188
--- /dev/null
+++ b/src/setjmp/xtensa/longjmp.s
@@ -0,0 +1,73 @@
+.global _longjmp
+.global longjmp
+.type _longjmp,%function
+.type longjmp,%function
+.align 4
+_longjmp:
+longjmp:
+	entry	a1, 16
+
+	/* Invalidate all but the current register window. */
+	call4	__window_spill
+
+	l32i	a0, a2, 64
+	addi	a7, a1, -16
+	l32i	a4, a2, 0
+	l32i	a5, a2, 4
+	s32i	a4, a7, 0
+	s32i	a5, a7, 4
+	l32i	a4, a2, 8
+	l32i	a5, a2, 12
+	s32i	a4, a7, 8
+	s32i	a5, a7, 12
+
+	/* Copy the remaining 0-8 saved registers. */
+	extui	a7, a0, 30, 2
+	blti	a7, 2, 2f
+	l32i	a8, a2, 52	/* a8: SP of 'caller-1' */
+	slli	a4, a7, 4
+	sub	a6, a8, a4
+	addi	a5, a2, 16
+	addi	a8, a8, -16	/* a8: end of overflow area */
+1:
+	l32i	a7, a5, 0
+	l32i	a4, a5, 4
+	s32i	a7, a6, 0
+	s32i	a4, a6, 4
+	l32i	a7, a5, 8
+	l32i	a4, a5, 12
+	s32i	a7, a6, 8
+	s32i	a4, a6, 12
+	addi	a5, a5, 16
+	addi	a6, a6, 16
+	bltu	a6, a8, 1b
+2:
+	/* The 4 words saved from the register save area at the target's
+	 * sp are copied back to the target procedure's save area. The
+	 * only point of this is to prevent a catastrophic failure in
+	 * case the contents were moved by an alloca after calling
+	 * setjmp. This is a bit paranoid but it doesn't cost much.
+	 */
+
+	l32i	a7, a2, 4		/* load the target stack pointer */
+	addi	a7, a7, -16		/* find the destination save area */
+	l32i	a4, a2, 48
+	l32i	a5, a2, 52
+	s32i	a4, a7, 0
+	s32i	a5, a7, 4
+	l32i	a4, a2, 56
+	l32i	a5, a2, 60
+	s32i	a4, a7, 8
+	s32i	a5, a7, 12
+
+	l32i	a4, a2, 68
+	beqz	a4, 1f
+
+	mov	a6, a2
+	movi	a7, 1
+.hidden __sigsetjmp_tail
+	call4	__sigsetjmp_tail
+1:
+	movi	a2, 1
+	movnez	a2, a3, a3
+	retw
diff --git a/src/setjmp/xtensa/setjmp.s b/src/setjmp/xtensa/setjmp.s
new file mode 100644
index 0000000..1366af0
--- /dev/null
+++ b/src/setjmp/xtensa/setjmp.s
@@ -0,0 +1,13 @@
+.global __setjmp
+.global _setjmp
+.global setjmp
+.type __setjmp,@function
+.type _setjmp,@function
+.type setjmp,@function
+.align 4
+__setjmp:
+_setjmp:
+setjmp:
+	entry	a1, 16
+	movi	a3, 0
+	j	___sigsetjmp
diff --git a/src/signal/xtensa/restore.s b/src/signal/xtensa/restore.s
new file mode 100644
index 0000000..a0c5229
--- /dev/null
+++ b/src/signal/xtensa/restore.s
@@ -0,0 +1,10 @@
+.global __restore
+.global __restore_rt
+.type __restore,%function
+.type __restore_rt,%function
+.space 1
+.align 4
+__restore:
+__restore_rt:
+	movi	a2, 225 # SYS_rt_sigreturn
+	syscall
diff --git a/src/signal/xtensa/sigsetjmp.s b/src/signal/xtensa/sigsetjmp.s
new file mode 100644
index 0000000..825e182
--- /dev/null
+++ b/src/signal/xtensa/sigsetjmp.s
@@ -0,0 +1,69 @@
+.global sigsetjmp
+.global __sigsetjmp
+.global ___sigsetjmp
+.type sigsetjmp,%function
+.type __sigsetjmp,%function
+.type ___sigsetjmp,%function
+.align 4
+sigsetjmp:
+__sigsetjmp:
+	entry	a1, 16
+
+___sigsetjmp:
+	call4	__window_spill
+
+	/* Copy the caller registers a0 - a3 at (sp - 16) to jmpbuf. */
+	addi	a7, a1, -16
+	l32i	a4, a7, 0
+	l32i	a5, a7, 4
+	s32i	a4, a2, 0
+	s32i	a5, a2, 4
+	l32i	a4, a7, 8
+	l32i	a5, a7, 12
+	s32i	a4, a2, 8
+	s32i	a5, a2, 12
+
+	/* Copy the caller registers a4-a8/a12 from the overflow area. */
+	/* Entry moved the SP by 16 bytes, so SP of caller-1 is at (sp + 4). */
+	extui	a7, a0, 30, 2
+	blti	a7, 2, 2f
+	l32i	a8, a1, 4	/* a8: SP of 'caller-1' */
+	slli	a4, a7, 4
+	sub	a6, a8, a4
+	addi	a5, a2, 16
+	addi	a8, a8, -16	/* a8: end of overflow area */
+1:
+	l32i	a7, a6, 0
+	l32i	a4, a6, 4
+	s32i	a7, a5, 0
+	s32i	a4, a5, 4
+	l32i	a7, a6, 8
+	l32i	a4, a6, 12
+	s32i	a7, a5, 8
+	s32i	a4, a5, 12
+	addi	a5, a5, 16
+	addi	a6, a6, 16
+	bltu	a6, a8, 1b
+2:
+	/* Copy caller-1 registers a0 - a3 (this is assuming entry a1, 16) */
+	l32i	a4, a1, 0
+	l32i	a5, a1, 4
+	s32i	a4, a2, 48
+	s32i	a5, a2, 52
+	l32i	a4, a1, 8
+	l32i	a5, a1, 12
+	s32i	a4, a2, 56
+	s32i	a5, a2, 60
+
+	/* Save the return address, including the window size bits. */
+	s32i	a0, a2, 64
+	s32i	a3, a2, 68
+	beqz	a3, 1f
+
+	mov	a6, a2
+	movi	a7, 0
+.hidden __sigsetjmp_tail
+	call4	__sigsetjmp_tail
+1:
+	movi	a2, 0
+	retw
diff --git a/src/signal/xtensa/windowspill.s b/src/signal/xtensa/windowspill.s
new file mode 100644
index 0000000..7ab7f3d
--- /dev/null
+++ b/src/signal/xtensa/windowspill.s
@@ -0,0 +1,78 @@
+#include <bits/xtensa-config.h>
+
+#ifdef __XTENSA_WINDOWED_ABI__
+.global __window_spill
+.type   __window_spill, @function
+.align  4
+__window_spill:
+	entry	a1, 48
+	bbci.l	a0, 31, .L4		/* branch if called with call4 */
+	bbsi.l	a0, 30, .L12		/* branch if called with call12 */
+
+	/* Called with call8: touch register NUM_REGS-12 (4/20/52) */
+.L8:
+#if XCHAL_NUM_AREGS > 16
+	call12	1f
+	retw
+
+	.align	4
+1:	_entry	a1, 48			/* touch NUM_REGS-24 (x/8/40) */
+
+#if XCHAL_NUM_AREGS == 32
+	mov	a8, a0
+	retw
+#else
+	mov	a12, a0
+	_entry	a1, 48			/* touch NUM_REGS-36 (x/x/28) */
+	mov	a12, a0
+	_entry	a1, 48			/* touch NUM_REGS-48 (x/x/16) */
+	mov	a12, a0
+	_entry	a1, 16			/* touch NUM_REGS-60 (x/x/4) */
+#endif
+#endif
+	mov	a4, a0
+	retw
+
+	/* Called with call4: touch register NUM_REGS-8 (8/24/56) */
+.L4:
+#if XCHAL_NUM_AREGS == 16
+	mov	a8, a0
+#else
+	call12	1f
+	retw
+
+	.align	4
+1:	_entry	a1, 48			/* touch NUM_REGS-20 (x/12/44) */
+	mov	a12, a0
+#if XCHAL_NUM_AREGS > 32
+	_entry	a1, 48			/* touch NUM_REGS-32 (x/x/32) */
+	mov	a12, a0
+	_entry	a1, 48			/* touch NUM_REGS-44 (x/x/20) */
+	mov	a12, a0
+	_entry	a1, 48			/* touch NUM_REGS-56 (x/x/8) */
+	mov	a8, a0
+#endif
+#endif
+	retw
+
+	/* Called with call12: touch register NUM_REGS-16 (x/16/48) */
+.L12:
+#if XCHAL_NUM_AREGS > 16
+	call12	1f
+	retw
+
+	.align	4
+1:	_entry	a1, 48			/* touch NUM_REGS-28 (x/4/36) */
+#if XCHAL_NUM_AREGS == 32
+	mov	a4, a0
+#else
+	mov	a12, a0
+	_entry	a1, 48			/* touch NUM_REGS-40 (x/x/24) */
+	mov	a12, a0
+	_entry	a1, 48			/* touch NUM_REGS-52 (x/x/12) */
+	mov	a12, a0
+#endif
+#endif
+	retw
+
+#endif
diff --git a/src/thread/xtensa/__set_thread_area.s b/src/thread/xtensa/__set_thread_area.s
new file mode 100644
index 0000000..4fe97ac
--- /dev/null
+++ b/src/thread/xtensa/__set_thread_area.s
@@ -0,0 +1,8 @@
+.global __set_thread_area
+.type   __set_thread_area,@function
+.align 4
+__set_thread_area:
+	entry	a1, 16
+	wur	a2, threadptr
+	movi	a2, 0
+	retw
diff --git a/src/thread/xtensa/__unmapself.s b/src/thread/xtensa/__unmapself.s
new file mode 100644
index 0000000..c5d8f54
--- /dev/null
+++ b/src/thread/xtensa/__unmapself.s
@@ -0,0 +1,10 @@
+.global __unmapself
+.type   __unmapself,%function
+.align 4
+__unmapself:
+	entry	a1, 16
+	mov	a6, a2
+	movi	a2, 81 # SYS_munmap
+	syscall
+	movi	a2, 118 # SYS_exit
+	syscall
diff --git a/src/thread/xtensa/clone.s b/src/thread/xtensa/clone.s
new file mode 100644
index 0000000..c75db81
--- /dev/null
+++ b/src/thread/xtensa/clone.s
@@ -0,0 +1,39 @@
+// __clone(func, stack, flags, arg, ptid, tls, ctid)
+//         a2,   a3,    a4,    a5,  a6,   a7,  [sp]
+
+// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
+//         a2,        a6,    a3,    a4,   a5,  a8
+
+.global __clone
+.type   __clone,%function
+.align 4
+__clone:
+	entry	a1, 16
+	// align stack and save func,arg
+	srli	a3, a3, 4
+	slli	a3, a3, 4
+	addi	a3, a3, -16
+	s32i	a2, a3, 0
+	s32i	a5, a3, 4
+
+	// syscall
+	mov	a2, a4
+	mov	a4, a6
+	mov	a6, a2
+	mov	a5, a7
+	l32i	a8, a1, 16
+	movi	a2, 116 # SYS_clone
+	syscall
+
+	beqz	a2, 1f
+	// parent
+	retw
+
+	// child
+1:
+	movi	a0, 0
+	l32i	a4, a1, 0
+	l32i	a6, a1, 4
+	callx4	a4
+	movi	a2, 118 # SYS_exit
+	syscall
diff --git a/src/thread/xtensa/syscall_cp.s b/src/thread/xtensa/syscall_cp.s
new file mode 100644
index 0000000..f68df8d
--- /dev/null
+++ b/src/thread/xtensa/syscall_cp.s
@@ -0,0 +1,37 @@
+// __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z)
+//                  a2             a3  a4 a5 a6 a7 [sp] [sp+4]
+
+// syscall(nr, u, v, w, x, y, z)
+//         a2  a6 a3 a4 a5 a8 a9
+
+.global __cp_begin
+.hidden __cp_begin
+.global __cp_end
+.hidden __cp_end
+.global __cp_cancel
+.hidden __cp_cancel
+.hidden __cancel
+.global __syscall_cp_asm
+.hidden __syscall_cp_asm
+.type __syscall_cp_asm,%function
+.align 4
+__syscall_cp_asm:
+	entry	a1, 16
+__cp_begin:
+	l32i	a2, a2, 0
+	bnez	a2, __cp_cancel
+	mov	a2, a4
+	mov	a4, a6
+	mov	a6, a2
+	mov	a2, a3
+	mov	a3, a5
+	mov	a5, a7
+	l32i	a8, a1, 16
+	l32i	a9, a1, 20
+	syscall
+__cp_end:
+	retw
+__cp_cancel:
+	call4	__cancel
+	mov	a2, a6
+	retw
-- 
2.1.4