Skip to content

Commit

Permalink
Updates to make relative positioning easier
Browse files Browse the repository at this point in the history
  • Loading branch information
cthulhuology committed Nov 22, 2013
1 parent a684b62 commit 341a10e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ syscall.asm : /usr/include/sys/syscall.h
cat /usr/include/sys/syscall.h | grep -v "old " | grep "^#define" | sed 's%#define%\%define%' | sed 's%SYS_%%' | sed 's%$$% + 0x2000000%' | tail -n +3 > syscall.asm

image.bin : image.asm syscall.asm vm.asm term.asm tools.asm
yasm -f bin -o image.bin image.asm
yasm -m amd64 -f bin -o image.bin image.asm

image : image.bin
dd if=/dev/zero of=image bs=1048576 count=1
Expand Down
17 changes: 6 additions & 11 deletions image.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@
;;

BITS 64
ORG 0x100003000
ORG 0

;; Include core macro files
%include "vm.asm"
%include "system.asm"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Initialize VM
;vm
;%include "term.asm"
;quit
vm

literal 18
data message
show

mov rax, write ; 0x2000004 write
mov rdi, 2 ; stderr
mov rsi, qword message ; string
mov rdx, 18 ; length
syscall
mov rax, exit ; 0x2000001 exit
syscall
quit

message: db "running in image",0xa,0xd
2 changes: 1 addition & 1 deletion system.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; System Maros for Mac OS X
;; System Macros for Mac OS X
;;
;; © 2012 David J Goehrig <dave@dloh.org>
;;
Expand Down
18 changes: 9 additions & 9 deletions term.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ call clear
call term
; we never get here

%include "screen.asm"
;%include "screen.asm"
%include "tools.asm"

; this is the key input display loop
term:
key
call test_quit
call test_retn
call test_backspace
call update
method draw ; draw co-routine
invoke ; will return
; call test_retn
; call test_backspace
; call update
jmp term ; will return

charshift: ; key count --
zero
Expand Down Expand Up @@ -83,14 +82,15 @@ linefeed:
mulnum 144
call cursor
store
method draw
invoke
ret

test_backspace:

ret

done:
xdone:
jmp done
;; never get here
offset done_str ; done_str -> tos
fetch ; [done_str] -> tos
dupe
Expand Down
31 changes: 22 additions & 9 deletions vm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
;
; rax top of stack / return value
; rdx misc data, arg3 / 2nd return
; rcx count, arg4
; rcx count
; rbx context pointer ( preserved )
; rbp data stack pointer ( preserved )
; rsp return stack pointer ( preserved )
; rdi -- syscalls arg1
; rsi -- syscalls arg2
; r8 -- syscalls arg5
; r9 -- syscalls arg6
; r10 -- temp
; r10 -- syscalls arg4
; r11 -- temp
; r12 free address location ( preserved )
; r13 image location ( preserved )
Expand All @@ -43,6 +43,12 @@
%macro vm 0
_vm:
jmp _init
nop
nop
nop
nop
nop
nop
; VM header
image_addr: dq 0
image_size: dq 0
Expand All @@ -51,7 +57,7 @@ _init:
mov [bp + image_addr], r13 ; Save addr
mov [bp + image_size], r14 ; Save size
mov [bp + image_fd], r15 ; Save file handle
mov tos, 0x1000 ; Load the base context
mov tos, 0x1000
spawn
%endmacro

Expand Down Expand Up @@ -114,11 +120,11 @@ rstack equ 8*18 ;

;; Creates initializes a new context at a given address
%macro spawn 0
lea cp,[bp + tos*8] ; load the context pointer in the top of the stack
; lea rp,[cp+rstack] ; loads the return stack pointer
lea fp,[cp+0x4000] ; free page is 1 page of memory above context
xor dp,dp ; data stack pointer is 0, aka cp + 0
xor tos,tos ; clear the rest of the pointers etc
lea cp,[bp + tos*8] ; load the context pointer in the top of the stack
lea rp,[cp + tos*8 + 0x1000] ; loads the return stack pointer
lea fp,[cp + tos*8 + 0x2000] ; free page is 2 pages of memory above context
xor dp,dp ; data stack pointer is 0, aka cp + 0
xor tos,tos ; clear the rest of the pointers etc
xor src,src
xor dst,dst
%endmacro
Expand Down Expand Up @@ -146,7 +152,7 @@ rstack equ 8*18 ;

;; loads OS C ABI arg4
%macro arg4 0
mov rcx,tos
mov r10,tos
drop
%endmacro

Expand Down Expand Up @@ -218,6 +224,13 @@ rstack equ 8*18 ;
lea tos,[bp+%1]
%endmacro

;; Locates literal data pointer
%macro data 1
dupe
lea tos,[bp+%1]
%endmacro


;; places the address of a static region of memory on the stack
%macro offset 1
dupe
Expand Down

0 comments on commit 341a10e

Please sign in to comment.