...
This commit is contained in:
@@ -8,7 +8,7 @@ PointerAlignment: Left
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
|
||||
# Control how short statements are placed
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
|
||||
|
||||
4
src/runtime/.gitignore
vendored
4
src/runtime/.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
out
|
||||
out-int
|
||||
bin
|
||||
bin-int
|
||||
@@ -1,16 +1,16 @@
|
||||
CC ?= x86_64-linux-gnu-gcc
|
||||
TARGET ?= x64
|
||||
|
||||
CFLAGS = -nostdlib -ffreestanding -Wall -Werror -Wextra
|
||||
CFLAGS = -nostdlib -ffreestanding -Wall -Werror -Wextra -g
|
||||
|
||||
libruntime: out-int/runtime.o
|
||||
$(CC) $(CFLAGS) -c targets/$(TARGET).s -o out-int/$(TARGET).o
|
||||
mkdir -p out
|
||||
ar rcs out/libruntime_$(TARGET).a out-int/runtime.o out-int/$(TARGET).o
|
||||
libruntime: bin-int/runtime.o
|
||||
$(CC) $(CFLAGS) -c targets/$(TARGET).s -o bin-int/$(TARGET).o
|
||||
mkdir -p bin
|
||||
ar rcs bin/libruntime_$(TARGET).a bin-int/runtime.o bin-int/$(TARGET).o
|
||||
|
||||
out-int/runtime.o: runtime/runtime.c
|
||||
mkdir -p out-int
|
||||
$(CC) $(CFLAGS) -c runtime/runtime.c -o out-int/runtime.o
|
||||
bin-int/runtime.o: runtime/runtime.c
|
||||
mkdir -p bin-int
|
||||
$(CC) $(CFLAGS) -c runtime/runtime.c -o bin-int/runtime.o
|
||||
|
||||
clean:
|
||||
rm -r out out-int
|
||||
rm -r bin bin-int
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define NUB_PANIC_ERROR_CODE 101
|
||||
|
||||
extern void nub_write_string(const char* str);
|
||||
extern void nub_exit(int code);
|
||||
typedef struct nub_string {
|
||||
uint64_t size;
|
||||
uint8_t buffer[];
|
||||
} nub_string_t;
|
||||
|
||||
uint64_t nub_cstring_length(const char* string)
|
||||
{
|
||||
@@ -14,9 +14,22 @@ uint64_t nub_cstring_length(const char* string)
|
||||
return len;
|
||||
}
|
||||
|
||||
uint64_t nub_string_length()
|
||||
uint64_t nub_string_length(const nub_string_t* string)
|
||||
{
|
||||
return 0;
|
||||
uint64_t count = 0;
|
||||
uint64_t i = 0;
|
||||
|
||||
while (i < string->size) {
|
||||
uint8_t byte = string->buffer[i];
|
||||
|
||||
if ((byte & 0b11000000) != 0b10000000) {
|
||||
count++;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void nub_memcpy(uint8_t* source, uint8_t* destination, uint64_t length)
|
||||
@@ -32,24 +45,3 @@ void nub_memset(uint8_t* destination, uint8_t value, uint64_t count)
|
||||
destination[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void nub_panic_array_oob()
|
||||
{
|
||||
nub_write_string("Array out of bounds\n");
|
||||
nub_exit(NUB_PANIC_ERROR_CODE);
|
||||
}
|
||||
|
||||
void nub_panic_oom()
|
||||
{
|
||||
nub_write_string("Out of memory\n");
|
||||
nub_exit(NUB_PANIC_ERROR_CODE);
|
||||
}
|
||||
|
||||
extern uint64_t main();
|
||||
|
||||
__attribute__((noreturn)) void _start()
|
||||
{
|
||||
uint64_t exit_code = main();
|
||||
nub_exit(exit_code);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
.intel_syntax noprefix
|
||||
|
||||
.text
|
||||
.globl nub_write_string
|
||||
# void nub_write_string(const char* str)
|
||||
nub_write_string:
|
||||
push rdi
|
||||
call nub_cstring_length
|
||||
mov rdx, rax
|
||||
pop rsi
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
syscall
|
||||
|
||||
.text
|
||||
.globl nub_exit
|
||||
# void nub_exit(int code)
|
||||
nub_exit:
|
||||
.globl _start
|
||||
_start:
|
||||
mov rdi, rsp
|
||||
call main
|
||||
mov rax, 60
|
||||
syscall
|
||||
|
||||
Reference in New Issue
Block a user