1 | ! This is the Modula-2 run-time start-off routine. It's job is to take the
|
---|
2 | ! arguments as put on the stack by EXEC, and to parse them and set them up the
|
---|
3 | ! way _m_a_i_n expects them.
|
---|
4 |
|
---|
5 | .extern __m_a_i_n, _exit, m2rtso, hol0, __penvp
|
---|
6 | .extern begtext, begdata, begbss, endtext, enddata, endbss
|
---|
7 | .text
|
---|
8 | begtext:
|
---|
9 | m2rtso:
|
---|
10 | xor bp, bp ! clear for backtrace of core files
|
---|
11 | mov bx, sp
|
---|
12 | mov ax, (bx) ! argc
|
---|
13 | lea dx, 2(bx) ! argv
|
---|
14 | lea cx, 4(bx)
|
---|
15 | add cx, ax
|
---|
16 | add cx, ax ! envp
|
---|
17 |
|
---|
18 | ! Test if environ is in the initialized data area and is set to our
|
---|
19 | ! magic number. If so then it is not redefined by the user.
|
---|
20 | mov bx, #_environ
|
---|
21 | cmp bx, #__edata ! within initialized data?
|
---|
22 | jae 0f
|
---|
23 | testb bl, #1 ! aligned?
|
---|
24 | jnz 0f
|
---|
25 | cmp (bx), #0x5353 ! is it our environ?
|
---|
26 | jne 0f
|
---|
27 | mov __penviron, bx ! _penviron = &environ;
|
---|
28 | 0: mov bx, __penviron
|
---|
29 | mov (bx), cx ! *_penviron = envp;
|
---|
30 |
|
---|
31 | push cx ! push envp
|
---|
32 | push dx ! push argv
|
---|
33 | push ax ! push argc
|
---|
34 |
|
---|
35 | call __m_a_i_n ! run Modula-2 program
|
---|
36 |
|
---|
37 | push ax ! push exit status
|
---|
38 | call __exit
|
---|
39 |
|
---|
40 | hlt ! force a trap if exit fails
|
---|
41 |
|
---|
42 | .data
|
---|
43 | begdata:
|
---|
44 | .data2 0 ! for sep I&D: *NULL == 0
|
---|
45 | __penviron:
|
---|
46 | .data2 __penvp ! Pointer to environ, or hidden pointer
|
---|
47 |
|
---|
48 | .bss
|
---|
49 | begbss:
|
---|
50 | .comm __penvp, 2 ! Hidden environment vector
|
---|