Compare commits
3 Commits
0425a92b79
...
415dfd9fa4
| Author | SHA1 | Date | |
|---|---|---|---|
| 415dfd9fa4 | |||
| eadc256d3f | |||
| 459626809a |
5
.gitignore
vendored
5
.gitignore
vendored
@ -2,4 +2,9 @@ print
|
|||||||
print_aarch64
|
print_aarch64
|
||||||
print_mips32
|
print_mips32
|
||||||
print_x64
|
print_x64
|
||||||
|
bldtst
|
||||||
|
bldtst_aarch64
|
||||||
|
bldtst_mips32
|
||||||
|
bldtst_x64
|
||||||
|
bldtst_llvm
|
||||||
a.out
|
a.out
|
||||||
|
|||||||
28
Makefile
28
Makefile
@ -1,12 +1,19 @@
|
|||||||
all: print print_x64 print_aarch64 print_mips32
|
all: print print_x64 print_aarch64 print_mips32 buildtest
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
if test -f print; then rm print; fi
|
if test -f print; then rm print; fi
|
||||||
if test -f print_x64; then rm print_x64; fi
|
if test -f print_x64; then rm print_x64; fi
|
||||||
if test -f print_aarch64; then rm print_aarch64; fi
|
if test -f print_aarch64; then rm print_aarch64; fi
|
||||||
if test -f print_mips32; then rm print_mips32; fi
|
if test -f print_mips32; then rm print_mips32; fi
|
||||||
|
if test -f bldtst; then rm bldtst; fi
|
||||||
|
if test -f bldtst_llvm; then rm bldtst_llvm; fi
|
||||||
|
if test -f bldtst_x64; then rm bldtst_x64; fi
|
||||||
|
if test -f bldtst_aarch64; then rm bldtst_aarch64; fi
|
||||||
|
if test -f bldtst_mips32; then rm bldtst_mips32; fi
|
||||||
|
|
||||||
.PHONY: all clean
|
buildtest: bldtst bldtst_llvm bldtst_x64 bldtst_aarch64 bldtst_mips32
|
||||||
|
|
||||||
|
.PHONY: all buildtest clean
|
||||||
|
|
||||||
print:
|
print:
|
||||||
gcc -static -nostdlib -Wno-builtin-declaration-mismatch -fno-stack-protector -o print print.c
|
gcc -static -nostdlib -Wno-builtin-declaration-mismatch -fno-stack-protector -o print print.c
|
||||||
@ -18,3 +25,20 @@ print_aarch64: print.c
|
|||||||
|
|
||||||
print_mips32: print.c
|
print_mips32: print.c
|
||||||
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -fno-pic -o print_mips32 print.c
|
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -fno-pic -o print_mips32 print.c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bldtst: buildtest.c arch/*.c
|
||||||
|
gcc -static -nostdlib -Wno-builtin-declaration-mismatch -fno-stack-protector -o bldtst buildtest.c arch/*.c
|
||||||
|
|
||||||
|
bldtst_llvm: buildtest.c arch/*.c
|
||||||
|
clang -nostdlib -static -fuse-ld=lld -fno-stack-protector -o bldtst_llvm buildtest.c arch/*.c
|
||||||
|
|
||||||
|
bldtst_x64: buildtest.c arch/x86_64.c
|
||||||
|
clang --target=x86_64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o bldtst_x64 buildtest.c arch/x86_64.c
|
||||||
|
|
||||||
|
bldtst_aarch64: buildtest.c
|
||||||
|
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o bldtst_aarch64 buildtest.c arch/aarch64.c
|
||||||
|
|
||||||
|
bldtst_mips32: buildtest.c
|
||||||
|
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -fno-pic -o bldtst_mips32 buildtest.c arch/mips.c
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#if defined(__aarch64__)
|
#if defined(__aarch64__)
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void exit(int8_t status){
|
void exit(int8_t status){
|
||||||
asm ( "mov x0, %0\n" // Move the exit status into register x0
|
asm ( "mov x0, %0\n" // Move the exit status into register x0
|
||||||
@ -19,7 +20,7 @@ intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
|||||||
"mov x8, #64\n"
|
"mov x8, #64\n"
|
||||||
"svc #0\n"
|
"svc #0\n"
|
||||||
: //TODO: n_written
|
: //TODO: n_written
|
||||||
: "r" (buf), "r"(count), "r"(fd)
|
: "r" (buf), "r"(size), "r"(fd)
|
||||||
: "x0", "x8" // Clobbered registers
|
: "x0", "x8" // Clobbered registers
|
||||||
);
|
);
|
||||||
return n_written;
|
return n_written;
|
||||||
|
|||||||
@ -15,13 +15,13 @@ void exit(int8_t status){
|
|||||||
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
||||||
intptr_t n_written = 0;
|
intptr_t n_written = 0;
|
||||||
asm (
|
asm (
|
||||||
"li $a0, 1\n"
|
"move $a0, %2\n"
|
||||||
"move $a1, %0\n"
|
"move $a1, %0\n"
|
||||||
"move $a2, %1\n"
|
"move $a2, %1\n"
|
||||||
"li $v0, 4004\n"
|
"li $v0, 4004\n"
|
||||||
"syscall\n"
|
"syscall\n"
|
||||||
: //TODO: n_written
|
: //TODO: n_written
|
||||||
: "r"(buf), "r"(count)
|
: "r"(buf), "r"(size), "r"(fd)
|
||||||
: "a0", "a1", "a2", "v0" //TODO: temp registers clobbered by syscall should probably also be listed but this fn returns right away so it should be fine?
|
: "a0", "a1", "a2", "v0" //TODO: temp registers clobbered by syscall should probably also be listed but this fn returns right away so it should be fine?
|
||||||
);
|
);
|
||||||
return n_written;
|
return n_written;
|
||||||
|
|||||||
48
buildtest.c
Normal file
48
buildtest.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include "sys.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if defined(__x86_64__) || defined(__aarch64__) || defined(__mips__)
|
||||||
|
uint64_t pid = fork();
|
||||||
|
char msg[17] = {' '};
|
||||||
|
msg[16] = '\n';
|
||||||
|
for(int i = 0; i < 16; ++i) {
|
||||||
|
char nibble = (pid >> ((15 - i) * 4)) & 0xf;
|
||||||
|
char c;
|
||||||
|
if (nibble > 9) {c = nibble + '7';}
|
||||||
|
else {c = nibble + '0';}
|
||||||
|
msg[i] = c;
|
||||||
|
}
|
||||||
|
write(STDIO, msg, 17);
|
||||||
|
#else
|
||||||
|
char *msg = "Hello World!\n";
|
||||||
|
write(STDIO, msg, 13);
|
||||||
|
#endif
|
||||||
|
return 69;
|
||||||
|
}
|
||||||
|
void __libc_start_main() {exit(main());}
|
||||||
|
|
||||||
|
void _start() {
|
||||||
|
__libc_start_main();
|
||||||
|
}
|
||||||
|
|
||||||
|
void __start() {
|
||||||
|
_start();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
printf("Compiled for x86_64 architecture\n");
|
||||||
|
#elif defined(__i386__)
|
||||||
|
printf("Compiled for x86 architecture\n");
|
||||||
|
#elif defined(__arm__)
|
||||||
|
printf("Compiled for ARM architecture\n");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
printf("Compiled for ARM64 architecture\n");
|
||||||
|
#elif defined(__mips__)
|
||||||
|
printf("Compiled for ARM architecture\n");
|
||||||
|
#else
|
||||||
|
printf("Unknown architecture\n");
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user