From 6297f36d4a6285b9c8c3dde8541d55c5bcc6ca26 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Wed, 15 Jul 2020 19:25:16 +0200 Subject: [PATCH] kaem: scaffold/main.kaem. * lib/linux/x86-mes-m2/crt1.c, lib/linux/x86-mes-m2/crt1.M1, lib/linux/x86-mes-m2/_exit.c, lib/linux/x86-mes-m2/_write.c: New files. * lib/m2/x86/x86_defs.M1: New file. Import from stage0. * lib/m2/x86/ELF-x86.hex2: New file. Import from M2-Planet. * scaffold/main.c: Update for M2-Planet. * scaffold/main.kaem: New file. * .gitignore: Update. --- .gitignore | 13 +++-- lib/linux/x86-mes-m2/_exit.c | 27 +++++++++++ lib/linux/x86-mes-m2/_write.c | 29 +++++++++++ lib/linux/x86-mes-m2/crt1.M1 | 52 ++++++++++++++++++++ lib/linux/x86-mes-m2/crt1.c | 34 +++++++++++++ lib/m2/x86/ELF-x86.hex2 | 74 ++++++++++++++++++++++++++++ lib/m2/x86/x86_defs.M1 | 90 +++++++++++++++++++++++++++++++++++ scaffold/hello.c | 2 +- scaffold/main.c | 7 +-- scaffold/main.kaem | 53 +++++++++++++++++++++ 10 files changed, 370 insertions(+), 11 deletions(-) create mode 100644 lib/linux/x86-mes-m2/_exit.c create mode 100644 lib/linux/x86-mes-m2/_write.c create mode 100644 lib/linux/x86-mes-m2/crt1.M1 create mode 100644 lib/linux/x86-mes-m2/crt1.c create mode 100644 lib/m2/x86/ELF-x86.hex2 create mode 100644 lib/m2/x86/x86_defs.M1 create mode 100644 scaffold/main.kaem diff --git a/.gitignore b/.gitignore index e4ff6828..017b7400 100644 --- a/.gitignore +++ b/.gitignore @@ -51,17 +51,20 @@ !/lib/tests/*/*.exit !/lib/tests/*/*.stdout +/scaffold/*.M1 +/scaffold/*.m2 +/scaffold/*.hex2 /scaffold/argv /scaffold/hello /scaffold/main /scaffold/micro-mes /scaffold/tiny-mes -/scaffold/tests/[0-9a][0-9a-z]-* -/scaffold/tests/t.* -!/scaffold/tests/*.c -!/scaffold/tests/*.exit -!/scaffold/tests/*.stdout +/scaffold/argv-m2 +/scaffold/hello-m2 +/scaffold/main-m2 +/scaffold/micro-mes-m2 +/scaffold/tiny-mes-m2 /.config.make /.store diff --git a/lib/linux/x86-mes-m2/_exit.c b/lib/linux/x86-mes-m2/_exit.c new file mode 100644 index 00000000..69a4b750 --- /dev/null +++ b/lib/linux/x86-mes-m2/_exit.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2019,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +void +_exit () +{ + asm ("mov____$i32,%eax SYS_exit"); + asm ("mov____0x8(%ebp),%ebx !-4"); + asm ("int____$0x80"); +} diff --git a/lib/linux/x86-mes-m2/_write.c b/lib/linux/x86-mes-m2/_write.c new file mode 100644 index 00000000..1f9ae1ac --- /dev/null +++ b/lib/linux/x86-mes-m2/_write.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2019,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +void +_write (int filedes, void *buffer, int size) +{ + asm ("mov____$i32,%eax SYS_write"); + asm ("mov____0x8(%ebp),%ebx !-4"); + asm ("mov____0x8(%ebp),%ecx !-8"); + asm ("mov____0x8(%ebp),%edx !-12"); + asm ("int____$0x80"); +} diff --git a/lib/linux/x86-mes-m2/crt1.M1 b/lib/linux/x86-mes-m2/crt1.M1 new file mode 100644 index 00000000..4354fb29 --- /dev/null +++ b/lib/linux/x86-mes-m2/crt1.M1 @@ -0,0 +1,52 @@ +### GNU Mes --- Maxwell Equations of Software +### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen +### +### This file is part of GNU Mes. +### +### GNU Mes is free software; you can redistribute it and/or modify it +### under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 3 of the License, or (at +### your option) any later version. +### +### GNU Mes is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with GNU Mes. If not, see . + +:_start + push___%ebp + mov____%esp,%ebp + sub____$i32,%esp %0x1054 + mov____$i8,%eax !0 + mov____%eax,0x32 &GLOBAL___stdin + mov____$i8,%eax !1 + mov____%eax,0x32 &GLOBAL___stdout + mov____$i8,%eax !2 + mov____%eax,0x32 &GLOBAL___stderr + mov____%ebp,%eax + add____$i8,%eax !4 + mov____(%eax),%eax + add____$i8,%eax !3 + shl____$i8,%eax !0x02 + add____%ebp,%eax + mov____%eax,0x32 &GLOBAL_environ + push___%eax + mov____%ebp,%eax + add____$i8,%eax !8 + push___%eax + mov____%ebp,%eax + add____$i8,%eax !4 + mov____(%eax),%eax + push___%eax + call32 %FUNCTION_main + add____$i8,%esp !0x0 + test___%eax,%eax + mov____%eax,%ebx + mov____$i32,%eax %1 + int____$0x80 + hlt + leave + ret diff --git a/lib/linux/x86-mes-m2/crt1.c b/lib/linux/x86-mes-m2/crt1.c new file mode 100644 index 00000000..1f8fb0ab --- /dev/null +++ b/lib/linux/x86-mes-m2/crt1.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include "mes/lib-mini.h" + +int __stdin; +int __stdout; +int __stderr; +char **environ; +int main (int argc, char **argv, char **envp); + +/* FIXME: this is going to be called `FUNCTION__start' */ +//#int +//#_start () +//#{ +//# .. +//#} diff --git a/lib/m2/x86/ELF-x86.hex2 b/lib/m2/x86/ELF-x86.hex2 new file mode 100644 index 00000000..cfb16487 --- /dev/null +++ b/lib/m2/x86/ELF-x86.hex2 @@ -0,0 +1,74 @@ +### Copyright (C) 2016 Jeremiah Orians +### Copyright (C) 2017 Jan Nieuwenhuizen +### This file is part of M2-Planet. +### +### M2-Planet is free software: you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation, either version 3 of the License, or +### (at your option) any later version. +### +### M2-Planet is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with M2-Planet. If not, see . + +### stage0's hex2 format +### !