exec_enable_amd64.M1 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_RAX 58
  17. DEFINE POP_RDI 5F
  18. DEFINE CMP_RAX_TO_IMMEDIATE8 4883f8
  19. DEFINE JNE8 75
  20. DEFINE LOADI32_RSI 48C7C6
  21. DEFINE LOADI32_RAX 48C7C0
  22. DEFINE LOADI32_RDI 48C7C7
  23. DEFINE LOADI32_RDX 48C7C2
  24. DEFINE SYSCALL 0F05
  25. :_start
  26. # first check that we got the correct number of inputs
  27. POP_RAX # Get the number of arguments
  28. POP_RDI # Get the program name
  29. POP_RDI # Get the actual argument
  30. # Check if we have the correct number of inputs
  31. CMP_RAX_TO_IMMEDIATE8 !02
  32. # Jump to Bail if the number is not correct
  33. JNE8 !Bail
  34. # Load our preferred mode (0777)
  35. LOADI32_RSI %0x1ff
  36. # Load the syscall number for chmod
  37. LOADI32_RAX %90
  38. # Call the kernel
  39. SYSCALL
  40. :Done
  41. # program completed Successfully
  42. LOADI32_RDI %0 # All is well
  43. LOADI32_RAX %60 # put the exit syscall number in rax
  44. SYSCALL # Call it a good day
  45. :Bail
  46. # first let the user know what was wrong
  47. LOADI32_RDX %0x1a # third argument: message length
  48. LOADI32_RSI &message # second argument: pointer to message to write
  49. LOADI32_RDI %1 # first argument: file handle (stdout)
  50. LOADI32_RAX %1 # system call number (sys_write)
  51. SYSCALL # call kernel
  52. # Second terminate with an error
  53. LOADI32_RDI %1 # there was an error
  54. LOADI32_RAX %60 # put the exit syscall number in eax
  55. SYSCALL # bail out
  56. :message
  57. "needs a proper file name
  58. "
  59. :ELF_end