2023-11-14 03:26:03 +02:00
|
|
|
.code16
|
|
|
|
|
|
|
|
.section .stage2
|
|
|
|
|
|
|
|
# fills command line buffer
|
|
|
|
# NO REGISTERS SAVED
|
|
|
|
.global read_user_command_line
|
|
|
|
read_user_command_line:
|
2023-11-17 20:38:38 +02:00
|
|
|
# print initial command line
|
2023-11-14 03:26:03 +02:00
|
|
|
movw $command_line_enter_msg, %si
|
|
|
|
call puts
|
2023-11-17 20:38:38 +02:00
|
|
|
movw $command_line_buffer, %si
|
|
|
|
call puts
|
2023-11-14 03:26:03 +02:00
|
|
|
|
2023-11-17 20:38:38 +02:00
|
|
|
# prepare registers for input
|
|
|
|
movw $command_line_enter_msg, %si
|
2023-11-14 03:26:03 +02:00
|
|
|
movw $command_line_buffer, %di
|
2023-11-17 20:38:38 +02:00
|
|
|
.read_user_command_line_goto_end:
|
|
|
|
cmpb $0, (%di)
|
|
|
|
jz .read_user_command_line_loop
|
|
|
|
incw %di
|
|
|
|
jmp .read_user_command_line_goto_end
|
2023-11-14 03:26:03 +02:00
|
|
|
|
|
|
|
.read_user_command_line_loop:
|
|
|
|
call getc
|
|
|
|
|
|
|
|
cmpb $'\b', %al
|
|
|
|
je .read_user_command_line_backspace
|
2024-01-03 11:58:50 +02:00
|
|
|
cmpb $0x7F, %al
|
|
|
|
je .read_user_command_line_backspace
|
2023-11-14 03:26:03 +02:00
|
|
|
|
|
|
|
# Not sure if some BIOSes return '\n' as enter, but check it just in case
|
|
|
|
cmpb $'\r', %al
|
|
|
|
je .read_user_command_line_done
|
|
|
|
cmpb $'\n', %al
|
|
|
|
je .read_user_command_line_done
|
|
|
|
|
2023-11-17 12:12:37 +02:00
|
|
|
pushw %ax
|
|
|
|
|
2023-11-14 03:26:03 +02:00
|
|
|
call isprint
|
|
|
|
testb %al, %al
|
2023-11-17 12:12:37 +02:00
|
|
|
jz .read_user_command_line_loop
|
|
|
|
|
|
|
|
popw %ax
|
2023-11-14 03:26:03 +02:00
|
|
|
|
|
|
|
# put byte to buffer
|
|
|
|
movb %al, (%di)
|
|
|
|
incw %di
|
|
|
|
|
|
|
|
# print byte
|
|
|
|
call putc
|
|
|
|
|
|
|
|
jmp .read_user_command_line_loop
|
|
|
|
|
|
|
|
.read_user_command_line_backspace:
|
|
|
|
# don't do anything if at the beginning
|
|
|
|
cmpw $command_line_buffer, %di
|
|
|
|
je .read_user_command_line_loop
|
|
|
|
|
|
|
|
# decrement buffer pointer
|
|
|
|
decw %di
|
|
|
|
|
|
|
|
# erase byte in display
|
|
|
|
call print_backspace
|
|
|
|
|
|
|
|
jmp .read_user_command_line_loop
|
|
|
|
|
|
|
|
.read_user_command_line_done:
|
|
|
|
# null terminate command line
|
|
|
|
movb $0, (%di)
|
|
|
|
|
|
|
|
call print_newline
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
command_line_enter_msg:
|
|
|
|
.asciz "cmdline: "
|
|
|
|
|
2023-11-17 20:33:02 +02:00
|
|
|
.global command_line
|
|
|
|
command_line:
|
2023-11-14 03:26:03 +02:00
|
|
|
# 100 character command line
|
|
|
|
command_line_buffer:
|
2023-11-17 22:45:35 +02:00
|
|
|
.ascii "root=/dev/sda2"
|
2023-11-17 20:38:38 +02:00
|
|
|
.skip 100 - 28
|