kaem: scaffold/main.kaem.
This commit is contained in:
parent
9e0858bb57
commit
ac297d36db
|
@ -52,21 +52,20 @@
|
||||||
!/lib/tests/*/*.exit
|
!/lib/tests/*/*.exit
|
||||||
!/lib/tests/*/*.stdout
|
!/lib/tests/*/*.stdout
|
||||||
|
|
||||||
|
/scaffold/*.M1
|
||||||
|
/scaffold/*.m2
|
||||||
|
/scaffold/*.hex2
|
||||||
/scaffold/argv
|
/scaffold/argv
|
||||||
/scaffold/hello
|
/scaffold/hello
|
||||||
/scaffold/main
|
/scaffold/main
|
||||||
/scaffold/micro-mes
|
/scaffold/micro-mes
|
||||||
/scaffold/tiny-mes
|
/scaffold/tiny-mes
|
||||||
|
|
||||||
/scaffold/x86-mes-*
|
/scaffold/argv-m2
|
||||||
/scaffold/x86_64-mes-*
|
/scaffold/hello-m2
|
||||||
|
/scaffold/main-m2
|
||||||
/scaffold/tests/x86-mes-*
|
/scaffold/micro-mes-m2
|
||||||
/scaffold/tests/[0-9a][0-9a-z]-*
|
/scaffold/tiny-mes-m2
|
||||||
/scaffold/tests/t.*
|
|
||||||
!/scaffold/tests/*.c
|
|
||||||
!/scaffold/tests/*.exit
|
|
||||||
!/scaffold/tests/*.stdout
|
|
||||||
|
|
||||||
/src/mes
|
/src/mes
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
:_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
|
||||||
|
movzbl_(%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
|
||||||
|
movzbl_(%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
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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 ()
|
||||||
|
{
|
||||||
|
asm ("mov____$i8,%eax !0");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL___stdin");
|
||||||
|
|
||||||
|
asm ("mov____$i8,%eax !1");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL___stdout");
|
||||||
|
|
||||||
|
asm ("mov____$i8,%eax !2");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL___stderr");
|
||||||
|
|
||||||
|
asm ("mov____%ebp,%eax");
|
||||||
|
asm ("add____$i8,%eax !4");
|
||||||
|
|
||||||
|
asm ("movzbl_(%eax),%eax");
|
||||||
|
asm ("add____$i8,%eax !3");
|
||||||
|
|
||||||
|
asm ("shl____$i8,%eax !0x02");
|
||||||
|
asm ("add____%ebp,%eax");
|
||||||
|
asm ("mov____%eax,0x32 &GLOBAL_environ");
|
||||||
|
asm ("push___%eax");
|
||||||
|
|
||||||
|
asm ("mov____%ebp,%eax");
|
||||||
|
asm ("add____$i8,%eax !8");
|
||||||
|
asm ("push___%eax");
|
||||||
|
|
||||||
|
asm ("mov____%ebp,%eax");
|
||||||
|
asm ("add____$i8,%eax !4");
|
||||||
|
asm ("movzbl_(%eax),%eax");
|
||||||
|
asm ("push___%eax");
|
||||||
|
main ();
|
||||||
|
|
||||||
|
asm ("mov____%eax,%ebx");
|
||||||
|
asm ("mov____$i32,%eax %1");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
asm ("hlt");
|
||||||
|
}
|
||||||
|
*/
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
_exit ()
|
||||||
|
{
|
||||||
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
|
asm ("mov____0x8(%ebp),%ebx !-4");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
|
@ -18,8 +18,6 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int __stderr;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
eputs (char *s)
|
eputs (char *s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -18,4 +18,21 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int write (int fd, char *s, int length);
|
#include <mes/lib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int errno;
|
||||||
|
|
||||||
|
int
|
||||||
|
write (int filedes, void *buffer, int size)
|
||||||
|
{
|
||||||
|
int r = _write (filedes, buffer, size);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
## Copyright (C) 2017 Jeremiah Orians
|
||||||
|
## 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE ADD_IMMEDIATE_to_eax 81C0
|
||||||
|
DEFINE ADD_IMMEDIATE_to_ebp 81C5
|
||||||
|
DEFINE ADD_eax_to_ebx 01C3
|
||||||
|
DEFINE ADD_ebp_to_eax 01E8
|
||||||
|
DEFINE ADD_ebx_to_eax 01D8
|
||||||
|
DEFINE AND_eax_ebx 21D8
|
||||||
|
DEFINE CALL_IMMEDIATE E8
|
||||||
|
DEFINE CALL_eax FFD0
|
||||||
|
DEFINE CMP 39C3
|
||||||
|
DEFINE COPY_eax_to_ebx 89C3
|
||||||
|
DEFINE COPY_eax_to_ecx 89C1
|
||||||
|
DEFINE COPY_ebp_to_eax 89E8
|
||||||
|
DEFINE COPY_ebx_to_eax 89D8
|
||||||
|
DEFINE COPY_ebx_to_edx 89DA
|
||||||
|
DEFINE COPY_ecx_to_ebp 89CD
|
||||||
|
DEFINE COPY_edi_to_ebp 89fd
|
||||||
|
DEFINE COPY_esp_to_ebp 89E5
|
||||||
|
DEFINE COPY_esp_to_ecx 89E1
|
||||||
|
DEFINE COPY_esp_to_edi 89E7
|
||||||
|
DEFINE DIVIDE_eax_by_ebx_into_eax F7FB
|
||||||
|
DEFINE INT_80 CD80
|
||||||
|
DEFINE JUMP E9
|
||||||
|
DEFINE JUMP_EQ 0F84
|
||||||
|
DEFINE JUMP_NE 0F85
|
||||||
|
DEFINE JUMP_EQ8 74
|
||||||
|
DEFINE JUMP_NE8 75
|
||||||
|
DEFINE LOAD_BASE_ADDRESS_eax 8D85
|
||||||
|
DEFINE LOAD_BYTE 0FBE00
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS 8D8424
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS_ebx 8D9C24
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS_ecx 8D8C24
|
||||||
|
DEFINE LOAD_EFFECTIVE_ADDRESS_edx 8D9424
|
||||||
|
DEFINE LOAD_ESP_IMMEDIATE_into_eax 8B8424
|
||||||
|
DEFINE LOAD_IMMEDIATE_eax B8
|
||||||
|
DEFINE LOAD_IMMEDIATE_ebx BB
|
||||||
|
DEFINE LOAD_IMMEDIATE_edx BA
|
||||||
|
DEFINE LOAD_INTEGER 8B00
|
||||||
|
DEFINE LOAD_INTEGER_ebx 8B1B
|
||||||
|
DEFINE LOAD_INTEGER_ecx 8B09
|
||||||
|
DEFINE LOAD_INTEGER_edx 8B12
|
||||||
|
DEFINE MODULUS_eax_from_ebx_into_ebx F7FB
|
||||||
|
DEFINE MOVEZBL 0FB6C0
|
||||||
|
DEFINE MOVE_ebx_to_eax 89D8
|
||||||
|
DEFINE MOVE_ecx_to_eax 89C8
|
||||||
|
DEFINE MOVE_edx_to_eax 89D0
|
||||||
|
DEFINE MULTIPLY_eax_by_ebx_into_eax F7E3
|
||||||
|
DEFINE NOP 00000000
|
||||||
|
DEFINE NOT_eax F7D0
|
||||||
|
DEFINE OR_eax_ebx 09D8
|
||||||
|
DEFINE POP_eax 58
|
||||||
|
DEFINE POP_ebx 5B
|
||||||
|
DEFINE POP_ebp 5D
|
||||||
|
DEFINE POP_edi 5F
|
||||||
|
DEFINE PUSH_eax 50
|
||||||
|
DEFINE PUSH_ebx 53
|
||||||
|
DEFINE PUSH_ebp 55
|
||||||
|
DEFINE PUSH_edi 57
|
||||||
|
DEFINE RETURN C3
|
||||||
|
DEFINE SAL_eax_Immediate8 C1E0
|
||||||
|
DEFINE SAL_eax_cl D3E0
|
||||||
|
DEFINE SAR_eax_cl D3F8
|
||||||
|
DEFINE SETE 0F94C0
|
||||||
|
DEFINE SETLE 0F9EC0
|
||||||
|
DEFINE SETL 0F9CC0
|
||||||
|
DEFINE SETGE 0F9DC0
|
||||||
|
DEFINE SETG 0F9FC0
|
||||||
|
DEFINE SETNE 0F95C0
|
||||||
|
DEFINE STORE_CHAR 8803
|
||||||
|
DEFINE STORE_INTEGER 8903
|
||||||
|
DEFINE SUBTRACT_eax_from_ebx_into_ebx 29C3
|
||||||
|
DEFINE TEST 85C0
|
||||||
|
DEFINE XCHG_eax_ebx 93
|
||||||
|
DEFINE XOR_ebx_eax_into_eax 31D8
|
|
@ -21,7 +21,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
eputs ("Hello, Mescc!\n");
|
eputs ("Hello, Mescc!\n");
|
||||||
return 42;
|
return 42;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -18,11 +18,8 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//V=2 CC32=i686-unknown-linux-gnu-gcc build-aux/cc32-mes.sh scaffold/main
|
|
||||||
//V=2 CC64=gcc build-aux/cc64-mes.sh scaffold/main
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
argc = 42;
|
argc = 42;
|
||||||
return argc;
|
return argc;
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Copyright (C) 2019 Jeremiah Orians <jeremiah@pdp10.guru>
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# kaem --verbose --strict --file scaffold/main.kaem
|
||||||
|
# scaffold/main-m2
|
||||||
|
|
||||||
|
M2-Planet \
|
||||||
|
--debug \
|
||||||
|
--architecture x86 \
|
||||||
|
-f lib/linux/x86-mes-m2/crt1.c \
|
||||||
|
-f scaffold/main.c \
|
||||||
|
-o scaffold/main.M1
|
||||||
|
|
||||||
|
blood-elf -f scaffold/main.M1 -o scaffold/main.blood-elf-M1
|
||||||
|
|
||||||
|
M1 \
|
||||||
|
--LittleEndian \
|
||||||
|
--architecture x86 \
|
||||||
|
-f lib/m2/x86/x86_defs.M1 \
|
||||||
|
-f lib/x86-mes/x86.M1 \
|
||||||
|
-f lib/linux/x86-mes-m2/crt1.M1 \
|
||||||
|
-f scaffold/main.M1 \
|
||||||
|
-f scaffold/main.blood-elf-M1 \
|
||||||
|
-o scaffold/main.hex2
|
||||||
|
|
||||||
|
hex2 \
|
||||||
|
--LittleEndian \
|
||||||
|
--architecture x86 \
|
||||||
|
--BaseAddress 0x1000000 \
|
||||||
|
--exec_enable \
|
||||||
|
-f lib/x86-mes/elf32-header.hex2 \
|
||||||
|
-f scaffold/main.hex2 \
|
||||||
|
-o scaffold/main-m2
|
||||||
|
|
||||||
|
echo Now run: scaffold/main-m2
|
Loading…
Reference in New Issue