nasm fixes #1

This commit is contained in:
Tyler Wilding 2020-08-28 20:26:27 -04:00
parent 2138beb150
commit c5bb7aab54
3 changed files with 43 additions and 24 deletions

View file

@ -3,6 +3,7 @@
#include "TypeSystem.h"
#include "type_util.h"
#include <cassert>
#include <stdexcept>
TypeSystem::TypeSystem() {
// the "none" type is included by default.

View file

@ -22,6 +22,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif(CMAKE_COMPILER_IS_GNUCXX)
enable_language(ASM_NASM)
#set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS ${CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS} asm)
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> <FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")
set_source_files_properties(kernel/asm_funcs.asm PROPERTIES COMPILE_FLAGS "-g")
set(RUNTIME_SOURCE
main.cpp
runtime.cpp
@ -35,7 +39,7 @@ set(RUNTIME_SOURCE
sce/sif_ee.cpp
sce/iop.cpp
sce/stubs.cpp
kernel/asm_funcs.nasm
kernel/asm_funcs.asm
kernel/fileio.cpp
kernel/kboot.cpp
kernel/kdgo.cpp

View file

@ -32,10 +32,12 @@ _format:
push rdi
; set the first argument register to the stack argument array
mov rdi, rsp
mov rcx, rsp
sub rsp, 32
; call C function to do format, result will go in RAX
call format_impl
add rsp, 32
; restore
; (note - this could probably just be add rsp 72, we don't care about the value of these register)
@ -70,29 +72,41 @@ _format:
global _call_goal_asm
_call_goal_asm:
;; x86 saved registers we need to modify for GOAL should be saved
push r13
push r14
push r15
;; RDI - first arg
;; RSI - second arg
;; RDX - third arg
;; RCX - function pointer (goes in r13)
;; R8 - st (goes in r14)
;; R9 - off (goes in r15)
;; set GOAL function pointer
mov r13, rcx
;; offset
mov r15, r8
;; symbol table
mov r14, r9
;; call GOAL by function pointer
push rdx ; 8
push rbx ; 16
push rbp ; 24
push rsi ; 32
push rdi ; 40
push r8 ; 48
push r9 ; 56
push r10 ; 64
push r11 ; 72
push r12 ; 80
push r13 ; 88
push r14 ; 96
push r15 ; 104
mov rdi, rcx ;; rdi is GOAL first argument, rcx is windows first argument
mov rsi, rdx ;; rsi is GOAL second argument, rdx is windows second argument
mov rdx, r8 ;; rdx is GOAL third argument, r8 is windows third argument
mov r13, r9 ;; r13 is GOAL fp, r9 is windows fourth argument
mov r14, [rsp + 144] ;; symbol table
mov r15, [rsp + 152] ;; offset
call r13
;; retore x86 registers.
pop r15
pop r14
pop r13
ret
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rbp
pop rbx
pop rdx
ret