libk  Check-in [62fd1bfe97]

Overview
Comment:Fix _start to properly find the environment. The arguments and environment are directly on the initial stack, which means that more work is needed to find the start of the environment properly. Also remove the hack in _boot that made it work if there were no arguments, as all of the math is being done in _start now.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 62fd1bfe97dfd2f741f8c43d1c888577661c1913d55113f0f050ba7fe433e7cb
User & Date: glowpelt on 2020-01-05 17:52:15
Other Links: manifest | tags
Context
2020-01-19
04:12
Partially fix shared library build by making sure that data_objects are linked in. This means that internal.ident.o is properly linked in, but internal.ident.o itself still references undefined symbols, so this is only a partial fix. check-in: 0d71b71cc8 user: glowpelt tags: trunk
2020-01-05
17:52
Fix _start to properly find the environment. The arguments and environment are directly on the initial stack, which means that more work is needed to find the start of the environment properly. Also remove the hack in _boot that made it work if there were no arguments, as all of the math is being done in _start now. check-in: 62fd1bfe97 user: glowpelt tags: trunk
2019-11-19
05:34
add freebsd signal numbers check-in: de2d78ff77 user: lexi tags: trunk
Changes

Modified mod/kcore/boot.rt.c from [a8282db34a] to [298efe4468].

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
unsigned long long
_boot(unsigned int argc, /* argument count */
		const char** argv, /* arguments */
		char** envp /* environment */ ) {

	_k_internal_binary_name = argv[0];

	envp ++; /* envp seems to point at a leading null;
				this is probably a sign of breakage but
				i don't know what else to do about it for
				the moment. */

	char** ep;
	/* advance ep until it points at the last element */
	for (ep = envp; *ep != 0; ++ep);

	/* allocate space for each environment variable */
	kvar variables [ep - envp];








<
<
<
<
<







7
8
9
10
11
12
13





14
15
16
17
18
19
20
unsigned long long
_boot(unsigned int argc, /* argument count */
		const char** argv, /* arguments */
		char** envp /* environment */ ) {

	_k_internal_binary_name = argv[0];






	char** ep;
	/* advance ep until it points at the last element */
	for (ep = envp; *ep != 0; ++ep);

	/* allocate space for each environment variable */
	kvar variables [ep - envp];

Modified mod/kcore/boot.rt.x86.lin.64.s from [a74c88489c] to [78d762a0b4].

19
20
21
22
23
24
25
26


27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
42




43
44
45
46
47
48
49
	mov edi, [rsp + 0] ; sizeof arguments
	; first argument to _boot(): argc
	; this is a 32-bit signed(??) integer
	; that is equal to the number of
	; elements in argv (see below). it is
	; not strictly necessary, because argv
	; is per spec always null-terminated,
	; but we pass it just in case.



	lea rsi, [rsp + 8] ; &arguments
	; 2nd argument to _boot(): ptr to argv
	; this points to an array of strings
	; containing the program's command line
	; arguments. _boot() does not need to 
	; parse this, but it does need to store
	; it in the structure passed to main()



	lea rdx, [rsp + 16] ; &environment
	; third argument to _boot(): ptr to envp
	; this points to the list of environment
	; variables for the running program. it
	; is the responsibility of _boot to parse
	; this list and arrange it into a set of
	; legible and useful C arrays.





	mov rax, 0 ; zero out %rax
	; this is required by the C ABI, and is
	; reputedly necessary for compatibility
	; with icc, intel's own proprietary C
	; compiler.








|
>
>








>
>

|





|
>
>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
	mov edi, [rsp + 0] ; sizeof arguments
	; first argument to _boot(): argc
	; this is a 32-bit signed(??) integer
	; that is equal to the number of
	; elements in argv (see below). it is
	; not strictly necessary, because argv
	; is per spec always null-terminated,
	; but we pass it just in case. it is
	; also used for finding the environment
	; below.

	lea rsi, [rsp + 8] ; &arguments
	; 2nd argument to _boot(): ptr to argv
	; this points to an array of strings
	; containing the program's command line
	; arguments. _boot() does not need to 
	; parse this, but it does need to store
	; it in the structure passed to main()
	; this exists on the stack, right above
	; argc

	lea rdx, [rsp + rdi * 8 + 16] ; &environment
	; third argument to _boot(): ptr to envp
	; this points to the list of environment
	; variables for the running program. it
	; is the responsibility of _boot to parse
	; this list and arrange it into a set of
	; legible and useful C arrays. it exists
	; above the argument list, the math is
	; stack pointer + argc*pointers(8 bytes)
	; + 16 bytes (argc itself and the
	; terminating null from argv)

	mov rax, 0 ; zero out %rax
	; this is required by the C ABI, and is
	; reputedly necessary for compatibility
	; with icc, intel's own proprietary C
	; compiler.