exec_enable_i386.M1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ## Copyright (C) 2017 Jeremiah Orians
  2. ## This file is part of stage0.
  3. ##
  4. ## stage0 is free software: you can redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## stage0 is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. DEFINE POP_eax 58
  17. DEFINE POP_ebx 5B
  18. DEFINE CMP_EAX_TO_IMMEDIATE8 83F8
  19. DEFINE JNE8 75
  20. DEFINE LOADI32_ECX B9
  21. DEFINE LOADI32_EAX B8
  22. DEFINE LOADI32_EBX BB
  23. DEFINE LOADI32_EDX BA
  24. DEFINE INT_80 CD80
  25. :_start
  26. # first check that we got the correct number of inputs
  27. POP_eax # Get the number of arguments
  28. POP_ebx # Get the program name
  29. POP_ebx # Get the actual argument
  30. # Check if we have the correct number of inputs
  31. CMP_EAX_TO_IMMEDIATE8 !02
  32. # Jump to Bail if the number is not correct
  33. JNE8 !Bail
  34. # Load our preferred mode (0777)
  35. LOADI32_ECX %0x1ff
  36. # Load the syscall number for chmod
  37. LOADI32_EAX %15
  38. # Call the kernel
  39. INT_80
  40. :Done
  41. # program completed Successfully
  42. LOADI32_EBX %0 # All is well
  43. LOADI32_EAX %1 # put the exit syscall number in eax
  44. INT_80 # Call it a good day
  45. :Bail
  46. # first let the user know what was wrong
  47. LOADI32_EDX %0x1a # third argument: message length
  48. LOADI32_ECX &msg # second argument: pointer to message to write
  49. LOADI32_EBX %1 # first argument: file handle (stdout)
  50. LOADI32_EAX %4 # system call number (sys_write)
  51. INT_80 # call kernel
  52. # Second terminate with an error
  53. LOADI32_EBX %1 # there was an error
  54. LOADI32_EAX %1 # put the exit syscall number in eax
  55. INT_80 # bail out
  56. :msg
  57. "needs a proper file name
  58. "
  59. :ELF_end