Avoid gcc dependency
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
#[link(name = "syscalls")]
|
||||
extern "C" {
|
||||
#[link_name = "_start_window_draw"]
|
||||
pub fn start_window_draw();
|
||||
|
||||
#[link_name = "_end_window_draw"]
|
||||
pub fn end_window_draw();
|
||||
|
||||
#[link_name = "exit0"]
|
||||
#[link_name = "_exit"]
|
||||
pub fn exit() -> !;
|
||||
|
||||
#[link_name = "_define_window"]
|
||||
pub fn define_window(ebx: u32, ecx: u32, edx: u32, edi: u32);
|
||||
#[link_name = "_display_message"]
|
||||
pub fn display_message(ebx: u32, ecx: u32, edx: u32, edi: u32, esi: u32);
|
||||
|
||||
#[link_name = "_wait_event"]
|
||||
pub fn wait_event() -> u32;
|
||||
|
||||
#[link_name = "_pressed_key"]
|
||||
pub fn pressed_key() -> u32;
|
||||
}
|
||||
|
67
src/syscalls.S
Normal file
67
src/syscalls.S
Normal file
@@ -0,0 +1,67 @@
|
||||
BITS 32
|
||||
|
||||
section .text
|
||||
global _exit
|
||||
global _start_window_draw
|
||||
global _end_window_draw
|
||||
global _define_window
|
||||
global _display_message
|
||||
global _wait_event
|
||||
global _pressed_key
|
||||
|
||||
_exit:
|
||||
mov eax, -1
|
||||
int 0x40
|
||||
|
||||
_start_window_draw:
|
||||
mov eax, 0xc
|
||||
mov ebx, 1
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
_end_window_draw:
|
||||
mov eax, 0xc
|
||||
mov ebx, 2
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
_define_window:
|
||||
push edi
|
||||
push ebx
|
||||
xor eax, eax
|
||||
mov ebx, dword [esp + 0x14]
|
||||
mov ecx, dword [esp + 0x18]
|
||||
mov edx, dword [esp + 0x1c]
|
||||
mov edi, dword [esp + 0x20]
|
||||
mov ebx, 2
|
||||
int 0x40
|
||||
pop ebx
|
||||
pop edi
|
||||
ret
|
||||
|
||||
_display_message:
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
mov eax, 4
|
||||
mov ebx, dword [esp + 0x14]
|
||||
mov ecx, dword [esp + 0x18]
|
||||
mov edx, dword [esp + 0x1c]
|
||||
mov esi, dword [esp + 0x20]
|
||||
mov edi, dword [esp + 0x24]
|
||||
mov ebx, 2
|
||||
int 0x40
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
ret
|
||||
|
||||
_wait_event:
|
||||
mov eax, 0xa
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
_pressed_key:
|
||||
mov eax, 2
|
||||
int 0x40
|
||||
ret
|
@@ -1,54 +0,0 @@
|
||||
void start_window_draw() {
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
:: "a"(12), "b"(1)
|
||||
);
|
||||
}
|
||||
|
||||
void end_window_draw() {
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
:: "a"(12), "b"(2)
|
||||
);
|
||||
}
|
||||
|
||||
void exit0() {
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
:: "a"(-1)
|
||||
);
|
||||
}
|
||||
|
||||
void define_window(unsigned ebx, unsigned ecx, unsigned edx, unsigned edi) {
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
:: "a"(0), "b"(ebx), "c"(ecx), "d"(edx), "D"(edi)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
void display_message(unsigned ebx, unsigned ecx, unsigned edx, unsigned edi, unsigned esi) {
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
:: "a"(4), "b"(ebx), "c"(ecx), "d"(edx), "D"(edi), "S"(esi)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
unsigned wait_event() {
|
||||
unsigned res;
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
: "=r"(res) : "a"(10)
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
unsigned pressed_key() {
|
||||
unsigned res;
|
||||
__asm__ volatile (
|
||||
"int $0x40;"
|
||||
: "=r"(res) : "a"(2)
|
||||
);
|
||||
return res;
|
||||
}
|
Reference in New Issue
Block a user