Move generic start code and memset into arch/generic.h
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#if defined(__aarch64__)
|
||||
#include "../int.h"
|
||||
|
||||
#include "generic.h"
|
||||
|
||||
void exit(int8_t status){
|
||||
asm ( "mov x0, %0\n" // Move the exit status into register x0
|
||||
"mov x8, #93\n" // Syscall number for 'exit' is 93 in AArch64
|
||||
|
||||
31
arch/generic.h
Normal file
31
arch/generic.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is not meant to be included by user applications
|
||||
* It contains generic arch agnostic implementations of helper functions
|
||||
* and start code that can be included in <arch>.c when an architecture
|
||||
* specific version is not nessisary.
|
||||
*
|
||||
* Copyright (c) 2025 Lucas Schumacher. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef MEMSET_DEFINED
|
||||
#define MEMSET_DEFINED
|
||||
// Generic memset implementation
|
||||
void *memset(void* s, int c, unsigned long n) {
|
||||
int8_t* mem = s;
|
||||
for(long int i = 0; i < n; ++i) mem[i] = c;
|
||||
return s;
|
||||
}
|
||||
#endif // !MEMSET_DEFINED
|
||||
|
||||
#ifndef _START_DEFINED
|
||||
#define _START_DEFINED
|
||||
// Generic _start implementation. Can't access any args
|
||||
extern void exit(int8_t status);
|
||||
extern int main(int argc, char** argv);
|
||||
void _start() {
|
||||
exit(main(0, 0));
|
||||
}
|
||||
void __start() {
|
||||
exit(main(0, 0));
|
||||
}
|
||||
#endif // !_START_DEFINED
|
||||
@@ -1,6 +1,8 @@
|
||||
#if defined(__mips__)
|
||||
#include "../int.h"
|
||||
|
||||
#include "generic.h"
|
||||
|
||||
void exit(int8_t status){
|
||||
asm (
|
||||
"move $a0, %0\n"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#if defined(__x86_64__)
|
||||
#include "../int.h"
|
||||
|
||||
#include "generic.h"
|
||||
|
||||
#define SYS_EXIT 60
|
||||
void exit(int8_t status) {
|
||||
asm volatile(
|
||||
|
||||
Reference in New Issue
Block a user