OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [include/] [neorv32_cpu.h] - Diff between revs 68 and 73

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 68 Rev 73
Line 1... Line 1...
// #################################################################################################
// #################################################################################################
// # << NEORV32: neorv32_cpu.h - CPU Core Functions HW Driver >>                                   #
// # << NEORV32: neorv32_cpu.h - CPU Core Functions HW Driver >>                                   #
// # ********************************************************************************************* #
// # ********************************************************************************************* #
// # BSD 3-Clause License                                                                          #
// # BSD 3-Clause License                                                                          #
// #                                                                                               #
// #                                                                                               #
// # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
// # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
// #                                                                                               #
// #                                                                                               #
// # Redistribution and use in source and binary forms, with or without modification, are          #
// # Redistribution and use in source and binary forms, with or without modification, are          #
// # permitted provided that the following conditions are met:                                     #
// # permitted provided that the following conditions are met:                                     #
// #                                                                                               #
// #                                                                                               #
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
Line 49... Line 49...
void neorv32_cpu_set_mcycle(uint64_t value);
void neorv32_cpu_set_mcycle(uint64_t value);
uint64_t neorv32_cpu_get_instret(void);
uint64_t neorv32_cpu_get_instret(void);
void neorv32_cpu_set_minstret(uint64_t value);
void neorv32_cpu_set_minstret(uint64_t value);
uint64_t neorv32_cpu_get_systime(void);
uint64_t neorv32_cpu_get_systime(void);
void neorv32_cpu_delay_ms(uint32_t time_ms);
void neorv32_cpu_delay_ms(uint32_t time_ms);
void __attribute__((naked)) neorv32_cpu_goto_user_mode(void);
 
uint32_t neorv32_cpu_pmp_get_num_regions(void);
uint32_t neorv32_cpu_pmp_get_num_regions(void);
uint32_t neorv32_cpu_pmp_get_granularity(void);
uint32_t neorv32_cpu_pmp_get_granularity(void);
int neorv32_cpu_pmp_configure_region(uint32_t index, uint32_t base, uint32_t size, uint8_t config);
int neorv32_cpu_pmp_configure_region(uint32_t index, uint32_t base, uint8_t config);
uint32_t neorv32_cpu_hpm_get_counters(void);
uint32_t neorv32_cpu_hpm_get_counters(void);
uint32_t neorv32_cpu_hpm_get_size(void);
uint32_t neorv32_cpu_hpm_get_size(void);
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Prototype for "after-main handler". This function is called if main() returns.
 * Prototype for "after-main handler". This function is called if main() returns.
 *
 *
 * @param[in] return_code Return value of main() function.
 * @param[in] return_code Return value of main() function.
 * @return Return value is irrelevant (there is no one left to check for it...).
 
 **************************************************************************/
 **************************************************************************/
extern int __neorv32_crt0_after_main(int32_t return_code) __attribute__ ((weak));
extern void __attribute__ ((weak)) __neorv32_crt0_after_main(int32_t return_code);
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Store unsigned word to address space if atomic access reservation is still valid.
 * Store unsigned word to address space if atomic access reservation is still valid.
 *
 *
Line 159... Line 157...
  asm volatile ("lr.w %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
  asm volatile ("lr.w %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
#else
#else
  asm volatile ("lw %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
  asm volatile ("lw %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
#endif
#endif
 
 
  return (uint32_t)reg_data;
  return reg_data;
}
}
 
 
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Load unsigned word from address space.
 * Load unsigned word from address space.
 *
 *
 * @note An unaligned access address will raise an alignment exception.
 * @note An unaligned access address will raise an alignment exception.
 *
 *
Line 179... Line 176...
  register uint32_t reg_addr = addr;
  register uint32_t reg_addr = addr;
  register uint32_t reg_data;
  register uint32_t reg_data;
 
 
  asm volatile ("lw %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
  asm volatile ("lw %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
 
 
  return (uint32_t)reg_data;
  return reg_data;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Load unsigned half-word from address space.
 * Load unsigned half-word from address space.
Line 194... Line 191...
 * @return Read data half-word (16-bit).
 * @return Read data half-word (16-bit).
 **************************************************************************/
 **************************************************************************/
inline uint16_t __attribute__ ((always_inline)) neorv32_cpu_load_unsigned_half(uint32_t addr) {
inline uint16_t __attribute__ ((always_inline)) neorv32_cpu_load_unsigned_half(uint32_t addr) {
 
 
  register uint32_t reg_addr = addr;
  register uint32_t reg_addr = addr;
  register uint32_t reg_data;
  register uint16_t reg_data;
 
 
  asm volatile ("lhu %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
  asm volatile ("lhu %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
 
 
  return (uint16_t)reg_data;
  return reg_data;
 
}
 
 
 
 
 
/**********************************************************************//**
 
 * Load signed half-word from address space.
 
 *
 
 * @note An unaligned access address will raise an alignment exception.
 
 *
 
 * @param[in] addr Address (32-bit).
 
 * @return Read data half-word (16-bit).
 
 **************************************************************************/
 
inline int16_t __attribute__ ((always_inline)) neorv32_cpu_load_signed_half(uint32_t addr) {
 
 
 
  register uint32_t reg_addr = addr;
 
  register int16_t reg_data;
 
 
 
  asm volatile ("lh %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
 
 
 
  return reg_data;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Load unsigned byte from address space.
 * Load unsigned byte from address space.
Line 211... Line 227...
 * @return Read data byte (8-bit).
 * @return Read data byte (8-bit).
 **************************************************************************/
 **************************************************************************/
inline uint8_t __attribute__ ((always_inline)) neorv32_cpu_load_unsigned_byte(uint32_t addr) {
inline uint8_t __attribute__ ((always_inline)) neorv32_cpu_load_unsigned_byte(uint32_t addr) {
 
 
  register uint32_t reg_addr = addr;
  register uint32_t reg_addr = addr;
  register uint32_t reg_data;
  register uint8_t reg_data;
 
 
  asm volatile ("lbu %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
  asm volatile ("lbu %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
 
 
  return (uint8_t)reg_data;
  return reg_data;
 
}
 
 
 
 
 
/**********************************************************************//**
 
 * Load signed byte from address space.
 
 *
 
 * @param[in] addr Address (32-bit).
 
 * @return Read data byte (8-bit).
 
 **************************************************************************/
 
inline int8_t __attribute__ ((always_inline)) neorv32_cpu_load_signed_byte(uint32_t addr) {
 
 
 
  register uint32_t reg_addr = addr;
 
  register int8_t reg_data;
 
 
 
  asm volatile ("lb %[da], 0(%[ad])" : [da] "=r" (reg_data) : [ad] "r" (reg_addr));
 
 
 
  return reg_data;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Read data from CPU configuration and status register (CSR).
 * Read data from CPU configuration and status register (CSR).

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.