source: trunk/minix/lib/i86/rts/ncrtso.s@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1! This is the C 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 _main expects them.
4! It also initializes _environ when this variable isn't defined by the
5! programmer. The detection of whether _environ belong to us is rather
6! simplistic. We simply check for some magic value, but there is no other
7! way.
8
9.extern _main, _exit, crtso, __penviron, __penvp
10.extern begtext, begdata, begbss, endtext, enddata, endbss
11.text
12begtext:
13crtso:
14 xor bp, bp ! clear for backtrace of core files
15 mov bx, sp
16 mov ax, (bx) ! argc
17 lea dx, 2(bx) ! argv
18 lea cx, 4(bx)
19 add cx, ax
20 add cx, ax ! envp
21
22 ! Test if environ is in the initialized data area and is set to our
23 ! magic number. If so then it is not redefined by the user.
24 mov bx, #_environ
25 cmp bx, #__edata ! within initialized data?
26 jae 0f
27 testb bl, #1 ! aligned?
28 jnz 0f
29 cmp (bx), #0x5353 ! is it our environ?
30 jne 0f
31 mov __penviron, bx ! _penviron = &environ;
320: mov bx, __penviron
33 mov (bx), cx ! *_penviron = envp;
34
35 push cx ! push envp
36 push dx ! push argv
37 push ax ! push argc
38
39 call _main ! main(argc, argv, envp)
40
41 push ax ! push exit status
42 call _exit
43
44 hlt ! force a trap if exit fails
45
46.data
47begdata:
48 .data2 0 ! for sep I&D: *NULL == 0
49__penviron:
50 .data2 __penvp ! Pointer to environ, or hidden pointer
51
52.bss
53begbss:
54 .comm __penvp, 2 ! Hidden environment vector
Note: See TracBrowser for help on using the repository browser.