|
@@ -461,16 +461,14 @@ sig_restorer:
|
461
|
461
|
|
462
|
462
|
;
|
463
|
463
|
; Argument parsing
|
464
|
|
-; TODO : support -r2
|
465
|
464
|
;
|
466
|
465
|
arg_parse:
|
467
|
466
|
; Checking argument count
|
468
|
467
|
mov rax, [rsp]
|
469
|
|
- cmp rax, 3
|
470
|
|
- je parse_r
|
471
|
468
|
cmp rax, 1
|
472
|
469
|
je arg_ok
|
473
|
|
- ; If 1 argument only it can only be -h
|
|
470
|
+ cmp rax, 3
|
|
471
|
+ jle parse_r
|
474
|
472
|
arg_err: ; badval & badarg jmp here too
|
475
|
473
|
mov rax, [rsp+8] ; argv[0] program name
|
476
|
474
|
mov rdi, -1 ; return status
|
|
@@ -481,14 +479,32 @@ arg_parse:
|
481
|
479
|
cmp bl, '-'
|
482
|
480
|
jne badarg
|
483
|
481
|
mov bl, [rax+1]
|
484
|
|
- cmp bl, 'h' ; -h given with another argument
|
|
482
|
+ cmp bl, 'h' ; -h
|
485
|
483
|
je arg_err
|
486
|
484
|
cmp bl, 'r'
|
487
|
485
|
jne badarg
|
488
|
486
|
mov bl, [rax+2]
|
489
|
487
|
cmp bl, 0
|
490
|
|
- ; the 1st argument is -r the second must be a 1 digit integer in [1..8]
|
491
|
|
- mov rax, [rsp+24]
|
|
488
|
+ jne arg_nxt ; the value seems to be just after the -r like -r2
|
|
489
|
+ nxt_arg:
|
|
490
|
+ ; the 1st argument is -r the second must be the time_res
|
|
491
|
+ ; check that the arg exists
|
|
492
|
+ mov rax, [rsp]
|
|
493
|
+ cmp rax, 3
|
|
494
|
+ jne arg_err
|
|
495
|
+ mov rax, [rsp+24]
|
|
496
|
+ jmp arg_cont
|
|
497
|
+ arg_nxt:
|
|
498
|
+ ; check that there is no more args
|
|
499
|
+ mov rbx, [rsp]
|
|
500
|
+ cmp rbx, 2
|
|
501
|
+ jne arg_err
|
|
502
|
+ add rax, 2
|
|
503
|
+ arg_cont:
|
|
504
|
+ ; rax should point on the value
|
|
505
|
+ mov bl, [rax+1]
|
|
506
|
+ cmp bl, 0
|
|
507
|
+ jne badval
|
492
|
508
|
xor rbx, rbx
|
493
|
509
|
mov bl, [rax]
|
494
|
510
|
cmp bl, '1'
|
|
@@ -496,30 +512,31 @@ arg_parse:
|
496
|
512
|
cmp bl, '8'
|
497
|
513
|
jg badval
|
498
|
514
|
sub bl, '0'
|
499
|
|
- dbg1:
|
500
|
515
|
mov [time_res], rbx
|
501
|
516
|
jmp arg_ok
|
502
|
517
|
|
503
|
|
-badval: ; print an error message, usage and exit
|
|
518
|
+; print an error message, usage and exit with rax pointing the value
|
|
519
|
+badval:
|
504
|
520
|
mov rsi, badval_msg
|
505
|
521
|
mov rdx, badval_msglen
|
506
|
|
- mov rax, [rsp+24]
|
507
|
522
|
jmp arg_strerr
|
508
|
523
|
|
509
|
|
-badarg: ; print an error message, usage and exit
|
|
524
|
+; print an error message, usage and exit
|
|
525
|
+badarg:
|
510
|
526
|
mov rsi, badarg_msg
|
511
|
527
|
mov rdx, badarg_msglen
|
512
|
528
|
mov rax, [rsp+16]
|
513
|
529
|
jmp arg_strerr
|
514
|
530
|
|
515
|
|
-arg_strerr: ; rsi msg ptr, rdx msg len, rax arg ptr
|
|
531
|
+; rsi msg ptr, rdx msg len, rax arg ptr
|
|
532
|
+arg_strerr:
|
516
|
533
|
mov r8, rax
|
517
|
534
|
mov rax, 1
|
518
|
535
|
mov rdi, 1
|
519
|
536
|
syscall
|
520
|
537
|
mov rsi, r8
|
521
|
538
|
mov rax, r8
|
522
|
|
- call strlen
|
|
539
|
+ call proc_strlen
|
523
|
540
|
mov rax, 1
|
524
|
541
|
syscall
|
525
|
542
|
mov rax, 1
|
|
@@ -545,7 +562,7 @@ usage:
|
545
|
562
|
|
546
|
563
|
pop rsi
|
547
|
564
|
mov rax, rsi
|
548
|
|
- call strlen
|
|
565
|
+ call proc_strlen
|
549
|
566
|
mov rax, 1
|
550
|
567
|
syscall
|
551
|
568
|
|
|
@@ -559,7 +576,7 @@ usage:
|
559
|
576
|
syscall
|
560
|
577
|
|
561
|
578
|
; With rax pointing on the string, the result will be in rdx
|
562
|
|
-strlen:
|
|
579
|
+proc_strlen:
|
563
|
580
|
mov r8, rax
|
564
|
581
|
mov r9, r8
|
565
|
582
|
sub r9, 1
|