Updated magenta crt init
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef SYS_LINUX___FIO_H_
|
||||
#define SYS_LINUX___FIO_H_
|
||||
#ifndef SYS_MAGENTA___FIO_H_
|
||||
#define SYS_MAGENTA___FIO_H_
|
||||
|
||||
#include <magenta.h>
|
||||
|
||||
@@ -11,12 +11,13 @@ extern "C" {
|
||||
|
||||
struct __io_file {
|
||||
char buf[__FIO_BUFSZ];
|
||||
unsigned int buf_idx;
|
||||
unsigned long buf_idx;
|
||||
mx_handle_t handle;
|
||||
char err;
|
||||
};
|
||||
|
||||
extern int __fileno(struct __io_file *f);
|
||||
extern void __fio_init(mx_handle_t in, mx_handle_t out, mx_handle_t err);
|
||||
extern unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz);
|
||||
extern unsigned int __fio_flush(struct __io_file *f);
|
||||
extern int __fio_error(struct __io_file *f);
|
||||
|
||||
@@ -10,13 +10,16 @@ struct __io_file *stdin = &__stdin;
|
||||
struct __io_file *stdout = &__stdout;
|
||||
struct __io_file *stderr = &__stderr;
|
||||
|
||||
void __fio_init()
|
||||
void __fio_init(mx_handle_t in, mx_handle_t out, mx_handle_t err)
|
||||
{
|
||||
__stdin.handle = in;
|
||||
__stdout.handle = out;
|
||||
__stderr.handle = err;
|
||||
}
|
||||
|
||||
int __fileno(struct __io_file *f)
|
||||
{
|
||||
return 0;
|
||||
return (int)f->handle;
|
||||
}
|
||||
|
||||
unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
|
||||
@@ -37,8 +40,9 @@ unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
|
||||
|
||||
unsigned int __fio_flush(struct __io_file *f)
|
||||
{
|
||||
ssize_t res = 0;//write(f->fd, f->buf, f->buf_idx);
|
||||
if ((size_t)res != f->buf_idx) {
|
||||
unsigned long written = 0;
|
||||
mx_status_t ret = mx_write(f->handle, f->buf_idx, f->buf, &written);
|
||||
if (ret != MX_OK || written != f->buf_idx) {
|
||||
f->err = 1;
|
||||
}
|
||||
|
||||
|
||||
10
photon/libc/sys/magenta/init.c
Normal file
10
photon/libc/sys/magenta/init.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "init.h"
|
||||
#include "__fio.h"
|
||||
|
||||
extern int main(int, const char **);
|
||||
|
||||
int __crt_init(struct __proc_start_info *info)
|
||||
{
|
||||
__fio_init(info->in, info->out, info->err);
|
||||
return main(info->argc, info->argv);
|
||||
}
|
||||
14
photon/libc/sys/magenta/init.h
Normal file
14
photon/libc/sys/magenta/init.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef SYS_MAGENTA_INIT_H_
|
||||
#define SYS_MAGENTA_INIT_H_
|
||||
|
||||
#include <magenta.h>
|
||||
|
||||
struct __proc_start_info {
|
||||
mx_handle_t in;
|
||||
mx_handle_t out;
|
||||
mx_handle_t err;
|
||||
int argc;
|
||||
const char **argv;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,19 +1,17 @@
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
.extern __fio_init
|
||||
.type __fio_init, @function
|
||||
.extern __crt_init
|
||||
.type __crt_init, @function
|
||||
|
||||
.extern main
|
||||
.type main, @function
|
||||
|
||||
_start:
|
||||
pop %rbp
|
||||
pop %rdi
|
||||
mov %rsp, %rsi
|
||||
andq $-16, %rsp
|
||||
call __fio_init
|
||||
call main
|
||||
call __crt_init
|
||||
movq %rax, %rdi
|
||||
movq $60, %rax
|
||||
syscall
|
||||
|
||||
Reference in New Issue
Block a user