-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
595 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
kernel_init: | ||
call code_buffer_init | ||
call data_stack_init | ||
call dictionary_init | ||
|
||
mov [_blue.base], 10 | ||
mov [_blue.mode], INTERPRET | ||
ret | ||
|
||
; | ||
; expects | ||
; - tib value in rsi | ||
; - tib length in ecx | ||
; - tib in in eax | ||
; | ||
kernel_loop: | ||
mov [_blue.tib], rsi | ||
mov [_blue.tib_len], ecx | ||
mov [_blue.tib_in], eax | ||
|
||
.loop: | ||
call parser_next_word | ||
cmp [_blue.word_len], 0 | ||
je .done | ||
|
||
call dictionary_find | ||
test eax, eax | ||
jz .number_or_bail | ||
|
||
call _handle_word | ||
jmp .loop | ||
.number_or_bail: | ||
call to_number | ||
cmp eax, SUCCESS | ||
jne .not_a_word | ||
|
||
mov eax, edi | ||
call data_stack_push | ||
jmp .loop | ||
|
||
.done: | ||
mov eax, SUCCESS | ||
ret | ||
|
||
.not_a_word: | ||
mov edi, ERR_NOT_A_WORD | ||
ret | ||
|
||
kernel_deinit: | ||
call dictionary_deinit | ||
call data_stack_deinit | ||
call code_buffer_deinit | ||
ret | ||
|
||
; | ||
; expects | ||
; - word in rax | ||
; | ||
_handle_word: | ||
test al, DE_IMMEDIATE | ||
jnz .interpret | ||
|
||
test [_blue.mode], INTERPRET | ||
jnz .interpret | ||
|
||
.interpret: | ||
push rax | ||
call data_stack_pop | ||
pop rsi | ||
|
||
add rsi, _dictionary.code_offset | ||
mov rsi, [rsi] | ||
call rsi | ||
ret | ||
|
||
.compile: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
format elf64 executable 3 | ||
|
||
macro tc1 tib, tib_len, expected, expected_len { | ||
call kernel_init | ||
|
||
mov rsi, tib | ||
mov ecx, tib_len | ||
xor eax, eax | ||
|
||
call kernel_loop | ||
|
||
inc [test_num] | ||
cmp eax, SUCCESS | ||
jne failure | ||
mov rsi, expected | ||
mov ecx, expected_len | ||
call check_code_buffer | ||
call kernel_deinit | ||
} | ||
|
||
macro tc2 tib, tib_len { | ||
call kernel_init | ||
|
||
mov rsi, tib | ||
mov ecx, tib_len | ||
xor eax, eax | ||
|
||
call kernel_loop | ||
|
||
inc [test_num] | ||
cmp eax, FAILURE | ||
jne failure | ||
|
||
cmp edi, ERR_NOT_A_WORD | ||
jne failure | ||
call kernel_deinit | ||
} | ||
|
||
segment readable writeable | ||
|
||
include "defs.inc" | ||
|
||
test_num db 1 | ||
|
||
segment readable executable | ||
|
||
include "linux.inc" | ||
include "code_buffer.inc" | ||
include "data_stack.inc" | ||
include "dictionary.inc" | ||
include "parser.inc" | ||
include "to_number.inc" | ||
include "kernel.inc" | ||
|
||
entry $ | ||
mov [test_num], 0 | ||
|
||
call kernel_init | ||
inc [test_num] | ||
cmp [_blue.base], 10 | ||
jne failure | ||
inc [test_num] | ||
cmp [_blue.mode], INTERPRET | ||
jne failure | ||
call kernel_deinit | ||
|
||
tc1 clean_exit.blue, clean_exit.blue_length, \ | ||
clean_exit.expected, clean_exit.expected_length | ||
|
||
tc2 bogus.blue, bogus.blue_length | ||
xor edi, edi | ||
exit: | ||
mov eax, 60 | ||
syscall | ||
|
||
failure: | ||
mov dil, [test_num] | ||
jmp exit | ||
|
||
check_code_buffer: | ||
mov rdi, [_code_buffer.here] | ||
sub rdi, [_code_buffer.base] | ||
cmp edi, ecx | ||
jne failure | ||
|
||
mov rdi, [_code_buffer.base] | ||
|
||
.loop: | ||
cmpsb | ||
jne failure | ||
|
||
dec ecx | ||
jnz .loop | ||
ret | ||
|
||
segment readable | ||
|
||
bogus: | ||
.blue: | ||
db '^%^*^%' | ||
.blue_length = $ - .blue | ||
|
||
clean_exit: | ||
.blue: | ||
db '49 b, 255 b, ' ; xor edi, edi | ||
db '184 b, 60 d, ' ; mov eax, 60 | ||
db '15 b, 5 b,' ; syscall | ||
.blue_length = $ - .blue | ||
|
||
.expected: | ||
db 0x31, 0xff | ||
db 0xb8 | ||
dd 0x3c | ||
db 0x0f, 0x05 | ||
.expected_length = $ - .expected |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.