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
#![deny(warnings)]

#![no_std]

extern crate rlibc;

pub use rlibc::*;

#[cfg(any(target_os="dos", docsrs))]
use core::arch::asm;
#[cfg(any(target_os="dos", docsrs))]
use core::ffi::{c_int, c_char, c_float, c_ulonglong};

#[cfg(any(target_os="dos", docsrs))]
#[no_mangle]
pub extern "C" fn _chkstk() { }

#[cfg(any(target_os="dos", docsrs))]
#[no_mangle]
#[used]
pub static mut _fltused: c_int = 0;

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn strlen(s: *const c_char) -> usize {
    let mut n = s;
    while *n != 0 {
        n = n.offset(1);
    }
    n.offset_from(s) as usize
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub extern "C" fn fminf(x: c_float, y: c_float) -> c_float {
    if x.is_nan() { return y; }
    if y.is_nan() { return x; }
    if x < y { x } else { y }
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn _aulldiv(a: c_ulonglong, b: c_ulonglong) -> c_ulonglong {
    a / b
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn _aullrem(a: c_ulonglong, b: c_ulonglong) -> c_ulonglong {
    a % b
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_load(src: *const usize, _model: c_int) -> usize {
    asm!("cli");
    let dest = *src;
    asm!("sti", "nop");
    dest
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_store(dest: *mut usize, src: usize, _model: c_int) {
    asm!("cli");
    *dest = src;
    asm!("sti", "nop");
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_load_1(src: *const u8, _model: c_int) -> u8 {
    asm!("cli");
    let dest = *src;
    asm!("sti", "nop");
    dest
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_store_1(dest: *mut u8, src: u8, _model: c_int) {
    asm!("cli");
    *dest = src;
    asm!("sti", "nop");
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_load_2(src: *const u16, _model: c_int) -> u16 {
    asm!("cli");
    let dest = *src;
    asm!("sti", "nop");
    dest
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_store_2(dest: *mut u16, src: u16, _model: c_int) {
    asm!("cli");
    *dest = src;
    asm!("sti", "nop");
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_load_4(src: *const u32, _model: c_int) -> u32 {
    asm!("cli");
    let dest = *src;
    asm!("sti", "nop");
    dest
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_store_4(dest: *mut u32, src: u32, _model: c_int) {
    asm!("cli");
    *dest = src;
    asm!("sti", "nop");
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_load_8(src: *const u64, _model: c_int) -> u64 {
    asm!("cli");
    let dest = *src;
    asm!("sti", "nop");
    dest
}

#[cfg(any(target_os="dos", docsrs))]
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn __atomic_store_8(dest: *mut u64, src: u64, _model: c_int) {
    asm!("cli");
    *dest = src;
    asm!("sti", "nop");
}