## This file was generated by running: ## cat functions/exit.c functions/file.c functions/file_print.c functions/malloc.c functions/calloc.c functions/uname.c test/test24/get_machine.c >| ../stage0/stage3/get_machine_x86.c ## inside M2-Planet's repo ## Copyright (C) 2016 Jeremiah Orians ## This file is part of stage0. ## ## stage0 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. ## ## stage0 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 stage0. If not, see . // CONSTANT EXIT_FAILURE 1 // CONSTANT EXIT_SUCCESS 0 void exit(int value) { asm("POP_ebx" "POP_ebx" "LOAD_IMMEDIATE_eax %1" "INT_80"); } /* Copyright (C) 2016 Jeremiah Orians * This file is part of stage0. * * stage0 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. * * stage0 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 stage0. If not, see . */ // CONSTANT stdin 0 // CONSTANT stdout 1 // CONSTANT stderr 2 // CONSTANT EOF 0xFFFFFFFF int fgetc(FILE* f) { asm("LOAD_IMMEDIATE_eax %3" "LOAD_EFFECTIVE_ADDRESS_ebx %4" "LOAD_INTEGER_ebx" "PUSH_ebx" "COPY_esp_to_ecx" "LOAD_IMMEDIATE_edx %1" "INT_80" "TEST" "POP_eax" "JUMP_NE8 !FUNCTION_fgetc_Done" "LOAD_IMMEDIATE_eax %-1" ":FUNCTION_fgetc_Done"); } void fputc(char s, FILE* f) { asm("LOAD_IMMEDIATE_eax %4" "LOAD_EFFECTIVE_ADDRESS_ebx %4" "LOAD_INTEGER_ebx" "LOAD_EFFECTIVE_ADDRESS_ecx %8" "LOAD_IMMEDIATE_edx %1" "INT_80"); } /* Important values needed for open * O_RDONLY => 0 * O_WRONLY => 1 * O_RDWR => 2 * O_CREAT => 64 * O_TRUNC => 512 * S_IRWXU => 00700 * S_IXUSR => 00100 * S_IWUSR => 00200 * S_IRUSR => 00400 */ FILE* open(char* name, int flag, int mode) { asm("LOAD_EFFECTIVE_ADDRESS_ebx %12" "LOAD_INTEGER_ebx" "LOAD_EFFECTIVE_ADDRESS_ecx %8" "LOAD_INTEGER_ecx" "LOAD_EFFECTIVE_ADDRESS_edx %4" "LOAD_INTEGER_edx" "LOAD_IMMEDIATE_eax %5" "INT_80"); } FILE* fopen(char* filename, char* mode) { FILE* f; if('w' == mode[0]) { /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */ f = open(filename, 577 , 384); } else { /* Everything else is a read */ f = open(filename, 0, 0); } /* Negative numbers are error codes */ if(0 > f) { return 0; } return f; } int close(int fd) { asm("LOAD_EFFECTIVE_ADDRESS_ebx %4" "LOAD_IMMEDIATE_eax %6" "INT_80"); } int fclose(FILE* stream) { int error = close(stream); return error; } /* Copyright (C) 2016 Jeremiah Orians * This file is part of stage0. * * stage0 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. * * stage0 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 stage0. If not, see . */ #include // void fputc(char s, FILE* f); void file_print(char* s, FILE* f) { while(0 != s[0]) { fputc(s[0], f); s = s + 1; } } ## Copyright (C) 2016 Jeremiah Orians ## This file is part of stage0. ## ## stage0 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. ## ## stage0 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 stage0. If not, see . // CONSTANT NULL 0 void* malloc(int size) { asm("STORE_eax_into_ESP_IMMEDIATE8 !4" "PUSH_eax" "LOAD_IMMEDIATE_eax %45" "LOAD_IMMEDIATE_ebx %0" "INT_80" "POP_ebx" "ADD_eax_to_ebx" "PUSH_eax" "PUSH_ebx" "LOAD_IMMEDIATE_eax %45" "INT_80" "POP_ebx" "CMP" "POP_eax" "JUMP_EQ8 !FUNCTION_malloc_Done" "LOAD_IMMEDIATE_eax %-1" ":FUNCTION_malloc_Done"); } /* Copyright (C) 2016 Jeremiah Orians * This file is part of stage0. * * stage0 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. * * stage0 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 stage0. If not, see . */ // void* malloc(int size); void* memset(void* ptr, int value, int num) { char* s; for(s = ptr; 0 < num; num = num - 1) { s[0] = value; s = s + 1; } } void* calloc(int count, int size) { void* ret = malloc(count * size); memset(ret, 0, (count * size)); return ret; } void free(void* l) { return; } /* Copyright (C) 2016 Jeremiah Orians * This file is part of stage0. * * stage0 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. * * stage0 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 stage0. If not, see . */ struct utsname { char** sysname[65]; /* Operating system name (e.g., "Linux") */ char** nodename[65]; /* Name within "some implementation-defined network" */ char** release[65]; /* Operating system release (e.g., "2.6.28") */ char** version[65]; /* Operating system version */ char** machine[65]; /* Hardware identifier */ }; int uname(struct utsname* unameData) { asm("LOAD_EFFECTIVE_ADDRESS_ebx %4" "LOAD_INTEGER_ebx" "LOAD_IMMEDIATE_eax %109" "INT_80"); } /* -*- c-file-style: "linux";indent-tabs-mode:t -*- */ /* Copyright (C) 2017 Jeremiah Orians * This file is part of mescc-tools. * * mescc-tools 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. * * mescc-tools 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 mescc-tools. If not, see . */ #include #include #include void file_print(char* s, FILE* f); /* Standard C main program */ int main() { struct utsname* unameData = calloc(1, sizeof(struct utsname)); uname(unameData); file_print(unameData->machine, stdout); file_print("\n", stdout); return EXIT_SUCCESS; }