Skip to content

Instantly share code, notes, and snippets.

@ArdaXi
Created August 23, 2010 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArdaXi/545000 to your computer and use it in GitHub Desktop.
Save ArdaXi/545000 to your computer and use it in GitHub Desktop.
; ------------------------------------------------------------------
; Machine code monitor -- by Yutaka Saito and Mike Saunders
;
; Accepts code in hex format, ORGed to 0x201000 (4K after where
; this program is loaded)
; ------------------------------------------------------------------
BITS 64
%INCLUDE "bmdev.asm"
ORG 0x200000
; This line determines where the machine code will
; be generated -- if you change it, you will need to
; ORG the code you enter at the new address
CODELOC equ 0x201000
mov rsi, helpmsg1 ; Print help text
call b_print_string
mov rsi, helpmsg2
call b_print_string
mov rsi, helpmsg3
call b_print_string
main_loop:
mov rsi, helpmsg4
call b_print_string
.noinput:
call b_print_newline
mov rsi, prompt ; Print prompt
call b_print_string
mov rdi, input ; Get hex string
call b_input_string
mov rdi, input
call b_string_length
cmp rdi, 0
je .noinput
mov rsi, input ; Convert to machine code...
mov rdi, run
.more:
cmp byte [rsi], '$' ; If char in string is '$', end of code
je .done
cmp byte [rsi], ' ' ; If space, move on to next char
je .space
cmp byte [rsi], 'r' ; If 'r' entered, re-run existing code
je .runprog
cmp byte [rsi], 'x' ; Or if 'x' entered, return to OS
jne .noexit
call b_print_newline
ret
.noexit:
mov al, [rsi]
and al, 0F0h
cmp al, 40h
je .H_A_to_F
.H_1_to_9:
mov al, [rsi]
sub al, 30h
mov ah, al
sal ah, 4
jmp .H_end
.H_A_to_F:
mov al, [rsi]
sub al, 37h
mov ah, al
sal ah, 4
.H_end:
inc rsi
mov al, [rsi]
and al, 0F0h
cmp al, 40h
je .L_A_to_F
.L_1_to_9:
mov al, [rsi]
sub al, 30h
jmp .L_end
.L_A_to_F:
mov al, [rsi]
sub al, 37h
.L_end:
or al, ah
mov [rdi], al
inc rdi
.space:
inc rsi
jmp .more
.done:
mov byte [rdi], 0 ; Write terminating zero
mov rsi, run ; Copy machine code to second 16K of RAM
mov rdi, CODELOC
mov cx, 255
cld
rep movsb
.runprog:
call b_print_newline
;call CODELOC ; Run program
mov rax, CODELOC
call b_smp_enqueue
call b_print_newline
jmp main_loop
input times 255 db 0 ; Code entered by user (in ASCII)
run times 255 db 0 ; Translated machine code to execute
helpmsg1 db 'MIKEOS MACHINE CODE MONITOR', 10, 13, 0
helpmsg2 db '(See the User Handbook for a quick guide)', 13, 10, 13, 10, 0
helpmsg3 db 'Enter instructions in hex, terminated by $ character', 10, 13, 0
helpmsg4 db 'Commands: r = re-run previous code, x = exit', 10, 13, 0
prompt db '= ', 0
; ------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment