Skip to content

Commit

Permalink
Merge pull request #7932 from tautschnig/cleanup/asm-library
Browse files Browse the repository at this point in the history
C library: ASM functions take void* pointers
  • Loading branch information
tautschnig authored Feb 8, 2024
2 parents 718587a + 0fff131 commit c81a6a6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-and-test-Xen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ jobs:

- name: Check for goto-cc section in xen-syms binary
run: objdump -h xen_4_13/xen/xen-syms | grep "goto-cc"

- name: Show goto-cc properties
run: $(pwd)/src/cbmc/cbmc --show-properties xen_4_13/xen/xen-syms

- name: Show some goto-cc functions
run: $(pwd)/src/cbmc/cbmc --list-goto-functions xen_4_13/xen/xen-syms | grep "arch"
12 changes: 6 additions & 6 deletions src/ansi-c/library/x86_assembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@

extern int __CPROVER_rounding_mode;

void __asm_fnstcw(unsigned short *dest)
void __asm_fnstcw(void *dest)
{
// the rounding mode is bits 10 and 11 in the control word
*dest=__CPROVER_rounding_mode<<10;
*(unsigned short *)dest = __CPROVER_rounding_mode << 10;
}

/* FUNCTION: __asm_fstcw */

extern int __CPROVER_rounding_mode;

void __asm_fstcw(unsigned short *dest)
void __asm_fstcw(void *dest)
{
// the rounding mode is bits 10 and 11 in the control word
*dest=__CPROVER_rounding_mode<<10;
*(unsigned short *)dest = __CPROVER_rounding_mode << 10;
}

/* FUNCTION: __asm_fldcw */

extern int __CPROVER_rounding_mode;

void __asm_fldcw(const unsigned short *src)
void __asm_fldcw(void *src)
{
// the rounding mode is bits 10 and 11 in the control word
__CPROVER_rounding_mode=((*src)>>10)&3;
__CPROVER_rounding_mode = ((*(const unsigned short *)src) >> 10) & 3;
}

/* FUNCTION: __asm_mfence */
Expand Down
24 changes: 20 additions & 4 deletions src/assembler/remove_asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class remove_asmt
void gcc_asm_function_call(
const irep_idt &function_base_name,
const code_asm_gcct &code,
std::size_t n_args,
goto_programt &dest);

void msc_asm_function_call(
Expand All @@ -83,10 +84,12 @@ class remove_asmt
/// \param function_base_name: Name of the function to call
/// \param code: gcc-style inline assembly statement to translate to function
/// call
/// \param n_args: Number of arguments required by \p function_base_name
/// \param dest: Goto program to append the function call to
void remove_asmt::gcc_asm_function_call(
const irep_idt &function_base_name,
const code_asm_gcct &code,
std::size_t n_args,
goto_programt &dest)
{
irep_idt function_identifier = function_base_name;
Expand Down Expand Up @@ -115,6 +118,16 @@ void remove_asmt::gcc_asm_function_call(
}
}

// An inline asm statement may consist of multiple commands, not all of which
// use all of the inputs/outputs of the inline asm statement.
DATA_INVARIANT_WITH_DIAGNOSTICS(
arguments.size() >= n_args,
"insufficient number of arguments for calling " +
id2string(function_identifier),
"required arguments: " + std::to_string(n_args),
code.pretty());
arguments.resize(n_args);

code_typet fkt_type{
code_typet::parameterst{
arguments.size(), code_typet::parametert{void_pointer}},
Expand All @@ -139,9 +152,12 @@ void remove_asmt::gcc_asm_function_call(
}
else
{
DATA_INVARIANT(
DATA_INVARIANT_WITH_DIAGNOSTICS(
symbol_table.lookup_ref(function_identifier).type == fkt_type,
"function types should match");
"types of function " + id2string(function_identifier) + " should match",
code.pretty(),
symbol_table.lookup_ref(function_identifier).type.pretty(),
fkt_type.pretty());
}
}

Expand Down Expand Up @@ -299,12 +315,12 @@ void remove_asmt::process_instruction_gcc(

if(command == "fstcw" || command == "fnstcw" || command == "fldcw") // x86
{
gcc_asm_function_call("__asm_" + id2string(command), code, tmp_dest);
gcc_asm_function_call("__asm_" + id2string(command), code, 1, tmp_dest);
}
else if(
command == "mfence" || command == "lfence" || command == "sfence") // x86
{
gcc_asm_function_call("__asm_" + id2string(command), code, tmp_dest);
gcc_asm_function_call("__asm_" + id2string(command), code, 0, tmp_dest);
}
else if(command == ID_sync) // Power
{
Expand Down

0 comments on commit c81a6a6

Please sign in to comment.