     1                                  ; ****************************************************************************
     2                                  ; hello.s (Retro Unix 386 v1 - sample binary file)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; RETRO UNIX 386 (Retro Unix == Turkish Rational Unix)
     6                                  ; Operating System Project (v0.2) by ERDOGAN TAN (Beginning: 24/12/2013)
     7                                  ;
     8                                  ; Retro UNIX 8086 v1 - 'hello' file for '/bin/sh' test
     9                                  ;
    10                                  ; Derived from 'Retro UNIX 8086 v1' source code by Erdogan Tan
    11                                  ; (v0.1 - Beginning: 11/07/2012)
    12                                  ;
    13                                  ; [ Last Modification: 03/09/2015 ]
    14                                  ;
    15                                  ; Derived from UNIX Operating System (v1.0 for PDP-11) 
    16                                  ; (Original) Source Code by Ken Thompson (Bell Laboratories, 1971-1972)
    17                                  ; ****************************************************************************
    18                                  ;
    19                                  ; hello.s (28/08/2015, Retro UNIX 386 v1, NASM 2.11, 32 bit version)
    20                                  ; HELLO.ASM, 18/11/2013 (Retro UNIX 8086 v1, MASM 6.11) 
    21                                  
    22                                  ; 03/09/2015
    23                                  ; 28/08/2015
    24                                  ; 18/11/2013
    25                                  
    26                                  ; UNIX v1 system calls
    27                                  _rele 	equ 0
    28                                  _exit 	equ 1
    29                                  _fork 	equ 2
    30                                  _read 	equ 3
    31                                  _write	equ 4
    32                                  _open	equ 5
    33                                  _close 	equ 6
    34                                  _wait 	equ 7
    35                                  _creat 	equ 8
    36                                  _link 	equ 9
    37                                  _unlink	equ 10
    38                                  _exec	equ 11
    39                                  _chdir	equ 12
    40                                  _time 	equ 13
    41                                  _mkdir 	equ 14
    42                                  _chmod	equ 15
    43                                  _chown	equ 16
    44                                  _break	equ 17
    45                                  _stat	equ 18
    46                                  _seek	equ 19
    47                                  _tell 	equ 20
    48                                  _mount	equ 21
    49                                  _umount	equ 22
    50                                  _setuid	equ 23
    51                                  _getuid	equ 24
    52                                  _stime	equ 25
    53                                  _quit	equ 26	
    54                                  _intr	equ 27
    55                                  _fstat	equ 28
    56                                  _emt 	equ 29
    57                                  _mdate 	equ 30
    58                                  _stty 	equ 31
    59                                  _gtty	equ 32
    60                                  _ilgins	equ 33
    61                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    62                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    63                                  
    64                                  %macro sys 1-4
    65                                      ; 03/09/2015	
    66                                      ; 13/04/2015
    67                                      ; Retro UNIX 386 v1 system call.		
    68                                      %if %0 >= 2   
    69                                          mov ebx, %2
    70                                          %if %0 >= 3    
    71                                              mov ecx, %3
    72                                              %if %0 = 4
    73                                                 mov edx, %4   
    74                                              %endif
    75                                          %endif
    76                                      %endif
    77                                      mov eax, %1
    78                                      int 30h	   
    79                                  %endmacro
    80                                  
    81                                  ; Retro UNIX 386 v1 system call format:
    82                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    83                                  
    84                                  [BITS 32] ; We need 32-bit intructions for protected mode
    85                                  
    86                                  [ORG 0] 
    87                                  
    88                                  START_CODE:
    89                                  	sys	_write, 1, msg_Hello, msg_size
    90                              <1> 
    91                              <1> 
    92                              <1> 
    93                              <1>  %if %0 >= 2
    94 00000000 BB01000000          <1>  mov ebx, %2
    95                              <1>  %if %0 >= 3
    96 00000005 B9[1F000000]        <1>  mov ecx, %3
    97                              <1>  %if %0 = 4
    98 0000000A BA0F000000          <1>  mov edx, %4
    99                              <1>  %endif
   100                              <1>  %endif
   101                              <1>  %endif
   102 0000000F B804000000          <1>  mov eax, %1
   103 00000014 CD30                <1>  int 30h
   104                                  	sys 	_exit
   105                              <1> 
   106                              <1> 
   107                              <1> 
   108                              <1>  %if %0 >= 2
   109                              <1>  mov ebx, %2
   110                              <1>  %if %0 >= 3
   111                              <1>  mov ecx, %3
   112                              <1>  %if %0 = 4
   113                              <1>  mov edx, %4
   114                              <1>  %endif
   115                              <1>  %endif
   116                              <1>  %endif
   117 00000016 B801000000          <1>  mov eax, %1
   118 0000001B CD30                <1>  int 30h
   119                                  here:
   120 0000001D EBFE                    	jmp	short here
   121                                  
   122                                  ;-----------------------------------------------------------------
   123                                  ;  message
   124                                  ;-----------------------------------------------------------------
   125                                  
   126 0000001F 0D0A                    msg_Hello:	db 0Dh, 0Ah
   127 00000021 48656C6C6F20776F72-     		db 'Hello world !'
   128 0000002A 6C642021           
   129                                  		;db 0Dh, 0Ah
   130                                  msg_size equ    $ - msg_Hello
   131                                  		;db 0
