mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
Flat address x86_64 port of Nuttx (#411)
* arch: x86_64: Pour-in the x86_64 code from cRTOS repository, excluding modifications of NuttX kernel, jailhouse support and linux compatibility layer * arch: x86_64: Refactor x86_64 loading procedure for better comprehension and included support for multiboot2 * arch: x86_64: Locate the kernel at 4GB~ and modify the page table initializing procedure accordingly * arch: x86_64: Implemented kconfig option for various x86_64 capabilities, dynamic probe and check capability on lowsetup before enabling * arch: x86_64: inte64_check_capability: Use Marco to prettify the capability checking procedure * arch: x86_64: intel64_timerisr.c: Refactor with new frequency calibrating method * arch: x86_64: Fix C alias of page table and GDT/IST * arch: x86_64: Reload GTDR with GDT in high address in up_lowsetup * arch: x86_64: Consolidate MSR definition in arch/arch.h * arch: x86_64: Edit the way of handling GDT/IST in C into structures * arch: x86_64: Correct the starting point of isr/irq stack * arch: x86_64: Update up_initialize.c with the new initializing procedure * arch: x86_64: up_map_region now take flags instead of assuming WR/PRESENT * arch: x86_64: Overhual of interrupt initialization procedure * arch: x86_64: Properly configure the heap to be memory as [_ebss, end of memory] * arch: x86_64: Try to probe the TSC frequency, fall-back to user specified frequency on failure * arch: x86_64: Remove debug printing during restore_aux, causing infinite CTX bug * arch: x86_64: for X86 16500 serial interrupt to work, OUT2 of MCR must be 1. Make it stuck at 1 after boot * arch: x86_64: Correctly apply license header, comment and format code * arch: x86_64: properly send a SIGFPE on floating point error * arch: x86_64: Remove unused variable in up_restore_auxstate * arch: x86_64: properly trash the processor with an infinite loop * arch: x86_64: Fix typo in ISR handler causing ISR not handled * arch: x86_64: Fix possibile race conditions with scheduler debug option on in signal handling path * arch: x86_64: Fix typo in MSR_X2APIC_LVTT_TSC_DEADLINE * arch: x86_64: Migrate tickless implementation to the new MSR naming and frequency calibration method * board: x86_64: qemu: Add guard to exclude up_netinitialize when compiling without net support * arch: x86_64: update defconfigs * arch: x86_64: rename qemu as qemu-intel64 * arch: x86_64: update Board readme
This commit is contained in:
+8
-2
@@ -79,10 +79,15 @@ config ARCH_SIM
|
||||
---help---
|
||||
Linux/Cygwin user-mode simulation.
|
||||
|
||||
config ARCH_X86
|
||||
config arch_x86
|
||||
bool "x86"
|
||||
---help---
|
||||
Intel x86 architectures.
|
||||
intel x86 architectures.
|
||||
|
||||
config ARCH_X86_64
|
||||
bool "x86_64"
|
||||
---help---
|
||||
x86-64 architectures.
|
||||
|
||||
config ARCH_XTENSA
|
||||
bool "Xtensa"
|
||||
@@ -136,6 +141,7 @@ source arch/renesas/Kconfig
|
||||
source arch/risc-v/Kconfig
|
||||
source arch/sim/Kconfig
|
||||
source arch/x86/Kconfig
|
||||
source arch/x86_64/Kconfig
|
||||
source arch/xtensa/Kconfig
|
||||
source arch/z16/Kconfig
|
||||
source arch/z80/Kconfig
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
if ARCH_X86_64
|
||||
comment "x86_64 Configuration Options"
|
||||
|
||||
config ARCH
|
||||
string
|
||||
default "x86_64"
|
||||
|
||||
choice
|
||||
prompt "x86_64 arch selection"
|
||||
default ARCH_INTEL64
|
||||
|
||||
config ARCH_INTEL64
|
||||
bool "Intel x86_64"
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_USE_MPU
|
||||
select ARCH_HAVE_TICKLESS
|
||||
select ARCH_HAVE_STACKCHECK
|
||||
select ARCH_HAVE_RNG
|
||||
---help---
|
||||
Intel x86_64 architecture
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "x86_64 system selection"
|
||||
default ARCH_BOARD_QEMU
|
||||
|
||||
config ARCH_BOARD_QEMU
|
||||
bool "Qemu envrionment"
|
||||
---help---
|
||||
Targeting virtualized qemu environment
|
||||
|
||||
endchoice
|
||||
|
||||
source arch/x86_64/src/common/Kconfig
|
||||
|
||||
if ARCH_INTEL64
|
||||
source arch/x86_64/src/intel64/Kconfig
|
||||
|
||||
config ARCH_CHIP
|
||||
string
|
||||
default "intel64"
|
||||
|
||||
endif # ARCH_INTEL64
|
||||
|
||||
if ARCH_BOARD_QEMU
|
||||
source arch/x86_64/src/qemu/Kconfig
|
||||
|
||||
config ARCH_BOARD
|
||||
string
|
||||
default "qemu-intel64"
|
||||
|
||||
endif # ARCH_CHIP_QEMU
|
||||
|
||||
config ARCH_EXCLUDE_MULTIBOOT
|
||||
bool "Don't append multiboot2 header"
|
||||
default n
|
||||
---help---
|
||||
Some platforms, e.g. jailhouse, do not like to have a multiboot header
|
||||
|
||||
|
||||
endif # ARCH_X86_64
|
||||
@@ -0,0 +1,3 @@
|
||||
/chip
|
||||
/board
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
arch/x86_64/include/README.txt
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This directory holds x86_64-specific header files. The top-level header files in
|
||||
arch/x86_64/include simply include corresponding header files from lower lower-
|
||||
level chip-specific and architecture-specific directories.
|
||||
|
||||
Architecture-Specific Directories
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Architecture-specific directories hold common header files for specific x86_64
|
||||
architectures.
|
||||
|
||||
intel64
|
||||
This directory holds definitions appropriate for any instantiation of the
|
||||
Intel architecture in 64bit long mode.
|
||||
|
||||
Chip-Specific directories
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The same x86 architecture may be realized in different chip implementations.
|
||||
For SoC chips, in particular, on-chip devices and differing interrupt
|
||||
structures may require special, chip-specific definitions in these chip-
|
||||
specific directories.
|
||||
|
||||
broadwell
|
||||
This is the implementation of NuttX on the Intel Broadwell processors.
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/arch.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through arch/arch.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_ARCH_H
|
||||
#define __ARCH_X86_64_INCLUDE_ARCH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/* Include chip-specific definitions */
|
||||
|
||||
# include <arch/chip/arch.h>
|
||||
|
||||
/* Include architecture-specific definitions */
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/arch.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Inline functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_ARCH_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,230 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/intel64/inttypes.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTEL64_INTTYPES_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTEL64_INTTYPES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define PRId8 "d"
|
||||
#define PRId16 "d"
|
||||
#define PRId32 "d"
|
||||
#define PRId64 "lld"
|
||||
|
||||
#define PRIdLEAST8 "d"
|
||||
#define PRIdLEAST16 "d"
|
||||
#define PRIdLEAST32 "d"
|
||||
#define PRIdLEAST64 "lld"
|
||||
|
||||
#define PRIdFAST8 "d"
|
||||
#define PRIdFAST16 "d"
|
||||
#define PRIdFAST32 "d"
|
||||
#define PRIdFAST64 "lld"
|
||||
|
||||
#define PRIdMAX "lld"
|
||||
#define PRIdPTR "lld"
|
||||
|
||||
#define PRIi8 "i"
|
||||
#define PRIi16 "i"
|
||||
#define PRIi32 "i"
|
||||
#define PRIi64 "lli"
|
||||
|
||||
#define PRIiLEAST8 "i"
|
||||
#define PRIiLEAST16 "i"
|
||||
#define PRIiLEAST32 "i"
|
||||
#define PRIiLEAST64 "lli"
|
||||
|
||||
#define PRIiFAST8 "i"
|
||||
#define PRIiFAST16 "i"
|
||||
#define PRIiFAST32 "i"
|
||||
#define PRIiFAST64 "lli"
|
||||
|
||||
#define PRIiMAX "lli"
|
||||
#define PRIiPTR "lli"
|
||||
|
||||
#define PRIo8 "o"
|
||||
#define PRIo16 "o"
|
||||
#define PRIo32 "o"
|
||||
#define PRIo64 "llo"
|
||||
|
||||
#define PRIoLEAST8 "o"
|
||||
#define PRIoLEAST16 "o"
|
||||
#define PRIoLEAST32 "o"
|
||||
#define PRIoLEAST64 "llo"
|
||||
|
||||
#define PRIoFAST8 "o"
|
||||
#define PRIoFAST16 "o"
|
||||
#define PRIoFAST32 "o"
|
||||
#define PRIoFAST64 "llo"
|
||||
|
||||
#define PRIoMAX "llo"
|
||||
#define PRIoPTR "llo"
|
||||
|
||||
#define PRIu8 "u"
|
||||
#define PRIu16 "u"
|
||||
#define PRIu32 "u"
|
||||
#define PRIu64 "llu"
|
||||
|
||||
#define PRIuLEAST8 "u"
|
||||
#define PRIuLEAST16 "u"
|
||||
#define PRIuLEAST32 "u"
|
||||
#define PRIuLEAST64 "llu"
|
||||
|
||||
#define PRIuFAST8 "u"
|
||||
#define PRIuFAST16 "u"
|
||||
#define PRIuFAST32 "u"
|
||||
#define PRIuFAST64 "llu"
|
||||
|
||||
#define PRIuMAX "llu"
|
||||
#define PRIuPTR "llu"
|
||||
|
||||
#define PRIx8 "x"
|
||||
#define PRIx16 "x"
|
||||
#define PRIx32 "x"
|
||||
#define PRIx64 "llx"
|
||||
|
||||
#define PRIxLEAST8 "x"
|
||||
#define PRIxLEAST16 "x"
|
||||
#define PRIxLEAST32 "x"
|
||||
#define PRIxLEAST64 "llx"
|
||||
|
||||
#define PRIxFAST8 "x"
|
||||
#define PRIxFAST16 "x"
|
||||
#define PRIxFAST32 "x"
|
||||
#define PRIxFAST64 "llx"
|
||||
|
||||
#define PRIxMAX "llx"
|
||||
#define PRIxPTR "llx"
|
||||
|
||||
#define PRIX8 "X"
|
||||
#define PRIX16 "X"
|
||||
#define PRIX32 "X"
|
||||
#define PRIX64 "llX"
|
||||
|
||||
#define PRIXLEAST8 "X"
|
||||
#define PRIXLEAST16 "X"
|
||||
#define PRIXLEAST32 "X"
|
||||
#define PRIXLEAST64 "llX"
|
||||
|
||||
#define PRIXFAST8 "X"
|
||||
#define PRIXFAST16 "X"
|
||||
#define PRIXFAST32 "X"
|
||||
#define PRIXFAST64 "llX"
|
||||
|
||||
#define PRIXMAX "llX"
|
||||
#define PRIXPTR "llX"
|
||||
|
||||
#define SCNd8 "hhd"
|
||||
#define SCNd16 "hd"
|
||||
#define SCNd32 "d"
|
||||
#define SCNd64 "lld"
|
||||
|
||||
#define SCNdLEAST8 "hhd"
|
||||
#define SCNdLEAST16 "hd"
|
||||
#define SCNdLEAST32 "d"
|
||||
#define SCNdLEAST64 "lld"
|
||||
|
||||
#define SCNdFAST8 "hhd"
|
||||
#define SCNdFAST16 "hd"
|
||||
#define SCNdFAST32 "d"
|
||||
#define SCNdFAST64 "lld"
|
||||
|
||||
#define SCNdMAX "lld"
|
||||
#define SCNdPTR "lld"
|
||||
|
||||
#define SCNi8 "hhi"
|
||||
#define SCNi16 "hi"
|
||||
#define SCNi32 "i"
|
||||
#define SCNi64 "lli"
|
||||
|
||||
#define SCNiLEAST8 "hhi"
|
||||
#define SCNiLEAST16 "hi"
|
||||
#define SCNiLEAST32 "i"
|
||||
#define SCNiLEAST64 "lli"
|
||||
|
||||
#define SCNiFAST8 "hhi"
|
||||
#define SCNiFAST16 "hi"
|
||||
#define SCNiFAST32 "i"
|
||||
#define SCNiFAST64 "lli"
|
||||
|
||||
#define SCNiMAX "lli"
|
||||
#define SCNiPTR "lli"
|
||||
|
||||
#define SCNo8 "hho"
|
||||
#define SCNo16 "ho"
|
||||
#define SCNo32 "o"
|
||||
#define SCNo64 "llo"
|
||||
|
||||
#define SCNoLEAST8 "hho"
|
||||
#define SCNoLEAST16 "ho"
|
||||
#define SCNoLEAST32 "o"
|
||||
#define SCNoLEAST64 "llo"
|
||||
|
||||
#define SCNoFAST8 "hho"
|
||||
#define SCNoFAST16 "ho"
|
||||
#define SCNoFAST32 "o"
|
||||
#define SCNoFAST64 "llo"
|
||||
|
||||
#define SCNoMAX "llo"
|
||||
#define SCNoPTR "llo"
|
||||
|
||||
#define SCNu8 "hhu"
|
||||
#define SCNu16 "hu"
|
||||
#define SCNu32 "u"
|
||||
#define SCNu64 "llu"
|
||||
|
||||
#define SCNuLEAST8 "hhu"
|
||||
#define SCNuLEAST16 "hu"
|
||||
#define SCNuLEAST32 "u"
|
||||
#define SCNuLEAST64 "llu"
|
||||
|
||||
#define SCNuFAST8 "hhu"
|
||||
#define SCNuFAST16 "hu"
|
||||
#define SCNuFAST32 "u"
|
||||
#define SCNuFAST64 "llu"
|
||||
|
||||
#define SCNuMAX "llu"
|
||||
#define SCNuPTR "u"
|
||||
|
||||
#define SCNx8 "hhx"
|
||||
#define SCNx16 "hx"
|
||||
#define SCNx32 "x"
|
||||
#define SCNx64 "llx"
|
||||
|
||||
#define SCNxLEAST8 "hhx"
|
||||
#define SCNxLEAST16 "hx"
|
||||
#define SCNxLEAST32 "x"
|
||||
#define SCNxLEAST64 "llx"
|
||||
|
||||
#define SCNxFAST8 "hhx"
|
||||
#define SCNxFAST16 "hx"
|
||||
#define SCNxFAST32 "x"
|
||||
#define SCNxFAST64 "llx"
|
||||
|
||||
#define SCNxMAX "llx"
|
||||
#define SCNxPTR "x"
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_INTEL64_INTTYPES_H */
|
||||
@@ -0,0 +1,206 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/intel64/io.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through arch/io.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTEL64_IO_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTEL64_IO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arch/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Inline functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Standard x86 Port I/O */
|
||||
|
||||
static inline void outb(uint8_t regval, uint16_t port)
|
||||
{
|
||||
asm volatile(
|
||||
"\toutb %0,%1\n"
|
||||
:
|
||||
: "a" (regval), "dN" (port)
|
||||
);
|
||||
}
|
||||
|
||||
static inline uint8_t inb(uint16_t port)
|
||||
{
|
||||
uint8_t regval;
|
||||
asm volatile(
|
||||
"\tinb %1,%0\n"
|
||||
: "=a" (regval)
|
||||
: "dN" (port)
|
||||
);
|
||||
return regval;
|
||||
}
|
||||
|
||||
static inline void outw(uint16_t regval, uint16_t port)
|
||||
{
|
||||
asm volatile(
|
||||
"\toutw %0,%1\n"
|
||||
:
|
||||
: "a" (regval), "dN" (port)
|
||||
);
|
||||
}
|
||||
|
||||
static inline uint16_t inw(uint16_t port)
|
||||
{
|
||||
uint16_t regval;
|
||||
|
||||
asm volatile(
|
||||
"\tinw %1,%0\n"
|
||||
: "=a" (regval)
|
||||
: "dN" (port)
|
||||
);
|
||||
return regval;
|
||||
}
|
||||
|
||||
static inline void outl(uint32_t regval, uint16_t port)
|
||||
{
|
||||
asm volatile(
|
||||
"\toutl %0,%1\n"
|
||||
:
|
||||
: "a" (regval), "dN" (port)
|
||||
);
|
||||
}
|
||||
|
||||
static inline uint32_t inl(uint16_t port)
|
||||
{
|
||||
uint32_t regval;
|
||||
asm volatile(
|
||||
"\tinl %1,%0\n"
|
||||
: "=a" (regval)
|
||||
: "dN" (port)
|
||||
);
|
||||
return regval;
|
||||
}
|
||||
|
||||
/* MMIO */
|
||||
|
||||
static inline uint8_t mmio_read8(void *address)
|
||||
{
|
||||
return *(volatile uint8_t *)address;
|
||||
}
|
||||
|
||||
static inline uint16_t mmio_read16(void *address)
|
||||
{
|
||||
return *(volatile uint16_t *)address;
|
||||
}
|
||||
|
||||
static inline uint32_t mmio_read32(void *address)
|
||||
{
|
||||
uint32_t value;
|
||||
|
||||
/* Assembly-encoded to match the hypervisor MMIO parser support */
|
||||
|
||||
asm volatile("movl (%1),%0" : "=r" (value) : "r" (address));
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline uint64_t mmio_read64(void *address)
|
||||
{
|
||||
return *(volatile uint64_t *)address;
|
||||
}
|
||||
|
||||
static inline void mmio_write8(void *address, uint8_t value)
|
||||
{
|
||||
*(volatile uint8_t *)address = value;
|
||||
}
|
||||
|
||||
static inline void mmio_write16(void *address, uint16_t value)
|
||||
{
|
||||
*(volatile uint16_t *)address = value;
|
||||
}
|
||||
|
||||
static inline void mmio_write32(void *address, uint32_t value)
|
||||
{
|
||||
/* Assembly-encoded to match the hypervisor MMIO parser support */
|
||||
|
||||
asm volatile("movl %0,(%1)" : : "r" (value), "r" (address));
|
||||
}
|
||||
|
||||
static inline void mmio_write64(void *address, uint64_t value)
|
||||
{
|
||||
*(volatile uint64_t *)address = value;
|
||||
}
|
||||
|
||||
static inline void up_trash_cpu(void)
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
asm volatile ("cli;hlt;");
|
||||
}
|
||||
|
||||
asm("ud2":::"memory");
|
||||
}
|
||||
|
||||
static inline void up_invalid_TLB(uintptr_t start, uintptr_t end)
|
||||
{
|
||||
uintptr_t i;
|
||||
|
||||
start = start & PAGE_MASK;
|
||||
end = (end + PAGE_SIZE - 1) & PAGE_MASK;
|
||||
|
||||
for (i = start; i < end; i += PAGE_SIZE)
|
||||
{
|
||||
asm("invlpg %0;":: "m"(i):"memory");
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_X86_64_INCLUDE_INTEL64_IO_H */
|
||||
@@ -0,0 +1,304 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/intel64/irq.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through nuttx/irq.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTEL64_IRQ_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTEL64_IRQ_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <stdint.h>
|
||||
# include <stdbool.h>
|
||||
# include <arch/arch.h>
|
||||
# include <semaphore.h>
|
||||
# include <time.h>
|
||||
# include <debug.h>
|
||||
# include <nuttx/config.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* ISR and IRQ numbers */
|
||||
|
||||
#define ISR0 0 /* Division by zero exception */
|
||||
#define ISR1 1 /* Debug exception */
|
||||
#define ISR2 2 /* Non maskable interrupt */
|
||||
#define ISR3 3 /* Breakpoint exception */
|
||||
#define ISR4 4 /* 'Into detected overflow' */
|
||||
#define ISR5 5 /* Out of bounds exception */
|
||||
#define ISR6 6 /* Invalid opcode exception */
|
||||
#define ISR7 7 /* No coprocessor exception */
|
||||
#define ISR8 8 /* Double fault (pushes an error code) */
|
||||
#define ISR9 9 /* Coprocessor segment overrun */
|
||||
#define ISR10 10 /* Bad TSS (pushes an error code) */
|
||||
#define ISR11 11 /* Segment not present (pushes an error code) */
|
||||
#define ISR12 12 /* Stack fault (pushes an error code) */
|
||||
#define ISR13 13 /* General protection fault (pushes an error code) */
|
||||
#define ISR14 14 /* Page fault (pushes an error code) */
|
||||
#define ISR15 15 /* Unknown interrupt exception */
|
||||
#define ISR16 16 /* Coprocessor fault */
|
||||
#define ISR17 17 /* Alignment check exception */
|
||||
#define ISR18 18 /* Machine check exception */
|
||||
#define ISR19 19 /* SIMD Float-Point Exception*/
|
||||
#define ISR20 20 /* Virtualization Exception */
|
||||
#define ISR21 21 /* Reserved */
|
||||
#define ISR22 22 /* Reserved */
|
||||
#define ISR23 23 /* Reserved */
|
||||
#define ISR24 24 /* Reserved */
|
||||
#define ISR25 25 /* Reserved */
|
||||
#define ISR26 26 /* Reserved */
|
||||
#define ISR27 27 /* Reserved */
|
||||
#define ISR28 28 /* Reserved */
|
||||
#define ISR29 29 /* Reserved */
|
||||
#define ISR30 30 /* Security Exception */
|
||||
#define ISR31 31 /* Reserved */
|
||||
|
||||
#define IRQ0 32 /* System timer (cannot be changed) */
|
||||
#define IRQ1 33 /* Keyboard controller (cannot be changed) */
|
||||
#define IRQ2 34 /* Cascaded signals from IRQs 8~15 */
|
||||
#define IRQ3 35 /* Serial port controller for COM2/4 */
|
||||
#define IRQ4 36 /* serial port controller for COM1/3 */
|
||||
#define IRQ5 37 /* LPT port 2 or sound card */
|
||||
#define IRQ6 38 /* Floppy disk controller */
|
||||
#define IRQ7 39 /* LPT port 1 or sound card */
|
||||
#define IRQ8 40 /* Real time clock (RTC) */
|
||||
#define IRQ9 41 /* Open interrupt/available or SCSI host adapter */
|
||||
#define IRQ10 42 /* Open interrupt/available or SCSI or NIC */
|
||||
#define IRQ11 43 /* Open interrupt/available or SCSI or NIC */
|
||||
#define IRQ12 44 /* Mouse on PS/2 connector */
|
||||
#define IRQ13 45 /* Math coprocessor */
|
||||
#define IRQ14 46 /* Primary ATA channel */
|
||||
#define IRQ15 47 /* Secondary ATA channel */
|
||||
|
||||
#define IRQ_ERROR 51 /* APIC Error */
|
||||
#define IRQ_SPURIOUS 0xff /* Spurious Interrupts */
|
||||
|
||||
#define NR_IRQS 48
|
||||
|
||||
/* Common register save structure created by up_saveusercontext() and by
|
||||
* ISR/IRQ interrupt processing.
|
||||
*/
|
||||
|
||||
#define XCPTCONTEXT_XMM_AREA_SIZE 512
|
||||
#define XMMAREA_OFFSET XCPTCONTEXT_XMM_AREA_SIZE / 8
|
||||
|
||||
/* Data segments */
|
||||
|
||||
#define REG_ALIGN (0 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_FS (1 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_GS (2 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_ES (3 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_DS (4 + XMMAREA_OFFSET) /* Data segment selector */
|
||||
|
||||
/* Remaining regs */
|
||||
|
||||
#define REG_RAX (5 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_RBX (6 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_RBP (7 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R10 (8 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R11 (9 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R12 (10 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R13 (11 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R14 (12 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R15 (13 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
|
||||
/* ABI calling convention */
|
||||
|
||||
#define REG_R9 (14 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_R8 (15 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_RCX (16 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_RDX (17 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_RSI (18 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
#define REG_RDI (19 + XMMAREA_OFFSET) /* " " "" " " */
|
||||
|
||||
/* IRQ saved */
|
||||
|
||||
#define REG_ERRCODE (20 + XMMAREA_OFFSET) /* Error code */
|
||||
#define REG_RIP (21 + XMMAREA_OFFSET) /* Pushed by process on interrupt processing */
|
||||
#define REG_CS (22 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_RFLAGS (23 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_RSP (24 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
#define REG_SS (25 + XMMAREA_OFFSET) /* " " "" " " "" " " " " */
|
||||
|
||||
/* NOTE 2: This is not really state data. Rather, this is just a convenient
|
||||
* way to pass parameters from the interrupt handler to C code.
|
||||
*/
|
||||
|
||||
#define XCPTCONTEXT_REGS (26 + XCPTCONTEXT_XMM_AREA_SIZE / 8)
|
||||
#define XCPTCONTEXT_SIZE (8 * XCPTCONTEXT_REGS + XCPTCONTEXT_XMM_AREA_SIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
enum ioapic_trigger_mode
|
||||
{
|
||||
TRIGGER_RISING_EDGE = 0,
|
||||
TRIGGER_FALLING_EDGE = (1 << 13),
|
||||
TRIGGER_LEVEL_ACTIVE_HIGH = 1 << 15,
|
||||
TRIGGER_LEVEL_ACTIVE_LOW = (1 << 15) | (1 << 13),
|
||||
};
|
||||
|
||||
/* This struct defines the way the registers are stored */
|
||||
|
||||
struct xcptcontext
|
||||
{
|
||||
/* The following function pointer is non-zero if there are pending signals
|
||||
* to be processed.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
void *sigdeliver; /* Actual type is sig_deliver_t */
|
||||
|
||||
/* These are saved copies of instruction pointer and EFLAGS used during
|
||||
* signal processing.
|
||||
*/
|
||||
|
||||
uint64_t saved_rip;
|
||||
uint64_t saved_rflags;
|
||||
uint64_t saved_rsp;
|
||||
#endif
|
||||
|
||||
/* Register save area */
|
||||
|
||||
uint64_t regs[XCPTCONTEXT_REGS] __attribute__((aligned (16)));
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* Name: up_irq_save, up_irq_restore, and friends.
|
||||
*
|
||||
* NOTE: This function should never be called from application code and,
|
||||
* as a general rule unless you really know what you are doing, this
|
||||
* function should not be called directly from operation system code either:
|
||||
* Typically, the wrapper functions, enter_critical_section() and
|
||||
* leave_critical section(), are probably what you really want.
|
||||
*/
|
||||
|
||||
/* Get the current FLAGS register contents */
|
||||
|
||||
static inline irqstate_t irqflags()
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
asm volatile(
|
||||
"\tpushfq\n"
|
||||
"\tpopq %0\n"
|
||||
: "=rm" (flags)
|
||||
:
|
||||
: "memory");
|
||||
return flags;
|
||||
}
|
||||
|
||||
/* Get a sample of the FLAGS register, determine if interrupts are disabled.
|
||||
* If the X86_FLAGS_IF is cleared by cli, then interrupts are disabled. If
|
||||
* if the X86_FLAGS_IF is set by sti, then interrupts are enable.
|
||||
*/
|
||||
|
||||
static inline bool up_irq_disabled(irqstate_t flags)
|
||||
{
|
||||
return ((flags & X86_64_RFLAGS_IF) == 0);
|
||||
}
|
||||
|
||||
static inline bool up_irq_enabled(irqstate_t flags)
|
||||
{
|
||||
return ((flags & X86_64_RFLAGS_IF) != 0);
|
||||
}
|
||||
|
||||
/* Disable interrupts unconditionally */
|
||||
|
||||
static inline void up_irq_disable(void)
|
||||
{
|
||||
asm volatile("cli": : :"memory");
|
||||
}
|
||||
|
||||
/* Enable interrupts unconditionally */
|
||||
|
||||
static inline void up_irq_enable(void)
|
||||
{
|
||||
asm volatile("sti": : :"memory");
|
||||
}
|
||||
|
||||
/* Disable interrupts, but return previous interrupt state */
|
||||
|
||||
static inline irqstate_t up_irq_save(void)
|
||||
{
|
||||
irqstate_t flags = irqflags();
|
||||
up_irq_disable();
|
||||
return flags;
|
||||
}
|
||||
|
||||
/* Conditionally disable interrupts */
|
||||
|
||||
static inline void up_irq_restore(irqstate_t flags)
|
||||
{
|
||||
if (up_irq_enabled(flags))
|
||||
{
|
||||
up_irq_enable();
|
||||
}
|
||||
}
|
||||
|
||||
static inline unsigned int up_apic_cpu_id(void)
|
||||
{
|
||||
return read_msr(MSR_X2APIC_ID);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
void up_ioapic_pin_set_vector(unsigned int pin,
|
||||
enum ioapic_trigger_mode trigger_mode,
|
||||
unsigned int vector);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_X86_INCLUDE_I486_IRQ_H */
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/intel64/limits.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTEL64_LIMITS_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTEL64_LIMITS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define SCHAR_MIN (-SCHAR_MAX - 1)
|
||||
#define SCHAR_MAX 127
|
||||
#define UCHAR_MAX 255
|
||||
|
||||
/* These could be different on machines where char is unsigned */
|
||||
|
||||
#ifdef __CHAR_UNSIGNED__
|
||||
#define CHAR_MIN 0
|
||||
#define CHAR_MAX UCHAR_MAX
|
||||
#else
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#endif
|
||||
|
||||
#define SHRT_MIN (-SHRT_MAX - 1)
|
||||
#define SHRT_MAX 32767
|
||||
#define USHRT_MAX 65535U
|
||||
|
||||
#define INT_MIN (-INT_MAX - 1)
|
||||
#define INT_MAX 2147483647
|
||||
#define UINT_MAX 4294967295U
|
||||
|
||||
/* For 64-bit x86 with Linux ABI, long is identical to long long */
|
||||
|
||||
#define LONG_MIN LLONG_MIN
|
||||
#define LONG_MAX LLONG_MAX
|
||||
#define ULONG_MAX ULLONG_MAX
|
||||
|
||||
#define LLONG_MIN (-LLONG_MAX - 1)
|
||||
#define LLONG_MAX 9223372036854775807LL
|
||||
#define ULLONG_MAX 18446744073709551615ULL
|
||||
|
||||
/* A pointer is 8 bytes */
|
||||
|
||||
#define PTR_MIN (-PTR_MAX - 1)
|
||||
#define PTR_MAX LLONG_MAX
|
||||
#define UPTR_MAX ULLONG_MAX
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_INTEL64_LIMITS_H */
|
||||
@@ -0,0 +1,156 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/intel64/syscall.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through include/syscall.h or include/sys/sycall.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTEL64_SYSCALL_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTEL64_SYSCALL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
void enable_syscall(void);
|
||||
void syscall_entry(void);
|
||||
uint64_t syscall_handler(unsigned long nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
|
||||
uintptr_t parm6);
|
||||
uint64_t linux_interface(unsigned long nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
|
||||
uintptr_t parm6);
|
||||
|
||||
/* SWI with SYS_ call number and six parameters */
|
||||
|
||||
static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
|
||||
uintptr_t parm2, uintptr_t parm3,
|
||||
uintptr_t parm4, uintptr_t parm5,
|
||||
uintptr_t parm6);
|
||||
|
||||
/* SWI with SYS_ call number and no parameters */
|
||||
|
||||
static inline uintptr_t sys_call0(unsigned int nbr)
|
||||
{
|
||||
return sys_call6(nbr, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* SWI with SYS_ call number and one parameter */
|
||||
|
||||
static inline uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)
|
||||
{
|
||||
return sys_call6(nbr, parm1, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* SWI with SYS_ call number and two parameters */
|
||||
|
||||
static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1,
|
||||
uintptr_t parm2)
|
||||
{
|
||||
return sys_call6(nbr, parm1, parm2, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* SWI with SYS_ call number and three parameters */
|
||||
|
||||
static inline uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
|
||||
uintptr_t parm2, uintptr_t parm3)
|
||||
{
|
||||
return sys_call6(nbr, parm1, parm2, parm3, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* SWI with SYS_ call number and four parameters */
|
||||
|
||||
static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1,
|
||||
uintptr_t parm2, uintptr_t parm3,
|
||||
uintptr_t parm4)
|
||||
{
|
||||
return sys_call6(nbr, parm1, parm2, parm3, parm4, 0, 0);
|
||||
}
|
||||
|
||||
/* SWI with SYS_ call number and five parameters */
|
||||
|
||||
static inline uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1,
|
||||
uintptr_t parm2, uintptr_t parm3,
|
||||
uintptr_t parm4, uintptr_t parm5)
|
||||
{
|
||||
return sys_call6(nbr, parm1, parm2, parm3, parm4, parm5, 0);
|
||||
}
|
||||
|
||||
static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
|
||||
uintptr_t parm2, uintptr_t parm3,
|
||||
uintptr_t parm4, uintptr_t parm5,
|
||||
uintptr_t parm6)
|
||||
{
|
||||
register uint64_t reg0 __asm__("rax") = (uint64_t)(nbr);
|
||||
register uint64_t reg1 __asm__("rdi") = (uint64_t)(parm1);
|
||||
register uint64_t reg2 __asm__("rsi") = (uint64_t)(parm2);
|
||||
register uint64_t reg3 __asm__("rdx") = (uint64_t)(parm3);
|
||||
register uint64_t reg4 __asm__("r10") = (uint64_t)(parm4);
|
||||
register uint64_t reg5 __asm__("r8") = (uint64_t)(parm5);
|
||||
register uint64_t reg6 __asm__("r9") = (uint64_t)(parm6);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"syscall"
|
||||
: "=r"(reg0)
|
||||
: "r"(reg0), "r"(reg1), "r"(reg2),
|
||||
"r"(reg3), "r"(reg4), "r"(reg5), "r"(reg6)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_INTEL64_SYSCALL_H */
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/intel64/types.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only
|
||||
* indirectly through arch/types.h (which is, in turn only accessed
|
||||
* through sys/types.h or stdint.h).
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTEL64_TYPES_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTEL64_TYPES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* These are the sizes of the standard integer types. NOTE that these type
|
||||
* names have a leading underscore character. This file will be included
|
||||
* (indirectly) by include/stdint.h and typedef'ed to the final name without
|
||||
* the underscore character. This roundabout way of doings things allows
|
||||
* the stdint.h to be removed from the include/ directory in the event that
|
||||
* the user prefers to use the definitions provided by their toolchain header
|
||||
* files
|
||||
*/
|
||||
|
||||
typedef signed char _int8_t;
|
||||
typedef unsigned char _uint8_t;
|
||||
|
||||
typedef signed short _int16_t;
|
||||
typedef unsigned short _uint16_t;
|
||||
|
||||
typedef signed int _int32_t;
|
||||
typedef unsigned int _uint32_t;
|
||||
|
||||
typedef signed long long _int64_t;
|
||||
typedef unsigned long long _uint64_t;
|
||||
#define __INT64_DEFINED
|
||||
|
||||
/* A pointer is 8 bytes */
|
||||
|
||||
typedef signed long long _intptr_t;
|
||||
typedef unsigned long long _uintptr_t;
|
||||
|
||||
#if defined(__SIZE_TYPE__)
|
||||
/* If __SIZE_TYPE__ is defined we define ssize_t based on size_t.
|
||||
* We simply change "unsigned" to "signed" for this single definition
|
||||
* to make sure ssize_t and size_t only differ by their signedness.
|
||||
*/
|
||||
|
||||
#define unsigned signed
|
||||
typedef __SIZE_TYPE__ _ssize_t;
|
||||
#undef unsigned
|
||||
typedef __SIZE_TYPE__ _size_t;
|
||||
|
||||
#elif defined(CONFIG_ARCH_SIZET_LONG)
|
||||
|
||||
typedef signed long _ssize_t;
|
||||
typedef unsigned long _size_t;
|
||||
|
||||
#else
|
||||
|
||||
typedef signed int _ssize_t;
|
||||
typedef unsigned int _size_t;
|
||||
|
||||
#endif
|
||||
|
||||
/* This is the size of the interrupt state save returned by
|
||||
* up_irq_save()
|
||||
*/
|
||||
|
||||
typedef unsigned long irqstate_t;
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_INTEL64_TYPES_H */
|
||||
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/inttypes.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_INTTYPES_H
|
||||
#define __ARCH_X86_64_INCLUDE_INTTYPES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/inttypes.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_INTTYPES_H */
|
||||
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/io.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_IO_H
|
||||
#define __ARCH_X86_64_INCLUDE_IO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Include architecture-specific IO definitions (These are probably common
|
||||
* across all architectures, but this gives a little bit of flexibility).
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/io.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Inline functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_IO_H */
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/irq.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through nuttx/irq.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_IRQ_H
|
||||
#define __ARCH_X86_64_INCLUDE_IRQ_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Include NuttX-specific IRQ definitions */
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/* Include chip-specific IRQ definitions (including IRQ numbers) */
|
||||
|
||||
#include <arch/chip/irq.h>
|
||||
|
||||
/* Include architecture-specific IRQ definitions (including register save
|
||||
* structure and up_irq_save()/up_irq_restore() macros).
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/irq.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Inline functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_IRQ_H */
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/limits.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_LIMITS_H
|
||||
#define __ARCH_X86_64_INCLUDE_LIMITS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Include architecture-specific limits */
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/limits.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_LIMITS_H */
|
||||
@@ -0,0 +1,438 @@
|
||||
/****************************************************************************
|
||||
* multiboot2.h - Multiboot 2 header file.
|
||||
*
|
||||
* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
|
||||
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_MULTIBOOT2_H
|
||||
#define __ARCH_X86_64_INCLUDE_MULTIBOOT2_H 1
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* How many bytes from the start of the file we search for the header. */
|
||||
|
||||
#define MULTIBOOT_SEARCH 32768
|
||||
#define MULTIBOOT_HEADER_ALIGN 8
|
||||
|
||||
/* The magic field should contain this. */
|
||||
|
||||
#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
|
||||
|
||||
/* This should be in %eax. */
|
||||
|
||||
#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
|
||||
|
||||
/* Alignment of multiboot modules. */
|
||||
|
||||
#define MULTIBOOT_MOD_ALIGN 0x00001000
|
||||
|
||||
/* Alignment of the multiboot info structure. */
|
||||
|
||||
#define MULTIBOOT_INFO_ALIGN 0x00000008
|
||||
|
||||
/* Flags set in the ’flags’ member of the multiboot header. */
|
||||
|
||||
#define MULTIBOOT_TAG_ALIGN 8
|
||||
#define MULTIBOOT_TAG_TYPE_END 0
|
||||
#define MULTIBOOT_TAG_TYPE_CMDLINE 1
|
||||
#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2
|
||||
#define MULTIBOOT_TAG_TYPE_MODULE 3
|
||||
#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4
|
||||
#define MULTIBOOT_TAG_TYPE_BOOTDEV 5
|
||||
#define MULTIBOOT_TAG_TYPE_MMAP 6
|
||||
#define MULTIBOOT_TAG_TYPE_VBE 7
|
||||
#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8
|
||||
#define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9
|
||||
#define MULTIBOOT_TAG_TYPE_APM 10
|
||||
#define MULTIBOOT_TAG_TYPE_EFI32 11
|
||||
#define MULTIBOOT_TAG_TYPE_EFI64 12
|
||||
#define MULTIBOOT_TAG_TYPE_SMBIOS 13
|
||||
#define MULTIBOOT_TAG_TYPE_ACPI_OLD 14
|
||||
#define MULTIBOOT_TAG_TYPE_ACPI_NEW 15
|
||||
#define MULTIBOOT_TAG_TYPE_NETWORK 16
|
||||
#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17
|
||||
#define MULTIBOOT_TAG_TYPE_EFI_BS 18
|
||||
#define MULTIBOOT_TAG_TYPE_EFI32_IH 19
|
||||
#define MULTIBOOT_TAG_TYPE_EFI64_IH 20
|
||||
#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21
|
||||
|
||||
#define MULTIBOOT_HEADER_TAG_END 0
|
||||
#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
|
||||
#define MULTIBOOT_HEADER_TAG_ADDRESS 2
|
||||
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3
|
||||
#define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
|
||||
#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
|
||||
#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
|
||||
#define MULTIBOOT_HEADER_TAG_EFI_BS 7
|
||||
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32 8
|
||||
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9
|
||||
#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10
|
||||
|
||||
#define MULTIBOOT_ARCHITECTURE_I386 0
|
||||
#define MULTIBOOT_ARCHITECTURE_MIPS32 4
|
||||
#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
|
||||
|
||||
#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
|
||||
#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
|
||||
#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
|
||||
|
||||
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
|
||||
#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
typedef unsigned char multiboot_uint8_t;
|
||||
typedef unsigned short multiboot_uint16_t;
|
||||
typedef unsigned int multiboot_uint32_t;
|
||||
typedef unsigned long long multiboot_uint64_t;
|
||||
|
||||
struct multiboot_header
|
||||
{
|
||||
/* Must be MULTIBOOT_MAGIC - see above. */
|
||||
|
||||
multiboot_uint32_t magic;
|
||||
|
||||
/* ISA */
|
||||
|
||||
multiboot_uint32_t architecture;
|
||||
|
||||
/* Total header length. */
|
||||
|
||||
multiboot_uint32_t header_length;
|
||||
|
||||
/* The above fields plus this one must equal 0 mod 2^32. */
|
||||
|
||||
multiboot_uint32_t checksum;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_information_request
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t requests[0];
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_address
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t header_addr;
|
||||
multiboot_uint32_t load_addr;
|
||||
multiboot_uint32_t load_end_addr;
|
||||
multiboot_uint32_t bss_end_addr;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_entry_address
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t entry_addr;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_console_flags
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t console_flags;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_framebuffer
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t width;
|
||||
multiboot_uint32_t height;
|
||||
multiboot_uint32_t depth;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_module_align
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_relocatable
|
||||
{
|
||||
multiboot_uint16_t type;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t min_addr;
|
||||
multiboot_uint32_t max_addr;
|
||||
multiboot_uint32_t align;
|
||||
multiboot_uint32_t preference;
|
||||
};
|
||||
|
||||
struct multiboot_color
|
||||
{
|
||||
multiboot_uint8_t red;
|
||||
multiboot_uint8_t green;
|
||||
multiboot_uint8_t blue;
|
||||
};
|
||||
|
||||
struct multiboot_mmap_entry
|
||||
{
|
||||
multiboot_uint64_t addr;
|
||||
multiboot_uint64_t len;
|
||||
#define MULTIBOOT_MEMORY_AVAILABLE 1
|
||||
#define MULTIBOOT_MEMORY_RESERVED 2
|
||||
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
|
||||
#define MULTIBOOT_MEMORY_NVS 4
|
||||
#define MULTIBOOT_MEMORY_BADRAM 5
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t zero;
|
||||
};
|
||||
|
||||
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
|
||||
|
||||
struct multiboot_tag
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
};
|
||||
|
||||
struct multiboot_tag_string
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
char string[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_module
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t mod_start;
|
||||
multiboot_uint32_t mod_end;
|
||||
char cmdline[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_basic_meminfo
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t mem_lower;
|
||||
multiboot_uint32_t mem_upper;
|
||||
};
|
||||
|
||||
struct multiboot_tag_bootdev
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t biosdev;
|
||||
multiboot_uint32_t slice;
|
||||
multiboot_uint32_t part;
|
||||
};
|
||||
|
||||
struct multiboot_tag_mmap
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t entry_size;
|
||||
multiboot_uint32_t entry_version;
|
||||
struct multiboot_mmap_entry entries[0];
|
||||
};
|
||||
|
||||
struct multiboot_vbe_info_block
|
||||
{
|
||||
multiboot_uint8_t external_specification[512];
|
||||
};
|
||||
|
||||
struct multiboot_vbe_mode_info_block
|
||||
{
|
||||
multiboot_uint8_t external_specification[256];
|
||||
};
|
||||
|
||||
struct multiboot_tag_vbe
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
|
||||
multiboot_uint16_t vbe_mode;
|
||||
multiboot_uint16_t vbe_interface_seg;
|
||||
multiboot_uint16_t vbe_interface_off;
|
||||
multiboot_uint16_t vbe_interface_len;
|
||||
|
||||
struct multiboot_vbe_info_block vbe_control_info;
|
||||
struct multiboot_vbe_mode_info_block vbe_mode_info;
|
||||
};
|
||||
|
||||
struct multiboot_tag_framebuffer_common
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
|
||||
multiboot_uint64_t framebuffer_addr;
|
||||
multiboot_uint32_t framebuffer_pitch;
|
||||
multiboot_uint32_t framebuffer_width;
|
||||
multiboot_uint32_t framebuffer_height;
|
||||
multiboot_uint8_t framebuffer_bpp;
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
|
||||
multiboot_uint8_t framebuffer_type;
|
||||
multiboot_uint16_t reserved;
|
||||
};
|
||||
|
||||
struct multiboot_tag_framebuffer
|
||||
{
|
||||
struct multiboot_tag_framebuffer_common common;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
multiboot_uint16_t framebuffer_palette_num_colors;
|
||||
struct multiboot_color framebuffer_palette[0];
|
||||
};
|
||||
struct
|
||||
{
|
||||
multiboot_uint8_t framebuffer_red_field_position;
|
||||
multiboot_uint8_t framebuffer_red_mask_size;
|
||||
multiboot_uint8_t framebuffer_green_field_position;
|
||||
multiboot_uint8_t framebuffer_green_mask_size;
|
||||
multiboot_uint8_t framebuffer_blue_field_position;
|
||||
multiboot_uint8_t framebuffer_blue_mask_size;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct multiboot_tag_elf_sections
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t num;
|
||||
multiboot_uint32_t entsize;
|
||||
multiboot_uint32_t shndx;
|
||||
char sections[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_apm
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint16_t version;
|
||||
multiboot_uint16_t cseg;
|
||||
multiboot_uint32_t offset;
|
||||
multiboot_uint16_t cseg_16;
|
||||
multiboot_uint16_t dseg;
|
||||
multiboot_uint16_t flags;
|
||||
multiboot_uint16_t cseg_len;
|
||||
multiboot_uint16_t cseg_16_len;
|
||||
multiboot_uint16_t dseg_len;
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi32
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi64
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint64_t pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_smbios
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint8_t major;
|
||||
multiboot_uint8_t minor;
|
||||
multiboot_uint8_t reserved[6];
|
||||
multiboot_uint8_t tables[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_old_acpi
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint8_t rsdp[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_new_acpi
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint8_t rsdp[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_network
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint8_t dhcpack[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi_mmap
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t descr_size;
|
||||
multiboot_uint32_t descr_vers;
|
||||
multiboot_uint8_t efi_mmap[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi32_ih
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi64_ih
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint64_t pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_load_base_addr
|
||||
{
|
||||
multiboot_uint32_t type;
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t load_base_addr;
|
||||
};
|
||||
|
||||
#endif /* !ASM_FILE */
|
||||
|
||||
#endif /* !__ARCH_X86_64_INCLUDE_MULTIBOOT2_H */
|
||||
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/syscall.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through include/syscall.h or include/sys/sycall.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_SYSCALL_H
|
||||
#define __ARCH_X86_64_INCLUDE_SYSCALL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Include x86 architecture-specific syscall macros */
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/syscall.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Inline functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_SYSCALL_H */
|
||||
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/types.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* This file should never be included directed but, rather, only indirectly
|
||||
* through sys/types.h
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_TYPES_H
|
||||
#define __ARCH_X86_64_INCLUDE_TYPES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Include architecture-specific limits */
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64
|
||||
# include <arch/intel64/types.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __ARCH_X86_64_INCLUDE_TYPES_H */
|
||||
@@ -0,0 +1,4 @@
|
||||
/chip
|
||||
/board
|
||||
/.depend
|
||||
/Make.dep
|
||||
@@ -0,0 +1,184 @@
|
||||
############################################################################
|
||||
# arch/x86_64/src/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
-include chip/Make.defs
|
||||
|
||||
ifeq ($(CONFIG_ARCH_INTEL64),y)
|
||||
ARCH_SUBDIR = intel64
|
||||
endif
|
||||
|
||||
CPPFLAGS += $(EXTRADEFINES)
|
||||
CFLAGS += $(EXTRADEFINES)
|
||||
CXXFLAGS += $(EXTRADEFINES)
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
ARCH_SRCDIR = $(TOPDIR)\arch\$(CONFIG_ARCH)\src
|
||||
NUTTX = $(TOPDIR)\nuttx$(EXEEXT)
|
||||
CFLAGS += -I$(ARCH_SRCDIR)\chip
|
||||
CFLAGS += -I$(ARCH_SRCDIR)\common
|
||||
CFLAGS += -I$(ARCH_SRCDIR)\$(ARCH_SUBDIR)
|
||||
CFLAGS += -I$(TOPDIR)\sched
|
||||
else
|
||||
ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src
|
||||
ifeq ($(WINTOOL),y)
|
||||
NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx$(EXEEXT)}"
|
||||
CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}"
|
||||
CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/common}"
|
||||
CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}"
|
||||
CFLAGS += -I "${shell cygpath -w $(TOPDIR)/sched}"
|
||||
else
|
||||
NUTTX = $(TOPDIR)/nuttx$(EXEEXT)
|
||||
LOADER = $(TOPDIR)/loader$(EXEEXT)
|
||||
CFLAGS += -I$(ARCH_SRCDIR)/chip
|
||||
CFLAGS += -I$(ARCH_SRCDIR)/common
|
||||
CFLAGS += -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR)
|
||||
CFLAGS += -I$(TOPDIR)/sched
|
||||
endif
|
||||
endif
|
||||
|
||||
ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS)
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
|
||||
CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS)
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
KBIN = libkarch$(LIBEXT)
|
||||
UBIN = libuarch$(LIBEXT)
|
||||
BIN = libarch$(LIBEXT)
|
||||
|
||||
# Override in Make.defs if linker is not 'ld'
|
||||
|
||||
LDSTARTGROUP ?= --start-group
|
||||
LDENDGROUP ?= --end-group
|
||||
|
||||
LDFLAGS += -z max-page-size=0x1000 $(ARCHSCRIPT)
|
||||
LOADER_LDFLAGS += $(LOADER_ARCHSCRIPT)
|
||||
EXTRA_LIBS ?=
|
||||
LINKLIBS ?=
|
||||
|
||||
OBJCOPYARGS =
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
BOARDMAKE = $(if $(wildcard .\board\Makefile),y,)
|
||||
LIBPATHS += -L"$(TOPDIR)\staging"
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
LIBPATHS += -L"$(TOPDIR)\arch\$(CONFIG_ARCH)\src\board"
|
||||
endif
|
||||
|
||||
else
|
||||
BOARDMAKE = $(if $(wildcard ./board/Makefile),y,)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/staging"}"
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"}"
|
||||
endif
|
||||
|
||||
else
|
||||
LIBPATHS += -L"$(TOPDIR)/staging"
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
LIBPATHS += -L"$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS)))
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
LDLIBS += -lboard
|
||||
endif
|
||||
|
||||
LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}"
|
||||
|
||||
ifeq ($(HOSTOS),FreeBSD)
|
||||
HOST_ARCH = ${shell uname -m 2>/dev/null || echo "Other"}
|
||||
endif
|
||||
|
||||
VPATH = chip:common:$(ARCH_SUBDIR)
|
||||
|
||||
all: libarch$(LIBEXT)
|
||||
|
||||
.PHONY: board/libboard$(LIBEXT)
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(BIN) $(KBIN): $(OBJS)
|
||||
$(call ARCHIVE, $@, $(OBJS))
|
||||
|
||||
$(UBIN): $(UOBJS)
|
||||
$(call ARCHIVE, $@, $(UOBJS))
|
||||
|
||||
board/libboard$(LIBEXT):
|
||||
$(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES)
|
||||
|
||||
nuttx$(EXEEXT): board/libboard$(LIBEXT)
|
||||
@echo "LD: nuttx$(EXEEXT)"
|
||||
$(Q) $(LD) $(LDFLAGS) $(LIBPATHS) -o $(NUTTX) $(EXTRA_OBJS) \
|
||||
$(LDSTARTGROUP) $(LIBGCC) --whole-archive $(LDLIBS) $(EXTRA_LIBS) $(LDENDGROUP)
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
$(Q) $(NM) $(NUTTX) | \
|
||||
grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
|
||||
sort > $(TOPDIR)/System.map
|
||||
endif
|
||||
|
||||
# This is part of the top-level export target
|
||||
|
||||
export_startup: board/libboard$(LIBEXT) $(STARTUP_OBJS)
|
||||
$(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \
|
||||
cp -f $(STARTUP_OBJS) "$(EXPORT_DIR)/startup"; \
|
||||
else \
|
||||
echo "$(EXPORT_DIR)/startup does not exist"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# Dependencies
|
||||
|
||||
.depend: Makefile chip/Make.defs $(SRCS)
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
$(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" depend
|
||||
endif
|
||||
$(Q) $(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \
|
||||
"$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
$(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" clean
|
||||
endif
|
||||
$(call DELFILE, libarch$(LIBEXT))
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
ifeq ($(BOARDMAKE),y)
|
||||
$(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean
|
||||
endif
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,31 @@
|
||||
arch/x86/src/README.txt
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This directory holds x86_64-specific source files. All x86 source reside in
|
||||
lower-level common, chip-specific, and architecture-specific directories.
|
||||
|
||||
common/ Directory
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
This directory holds source files common to all x86_64 architectures.
|
||||
|
||||
Architecture-Specific Directories
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Architecture-specific directories hold common source files shared for by
|
||||
implementations of specific x86_64 architectures.
|
||||
|
||||
intel64
|
||||
This directory holds logic appropriate for any instantiation of the 64-bit
|
||||
intel64 architecture.
|
||||
|
||||
Chip-Specific directories
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The same x86 architecture may be realized in different chip implementations.
|
||||
For SoC chips, in particular, on-chip devices and differing interrupt
|
||||
structures may require special, chip-specific definitions in these chip-
|
||||
specific directories.
|
||||
|
||||
broadwell
|
||||
This is the implementation of NuttX on the Intel Broadwell processors.
|
||||
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
if ARCH_X86_64
|
||||
comment "Common Configuration Options"
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_allocateheap.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_allocate_heap
|
||||
*
|
||||
* Description:
|
||||
* This function will be called to dynamically set aside the heap region.
|
||||
*
|
||||
* For the kernel build (CONFIG_BUILD_KERNEL=y) with both kernel- and
|
||||
* user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the
|
||||
* size of the unprotected, user-space heap.
|
||||
*
|
||||
* If a protected kernel-space heap is provided, the kernel heap must be
|
||||
* allocated (and protected) by an analogous up_allocate_kheap().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
|
||||
{
|
||||
board_autoled_on(LED_HEAPALLOCATE);
|
||||
|
||||
// Calculate the end of .bss section
|
||||
uintptr_t hstart = (((uintptr_t)&_ebss + PAGE_SIZE - 1) & PAGE_MASK);
|
||||
*heap_start = (void*)hstart;
|
||||
|
||||
// The size is the rest of the RAM
|
||||
*heap_size = (size_t)(CONFIG_RAM_SIZE - (hstart - 0x100000000 - 1));
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_arch.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef ___ARCH_X86_64_SRC_COMMON_UP_ARCH_H
|
||||
#define ___ARCH_X86_64_SRC_COMMON_UP_ARCH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#include <arch/io.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
# define getreg8(p) inb(p)
|
||||
# define putreg8(v,p) outb(v,p)
|
||||
# define getreg16(p) inw(p)
|
||||
# define putreg16(v,p) outw(v,p)
|
||||
# define getreg32(p) inl(p)
|
||||
# define putreg32(v,p) outl(v,p)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Atomic modification of registers */
|
||||
|
||||
void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits);
|
||||
void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits);
|
||||
void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* ___ARCH_X86_64_SRC_COMMON_UP_ARCH_H */
|
||||
@@ -0,0 +1,267 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_assert.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <arch/arch.h>
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/usb/usbdev_trace.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "sched/sched.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* USB trace dumping */
|
||||
|
||||
#ifndef CONFIG_USBDEV_TRACE
|
||||
# undef CONFIG_ARCH_USBDUMP
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_stackdump
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_STACKDUMP
|
||||
static void up_stackdump(uint64_t sp, uint64_t stack_base)
|
||||
{
|
||||
uint64_t stack ;
|
||||
|
||||
for (stack = sp & ~0x1f; stack < stack_base; stack += 32)
|
||||
{
|
||||
uint32_t *ptr = (uint32_t *)stack;
|
||||
_alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||
stack, ptr[0], ptr[1], ptr[2], ptr[3],
|
||||
ptr[4], ptr[5], ptr[6], ptr[7]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define up_stackdump()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: assert_tracecallback
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_USBDUMP
|
||||
static int usbtrace_syslog(FAR const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
/* Let nx_vsyslog do the real work */
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = nx_vsyslog(LOG_EMERG, fmt, &ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg)
|
||||
{
|
||||
usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_dumpstate
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_STACKDUMP
|
||||
static void up_dumpstate(void)
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
uint64_t sp = up_getrsp();
|
||||
uint64_t ustackbase;
|
||||
uint64_t ustacksize;
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
||||
uint64_t istackbase;
|
||||
uint64_t istacksize;
|
||||
#endif
|
||||
|
||||
/* Get the limits on the user stack memory */
|
||||
|
||||
if (rtcb->pid == 0)
|
||||
{
|
||||
ustackbase = g_idle_topstack - 8;
|
||||
ustacksize = CONFIG_IDLETHREAD_STACKSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ustackbase = (uint64_t)rtcb->adj_stack_ptr;
|
||||
ustacksize = (uint64_t)rtcb->adj_stack_size;
|
||||
}
|
||||
|
||||
/* Get the limits on the interrupt stack memory */
|
||||
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
||||
istackbase = (uint64_t)&g_intstackbase;
|
||||
istacksize = (CONFIG_ARCH_INTERRUPTSTACK & ~3) - 8;
|
||||
|
||||
/* Show interrupt stack info */
|
||||
|
||||
_alert("sp: %016x\n", sp);
|
||||
_alert("IRQ stack:\n");
|
||||
_alert(" base: %016x\n", istackbase);
|
||||
_alert(" size: %016x\n", istacksize);
|
||||
|
||||
/* Does the current stack pointer lie within the interrupt
|
||||
* stack?
|
||||
*/
|
||||
|
||||
if (sp <= istackbase && sp > istackbase - istacksize)
|
||||
{
|
||||
/* Yes.. dump the interrupt stack */
|
||||
|
||||
up_stackdump(sp, istackbase);
|
||||
|
||||
/* Extract the user stack pointer which should lie
|
||||
* at the base of the interrupt stack.
|
||||
*/
|
||||
|
||||
sp = g_intstackbase;
|
||||
_alert("sp: %016x\n", sp);
|
||||
}
|
||||
|
||||
/* Show user stack info */
|
||||
|
||||
_alert("User stack:\n");
|
||||
_alert(" base: %016x\n", ustackbase);
|
||||
_alert(" size: %016x\n", ustacksize);
|
||||
#else
|
||||
_alert("sp: %016x\n", sp);
|
||||
_alert("stack base: %016x\n", ustackbase);
|
||||
_alert("stack size: %016x\n", ustacksize);
|
||||
#endif
|
||||
|
||||
/* Dump the user stack if the stack pointer lies within the allocated user
|
||||
* stack memory.
|
||||
*/
|
||||
|
||||
if (sp > ustackbase || sp <= ustackbase - ustacksize)
|
||||
{
|
||||
#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4
|
||||
_alert("ERROR: Stack pointer is not within allocated stack\n");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
up_stackdump(sp, ustackbase);
|
||||
}
|
||||
|
||||
/* Then dump the registers (if available) */
|
||||
|
||||
if (g_current_regs != NULL)
|
||||
{
|
||||
up_registerdump((uint64_t *)g_current_regs);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ARCH_USBDUMP
|
||||
/* Dump USB trace data */
|
||||
|
||||
(void)usbtrace_enumerate(assert_tracecallback, NULL);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
# define up_dumpstate()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: _up_assert
|
||||
****************************************************************************/
|
||||
|
||||
static void _up_assert(int errorcode) noreturn_function;
|
||||
static void _up_assert(int errorcode)
|
||||
{
|
||||
/* Are we in an interrupt handler or the idle task? */
|
||||
|
||||
if (g_current_regs || (this_task())->pid == 0)
|
||||
{
|
||||
(void)up_irq_save();
|
||||
for (; ; )
|
||||
{
|
||||
#ifdef CONFIG_ARCH_LEDS
|
||||
board_autoled_on(LED_PANIC);
|
||||
up_mdelay(250);
|
||||
board_autoled_off(LED_PANIC);
|
||||
up_mdelay(250);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(errorcode);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_assert
|
||||
****************************************************************************/
|
||||
|
||||
void up_assert(const uint8_t *filename, int lineno)
|
||||
{
|
||||
#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_DEBUG_ALERT)
|
||||
struct tcb_s *rtcb = this_task();
|
||||
#endif
|
||||
|
||||
board_autoled_on(LED_ASSERTION);
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
_alert("Assertion failed at file:%s line: %d task: %s\n",
|
||||
filename, lineno, rtcb->name);
|
||||
#else
|
||||
_alert("Assertion failed at file:%s line: %d\n",
|
||||
filename, lineno);
|
||||
#endif
|
||||
|
||||
up_dumpstate();
|
||||
|
||||
#ifdef CONFIG_BOARD_CRASHDUMP
|
||||
board_crashdump(up_getrsp(), this_task(), filename, lineno);
|
||||
#endif
|
||||
|
||||
_up_assert(EXIT_FAILURE);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_blocktask.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_block_task
|
||||
*
|
||||
* Description:
|
||||
* The currently executing task at the head of the ready to run list must
|
||||
* be stopped. Save its context and move it to the inactive list specified
|
||||
* by task_state.
|
||||
*
|
||||
* Input Parameters:
|
||||
* tcb: Refers to a task in the ready-to-run list (normally the task at the
|
||||
* head of the list). It most be stopped, its context saved and moved
|
||||
* into one of the waiting task lists. It it was the task at the head
|
||||
* of the ready-to-run list, then a context to the new ready to run task
|
||||
* must be performed.
|
||||
* task_state: Specifies which waiting task list should be
|
||||
* hold the blocked task TCB.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_block_task(struct tcb_s *tcb, tstate_t task_state)
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
bool switch_needed;
|
||||
|
||||
/* Verify that the context switch can be performed */
|
||||
|
||||
ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) &&
|
||||
(tcb->task_state <= LAST_READY_TO_RUN_STATE));
|
||||
|
||||
/* Remove the tcb task from the ready-to-run list. If we
|
||||
* are blocking the task at the head of the task list (the
|
||||
* most likely case), then a context switch to the next
|
||||
* ready-to-run task is needed. In this case, it should
|
||||
* also be true that rtcb == tcb.
|
||||
*/
|
||||
|
||||
switch_needed = sched_removereadytorun(tcb);
|
||||
|
||||
/* Add the task to the specified blocked task list */
|
||||
|
||||
sched_addblocked(tcb, (tstate_t)task_state);
|
||||
|
||||
/* If there are any pending tasks, then add them to the ready-to-run
|
||||
* task list now
|
||||
*/
|
||||
|
||||
if (g_pendingtasks.head)
|
||||
{
|
||||
switch_needed |= sched_mergepending();
|
||||
}
|
||||
|
||||
/* Now, perform the context switch if one is needed */
|
||||
|
||||
if (switch_needed)
|
||||
{
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_suspend_scheduler(rtcb);
|
||||
|
||||
/* Are we in an interrupt handler? */
|
||||
|
||||
if (g_current_regs)
|
||||
{
|
||||
/* Yes, then we have to do things differently.
|
||||
* Just copy the g_current_regs into the OLD rtcb.
|
||||
*/
|
||||
|
||||
up_savestate(rtcb->xcp.regs);
|
||||
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts. Any necessary address environment
|
||||
* changes will be made when the interrupt returns.
|
||||
*/
|
||||
|
||||
up_restorestate(rtcb->xcp.regs);
|
||||
}
|
||||
|
||||
/* Copy the user C context into the TCB at the (old) head of the
|
||||
* ready-to-run Task list. if up_saveusercontext returns a non-zero
|
||||
* value, then this is really the previously running task restarting!
|
||||
*/
|
||||
|
||||
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||
{
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Make sure that the address environment for the previously
|
||||
* running task is closed down gracefully (data caches dump,
|
||||
* MMU flushed) and set up the address environment for the new
|
||||
* thread at the head of the ready-to-run list.
|
||||
*/
|
||||
|
||||
(void)group_addrenv(rtcb);
|
||||
#endif
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_fullcontextrestore(rtcb->xcp.regs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_copystate.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_undefinedinsn
|
||||
****************************************************************************/
|
||||
|
||||
/* A little faster than most memcpy's */
|
||||
|
||||
void up_copystate(uint64_t *dest, uint64_t *src)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < XCPTCONTEXT_REGS; i++)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/****************************************************************************
|
||||
* common/up_exit.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/irq.h>
|
||||
#ifdef CONFIG_DUMP_ON_EXIT
|
||||
# include <nuttx/fs/fs.h>
|
||||
#endif
|
||||
|
||||
#include "task/task.h"
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DEBUG_SCHED_INFO
|
||||
# undef CONFIG_DUMP_ON_EXIT
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: _up_dumponexit
|
||||
*
|
||||
* Description:
|
||||
* Dump the state of all tasks whenever on task exits. This is debug
|
||||
* instrumentation that was added to check file-related reference counting
|
||||
* but could be useful again sometime in the future.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DUMP_ON_EXIT
|
||||
static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg)
|
||||
{
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
FAR struct filelist *filelist;
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
FAR struct streamlist *streamlist;
|
||||
#endif
|
||||
int i;
|
||||
#endif
|
||||
|
||||
sinfo(" TCB=%p name=%s pid=%d\n", tcb, tcb->argv[0], tcb->pid);
|
||||
sinfo(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
filelist = tcb->group->tg_filelist;
|
||||
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
|
||||
{
|
||||
struct inode *inode = filelist->fl_files[i].f_inode;
|
||||
if (inode)
|
||||
{
|
||||
sinfo(" fd=%d refcount=%d\n",
|
||||
i, inode->i_crefs);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
streamlist = tcb->group->tg_streamlist;
|
||||
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
|
||||
{
|
||||
struct file_struct *filep = &streamlist->sl_streams[i];
|
||||
if (filep->fs_fd >= 0)
|
||||
{
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
if (filep->fs_bufstart != NULL)
|
||||
{
|
||||
sinfo(" fd=%d nbytes=%d\n",
|
||||
filep->fs_fd,
|
||||
filep->fs_bufpos - filep->fs_bufstart);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sinfo(" fd=%d\n", filep->fs_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: _exit
|
||||
*
|
||||
* Description:
|
||||
* This function causes the currently executing task to cease to exist.
|
||||
* This is a special case of task_delete() where the task to be deleted is
|
||||
* the currently executing task. It is more complex because a context
|
||||
* switch must be perform to the next ready to run task.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void _exit(int status)
|
||||
{
|
||||
struct tcb_s *tcb;
|
||||
|
||||
/* Make sure that we are in a critical section with local interrupts.
|
||||
* The IRQ state will be restored when the next task is started.
|
||||
*/
|
||||
|
||||
(void)enter_critical_section();
|
||||
|
||||
sinfo("TCB=%p exiting\n", this_task());
|
||||
|
||||
#ifdef CONFIG_DUMP_ON_EXIT
|
||||
sinfo("Other tasks:\n");
|
||||
sched_foreach(_up_dumponexit, NULL);
|
||||
#endif
|
||||
|
||||
/* Destroy the task at the head of the ready to run list. */
|
||||
|
||||
(void)nxtask_exit();
|
||||
|
||||
/* Now, perform the context switch to the new ready-to-run task at the
|
||||
* head of the list.
|
||||
*/
|
||||
|
||||
tcb = this_task();
|
||||
|
||||
/* Context switch, rearrange MMU */
|
||||
|
||||
up_restore_auxstate(tcb);
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Make sure that the address environment for the previously running
|
||||
* task is closed down gracefully (data caches dump, MMU flushed) and
|
||||
* set up the address environment for the new thread at the head of
|
||||
* the ready-to-run list.
|
||||
*/
|
||||
|
||||
(void)group_addrenv(tcb);
|
||||
#endif
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_fullcontextrestore(tcb->xcp.regs);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_initialize.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/sched_note.h>
|
||||
#include <nuttx/mm/iob.h>
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#include <nuttx/fs/loop.h>
|
||||
#include <nuttx/net/loopback.h>
|
||||
#include <nuttx/net/tun.h>
|
||||
#include <nuttx/net/telnet.h>
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/syslog/syslog_console.h>
|
||||
#include <nuttx/serial/pty.h>
|
||||
#include <nuttx/crypto/crypto.h>
|
||||
#include <nuttx/power/pm.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_calibratedelay
|
||||
*
|
||||
* Description:
|
||||
* Delay loops are provided for short timing loops. This function, if
|
||||
* enabled, will just wait for 100 seconds. Using a stopwatch, you can
|
||||
* can then determine if the timing loops are properly calibrated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ARCH_CALIBRATION) && defined(CONFIG_DEBUG_FEATURES)
|
||||
static void up_calibratedelay(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
_warn("Beginning 100s delay\n");
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
up_mdelay(1000);
|
||||
}
|
||||
|
||||
_warn("End 100s delay\n");
|
||||
}
|
||||
#else
|
||||
# define up_calibratedelay()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_initialize
|
||||
*
|
||||
* Description:
|
||||
* up_initialize will be called once during OS initialization after the
|
||||
* basic OS services have been initialized. The architecture specific
|
||||
* details of initializing the OS will be handled here. Such things as
|
||||
* setting up interrupt service routines, starting the clock, and
|
||||
* registering device drivers are some of the things that are different
|
||||
* for each processor and hardware platform.
|
||||
*
|
||||
* up_initialize is called after the OS initialized but before the user
|
||||
* initialization logic has been started and before the libraries have
|
||||
* been initialized. OS services and driver services are available.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_initialize(void)
|
||||
{
|
||||
/* Initialize global variables */
|
||||
|
||||
g_current_regs = NULL;
|
||||
|
||||
/* Add any extra memory fragments to the memory manager */
|
||||
|
||||
up_addregion();
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
/* Initialize the power management subsystem. This MCU-specific function
|
||||
* must be called *very* early in the initialization sequence *before* any
|
||||
* other device drivers are initialized (since they may attempt to register
|
||||
* with the power management subsystem).
|
||||
*/
|
||||
|
||||
up_pminitialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_DMA
|
||||
/* Initialize the DMA subsystem if the weak function up_dma_initialize has been
|
||||
* brought into the build
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
||||
if (up_dma_initialize)
|
||||
#endif
|
||||
{
|
||||
up_dma_initialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Register devices */
|
||||
|
||||
#if defined(CONFIG_DEV_NULL)
|
||||
devnull_register(); /* Standard /dev/null */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DEV_RANDOM)
|
||||
devrandom_register(); /* Standard /dev/random */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DEV_URANDOM)
|
||||
devurandom_register(); /* Standard /dev/urandom */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DEV_ZERO)
|
||||
devzero_register(); /* Standard /dev/zero */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DEV_LOOP)
|
||||
loop_register(); /* Standard /dev/loop */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \
|
||||
defined(CONFIG_DRIVER_NOTE)
|
||||
note_register(); /* Non-standard /dev/note */
|
||||
#endif
|
||||
|
||||
/* Initialize the serial device driver */
|
||||
|
||||
#ifdef USE_SERIALDRIVER
|
||||
up_serialinit();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RPMSG_UART
|
||||
rpmsg_serialinit();
|
||||
#endif
|
||||
|
||||
/* Initialize the console device driver (if it is other than the standard
|
||||
* serial driver).
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_CONSOLE_SYSLOG)
|
||||
syslog_console_init();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PSEUDOTERM_SUSV1
|
||||
/* Register the master pseudo-terminal multiplexor device */
|
||||
|
||||
ptmx_register();
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CRYPTO)
|
||||
/* Initialize the HW crypto and /dev/crypto */
|
||||
|
||||
up_cryptoinitialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CRYPTO_CRYPTODEV
|
||||
devcrypto_register();
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NETDEV_LATEINIT
|
||||
/* Initialize the network */
|
||||
|
||||
up_netinitialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_LOOPBACK
|
||||
/* Initialize the local loopback device */
|
||||
|
||||
localhost_initialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_TUN
|
||||
/* Initialize the TUN device */
|
||||
|
||||
tun_initialize();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETDEV_TELNET
|
||||
/* Initialize the Telnet session factory */
|
||||
|
||||
telnet_initialize();
|
||||
#endif
|
||||
|
||||
/* Initialize USB -- device and/or host */
|
||||
|
||||
up_usbinitialize();
|
||||
board_autoled_on(LED_IRQSENABLED);
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_internal.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_SRC_COMMON_UP_INTERNAL_H
|
||||
#define __ARCH_X86_64_SRC_COMMON_UP_INTERNAL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <nuttx/compiler.h>
|
||||
# include <nuttx/sched.h>
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Bring-up debug configurations. These are here (vs defconfig) because
|
||||
* these should only be controlled during low level board bring-up and not
|
||||
* part of normal platform configuration.
|
||||
*/
|
||||
|
||||
#undef CONFIG_SUPPRESS_INTERRUPTS /* DEFINED: Do not enable interrupts */
|
||||
#undef CONFIG_SUPPRESS_TIMER_INTS /* DEFINED: No timer */
|
||||
#undef CONFIG_SUPPRESS_SERIAL_INTS /* DEFINED: Console will poll */
|
||||
#undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfig UART */
|
||||
#undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */
|
||||
|
||||
#ifndef CONFIG_DEBUG_SCHED_INFO
|
||||
# undef CONFIG_DUMP_ON_EXIT /* Needs CONFIG_DEBUG_SCHED_INFO */
|
||||
#endif
|
||||
|
||||
/* Determine which (if any) console driver to use. If a console is enabled
|
||||
* and no other console device is specified, then a serial console is
|
||||
* assumed.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0
|
||||
# undef USE_SERIALDRIVER
|
||||
# undef USE_EARLYSERIALINIT
|
||||
# undef CONFIG_DEV_LOWCONSOLE
|
||||
# undef CONFIG_RAMLOG_CONSOLE
|
||||
#else
|
||||
# if defined(CONFIG_RAMLOG_CONSOLE)
|
||||
# undef USE_SERIALDRIVER
|
||||
# undef USE_EARLYSERIALINIT
|
||||
# undef CONFIG_DEV_LOWCONSOLE
|
||||
# else
|
||||
# define USE_SERIALDRIVER 1
|
||||
# define USE_EARLYSERIALINIT 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If some other device is used as the console, then the serial driver may
|
||||
* still be needed. Let's assume that if the upper half serial driver is
|
||||
* built, then the lower half will also be needed. There is no need for
|
||||
* the early serial initialization in this case.
|
||||
*/
|
||||
|
||||
#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL)
|
||||
# define USE_SERIALDRIVER 1
|
||||
#endif
|
||||
|
||||
/* Check if an interrupt stack size is configured */
|
||||
|
||||
#ifndef CONFIG_ARCH_INTERRUPTSTACK
|
||||
# define CONFIG_ARCH_INTERRUPTSTACK 0
|
||||
#endif
|
||||
|
||||
/* Macros to handle saving and restore interrupt state. In the current
|
||||
* model, the state is copied from the stack to the TCB, but only a
|
||||
* referenced is passed to get the state from the TCB.
|
||||
*/
|
||||
|
||||
#define up_restorestate(regs) (g_current_regs = regs)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
typedef void (*up_vector_t)(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
/* This holds a references to the current interrupt level register storage
|
||||
* structure. If is non-NULL only during interrupt processing.
|
||||
*/
|
||||
|
||||
extern volatile uint64_t *g_current_regs;
|
||||
|
||||
/* This is the beginning of heap as provided from up_head.S. This is the first
|
||||
* address in DRAM after the loaded program+bss+idle stack. The end of the
|
||||
* heap is CONFIG_RAM_END
|
||||
*/
|
||||
|
||||
extern uint64_t g_idle_topstack;
|
||||
|
||||
/* Address of the saved user stack pointer */
|
||||
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
||||
extern uint64_t g_intstackbase;
|
||||
#endif
|
||||
|
||||
/* These 'addresses' of these values are setup by the linker script. They are
|
||||
* not actual uint32_t storage locations! They are only used meaningfully in the
|
||||
* following way:
|
||||
*
|
||||
* - The linker script defines, for example, the symbol_sdata.
|
||||
* - The declareion extern uint32_t _sdata; makes C happy. C will believe
|
||||
* that the value _sdata is the address of a uint32_t variable _data (it is
|
||||
* not!).
|
||||
* - We can recoved the linker value then by simply taking the address of
|
||||
* of _data. like: uint32_t *pdata = &_sdata;
|
||||
*/
|
||||
|
||||
extern uint64_t _stext; /* Start of .text */
|
||||
extern uint64_t _etext; /* End_1 of .text + .rodata */
|
||||
extern const uint64_t _eronly; /* End+1 of read only section (.text + .rodata) */
|
||||
extern uint64_t _sdata; /* Start of .data */
|
||||
extern uint64_t _edata; /* End+1 of .data */
|
||||
extern uint64_t _sbss; /* Start of .bss */
|
||||
extern uint64_t _ebss; /* End+1 of .bss */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Name: x86_64_boardinitialize
|
||||
*
|
||||
* Description:
|
||||
* This function must be provided by the board-specific logic in the
|
||||
* directory configs/<board-name>/src/.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void x86_64_boardinitialize(void);
|
||||
|
||||
/* Defined in files with the same name as the function */
|
||||
|
||||
void up_copystate(uint64_t *dest, uint64_t *src);
|
||||
void up_savestate(uint64_t *regs);
|
||||
void up_decodeirq(uint64_t *regs);
|
||||
void up_irqinitialize(void);
|
||||
#ifdef CONFIG_ARCH_DMA
|
||||
void weak_function up_dmainitialize(void);
|
||||
#endif
|
||||
int up_saveusercontext(uint64_t *saveregs);
|
||||
void up_fullcontextrestore(uint64_t *restoreregs) noreturn_function;
|
||||
void up_switchcontext(uint64_t *saveregs, uint64_t *restoreregs);
|
||||
void up_sigdeliver(void);
|
||||
void up_lowputc(char ch);
|
||||
void up_puts(const char *str);
|
||||
void up_lowputs(const char *str);
|
||||
void up_restore_auxstate(struct tcb_s *rtcb);
|
||||
void up_checktasks(void);
|
||||
|
||||
void up_syscall(uint64_t *regs);
|
||||
void up_registerdump(uint64_t *regs);
|
||||
|
||||
/* Defined in up_allocateheap.c */
|
||||
|
||||
#if CONFIG_MM_REGIONS > 1
|
||||
void up_addregion(void);
|
||||
#else
|
||||
# define up_addregion()
|
||||
#endif
|
||||
|
||||
/* Defined in xyz_serial.c */
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
void up_earlyserialinit(void);
|
||||
void up_serialinit(void);
|
||||
#else
|
||||
# define up_earlyserialinit()
|
||||
# define up_serialinit()
|
||||
#endif
|
||||
|
||||
/* Defined in xyz_watchdog.c */
|
||||
|
||||
void up_wdtinit(void);
|
||||
|
||||
/* Defined in xyz_timerisr.c */
|
||||
|
||||
void x86_64_timer_calibrate_freq(void);
|
||||
void x86_64_timer_initialize(void);
|
||||
|
||||
/* Defined in board/up_network.c */
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
void up_netinitialize(void);
|
||||
#else
|
||||
# define up_netinitialize()
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV
|
||||
void up_usbinitialize(void);
|
||||
void up_usbuninitialize(void);
|
||||
#else
|
||||
# define up_usbinitialize()
|
||||
# define up_usbuninitialize()
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#endif /* __ARCH_X86_64_SRC_COMMON_UP_INTERNAL_H */
|
||||
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_interruptcontext.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
* Description:
|
||||
* Return true is we are currently executing in the interrupt handler
|
||||
* context.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool up_interrupt_context(void)
|
||||
{
|
||||
return g_current_regs != NULL;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_lowputs.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_lowputs
|
||||
*
|
||||
* Description:
|
||||
* This is a low-level helper function used to support debug.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_lowputs(const char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
up_lowputc(*str++);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_mdelay.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_mdelay
|
||||
*
|
||||
* Description:
|
||||
* Delay inline for the requested number of milliseconds.
|
||||
* *** NOT multi-tasking friendly ***
|
||||
*
|
||||
* ASSUMPTIONS:
|
||||
* The setting CONFIG_BOARD_LOOPSPERMSEC has been calibrated
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_mdelay(unsigned int milliseconds)
|
||||
{
|
||||
volatile int i;
|
||||
volatile int j;
|
||||
|
||||
for (i = 0; i < milliseconds; i++)
|
||||
{
|
||||
for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_modifyreg16.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: modifyreg16
|
||||
*
|
||||
* Description:
|
||||
* Atomically modify the specified bits in a memory mapped register
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
|
||||
{
|
||||
irqstate_t flags;
|
||||
uint16_t regval;
|
||||
|
||||
flags = enter_critical_section();
|
||||
regval = getreg16((uint16_t)addr);
|
||||
regval &= ~clearbits;
|
||||
regval |= setbits;
|
||||
putreg16(regval, (uint16_t)addr);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_modifyreg32.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: modifyreg32
|
||||
*
|
||||
* Description:
|
||||
* Atomically modify the specified bits in a memory mapped register
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
|
||||
{
|
||||
irqstate_t flags;
|
||||
uint32_t regval;
|
||||
|
||||
flags = enter_critical_section();
|
||||
regval = getreg32((uint16_t)addr);
|
||||
regval &= ~clearbits;
|
||||
regval |= setbits;
|
||||
putreg32(regval, (uint16_t)addr);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_modifyreg8.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: modifyreg8
|
||||
*
|
||||
* Description:
|
||||
* Atomically modify the specified bits in a memory mapped register
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
|
||||
{
|
||||
irqstate_t flags;
|
||||
uint8_t regval;
|
||||
|
||||
flags = enter_critical_section();
|
||||
regval = getreg8((uint16_t)addr);
|
||||
regval &= ~clearbits;
|
||||
regval |= setbits;
|
||||
putreg8(regval, (uint16_t)addr);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_puts.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_puts
|
||||
*
|
||||
* Description:
|
||||
* This is a low-level helper function used to support debug.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_puts(const char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
up_putc(*str++);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_releasepending.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_release_pending
|
||||
*
|
||||
* Description:
|
||||
* Release and ready-to-run tasks that have
|
||||
* collected in the pending task list. This can call a
|
||||
* context switch if a new task is placed at the head of
|
||||
* the ready to run list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_release_pending(void)
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
|
||||
sinfo("From TCB=%p\n", rtcb);
|
||||
|
||||
/* Merge the g_pendingtasks list into the ready-to-run task list */
|
||||
|
||||
if (sched_mergepending())
|
||||
{
|
||||
/* The currently active task has changed! We will need to switch
|
||||
* contexts.
|
||||
*
|
||||
* Update scheduler parameters.
|
||||
*/
|
||||
|
||||
sched_suspend_scheduler(rtcb);
|
||||
|
||||
/* Are we operating in interrupt context? */
|
||||
|
||||
if (g_current_regs)
|
||||
{
|
||||
/* Yes, then we have to do things differently.
|
||||
* Just copy the g_current_regs into the OLD rtcb.
|
||||
*/
|
||||
|
||||
up_savestate(rtcb->xcp.regs);
|
||||
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts. Any necessary address environment
|
||||
* changes will be made when the interrupt returns.
|
||||
*/
|
||||
|
||||
up_restorestate(rtcb->xcp.regs);
|
||||
}
|
||||
|
||||
/* Copy the exception context into the TCB of the task that
|
||||
* was currently active. if up_saveusercontext returns a non-zero
|
||||
* value, then this is really the previously running task
|
||||
* restarting!
|
||||
*/
|
||||
|
||||
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||
{
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Make sure that the address environment for the previously
|
||||
* running task is closed down gracefully (data caches dump,
|
||||
* MMU flushed) and set up the address environment for the new
|
||||
* thread at the head of the ready-to-run list.
|
||||
*/
|
||||
|
||||
(void)group_addrenv(rtcb);
|
||||
#endif
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_fullcontextrestore(rtcb->xcp.regs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/common/up_reprioritizertr.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_reprioritize_rtr
|
||||
*
|
||||
* Description:
|
||||
* Called when the priority of a running or
|
||||
* ready-to-run task changes and the reprioritization will
|
||||
* cause a context switch. Two cases:
|
||||
*
|
||||
* 1) The priority of the currently running task drops and the next
|
||||
* task in the ready to run list has priority.
|
||||
* 2) An idle, ready to run task's priority has been raised above the
|
||||
* the priority of the current, running task and it now has the
|
||||
* priority.
|
||||
*
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of the task that has been reprioritized
|
||||
* priority: The new task priority
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_reprioritize_rtr(struct tcb_s *tcb, uint8_t priority)
|
||||
{
|
||||
/* Verify that the caller is sane */
|
||||
|
||||
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
|
||||
tcb->task_state > LAST_READY_TO_RUN_STATE
|
||||
#if SCHED_PRIORITY_MIN > 0
|
||||
|| priority < SCHED_PRIORITY_MIN
|
||||
#endif
|
||||
#if SCHED_PRIORITY_MAX < UINT8_MAX
|
||||
|| priority > SCHED_PRIORITY_MAX
|
||||
#endif
|
||||
)
|
||||
{
|
||||
PANIC();
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
bool switch_needed;
|
||||
|
||||
sinfo("TCB=%p PRI=%d\n", tcb, priority);
|
||||
|
||||
/* Remove the tcb task from the ready-to-run list.
|
||||
* sched_removereadytorun will return true if we just
|
||||
* remove the head of the ready to run list.
|
||||
*/
|
||||
|
||||
switch_needed = sched_removereadytorun(tcb);
|
||||
|
||||
/* Setup up the new task priority */
|
||||
|
||||
tcb->sched_priority = (uint8_t)priority;
|
||||
|
||||
/* Return the task to the specified blocked task list.
|
||||
* sched_addreadytorun will return true if the task was
|
||||
* added to the new list. We will need to perform a context
|
||||
* switch only if the EXCLUSIVE or of the two calls is non-zero
|
||||
* (i.e., one and only one the calls changes the head of the
|
||||
* ready-to-run list).
|
||||
*/
|
||||
|
||||
switch_needed ^= sched_addreadytorun(tcb);
|
||||
|
||||
/* Now, perform the context switch if one is needed */
|
||||
|
||||
if (switch_needed)
|
||||
{
|
||||
/* If we are going to do a context switch, then now is the right
|
||||
* time to add any pending tasks back into the ready-to-run list.
|
||||
* task list now
|
||||
*/
|
||||
|
||||
if (g_pendingtasks.head)
|
||||
{
|
||||
sched_mergepending();
|
||||
}
|
||||
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_suspend_scheduler(rtcb);
|
||||
|
||||
/* Are we in an interrupt handler? */
|
||||
|
||||
if (g_current_regs)
|
||||
{
|
||||
/* Yes, then we have to do things differently.
|
||||
* Just copy the g_current_regs into the OLD rtcb.
|
||||
*/
|
||||
|
||||
up_savestate(rtcb->xcp.regs);
|
||||
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts. Any necessary address environment
|
||||
* changes will be made when the interrupt returns.
|
||||
*/
|
||||
|
||||
up_restorestate(rtcb->xcp.regs);
|
||||
}
|
||||
|
||||
/* Copy the exception context into the TCB at the (old) head of the
|
||||
* ready-to-run Task list. if up_saveusercontext returns a non-zero
|
||||
* value, then this is really the previously running task restarting!
|
||||
*/
|
||||
|
||||
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||
{
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Make sure that the address environment for the previously
|
||||
* running task is closed down gracefully (data caches dump,
|
||||
* MMU flushed) and set up the address environment for the new
|
||||
* thread at the head of the ready-to-run list.
|
||||
*/
|
||||
|
||||
(void)group_addrenv(rtcb);
|
||||
#endif
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_fullcontextrestore(rtcb->xcp.regs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_udelay.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_BOARD_LOOPSPER100USEC ((CONFIG_BOARD_LOOPSPERMSEC+5)/10)
|
||||
#define CONFIG_BOARD_LOOPSPER10USEC ((CONFIG_BOARD_LOOPSPERMSEC+50)/100)
|
||||
#define CONFIG_BOARD_LOOPSPERUSEC ((CONFIG_BOARD_LOOPSPERMSEC+500)/1000)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_udelay
|
||||
*
|
||||
* Description:
|
||||
* Delay inline for the requested number of microseconds. NOTE: Because
|
||||
* of all of the setup, several microseconds will be lost before the actual
|
||||
* timing loop begins. Thus, the delay will always be a few microseconds
|
||||
* longer than requested.
|
||||
*
|
||||
* *** NOT multi-tasking friendly ***
|
||||
*
|
||||
* ASSUMPTIONS:
|
||||
* The setting CONFIG_BOARD_LOOPSPERMSEC has been calibrated
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_udelay(useconds_t microseconds)
|
||||
{
|
||||
volatile int i;
|
||||
|
||||
/* We'll do this a little at a time because we expect that the
|
||||
* CONFIG_BOARD_LOOPSPERUSEC is very inaccurate during to truncation in
|
||||
* the divisions of its calculation. We'll use the largest values that
|
||||
* we can in order to prevent significant error buildup in the loops.
|
||||
*/
|
||||
|
||||
while (microseconds > 1000)
|
||||
{
|
||||
for (i = 0; i < CONFIG_BOARD_LOOPSPERMSEC; i++)
|
||||
{
|
||||
}
|
||||
|
||||
microseconds -= 1000;
|
||||
}
|
||||
|
||||
while (microseconds > 100)
|
||||
{
|
||||
for (i = 0; i < CONFIG_BOARD_LOOPSPER100USEC; i++)
|
||||
{
|
||||
}
|
||||
|
||||
microseconds -= 100;
|
||||
}
|
||||
|
||||
while (microseconds > 10)
|
||||
{
|
||||
for (i = 0; i < CONFIG_BOARD_LOOPSPER10USEC; i++)
|
||||
{
|
||||
}
|
||||
|
||||
microseconds -= 10;
|
||||
}
|
||||
|
||||
while (microseconds > 0)
|
||||
{
|
||||
for (i = 0; i < CONFIG_BOARD_LOOPSPERUSEC; i++)
|
||||
{
|
||||
}
|
||||
|
||||
microseconds--;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/common/up_unblocktask.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "group/group.h"
|
||||
#include "clock/clock.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_unblock_task
|
||||
*
|
||||
* Description:
|
||||
* A task is currently in an inactive task list but has been prepped to
|
||||
* execute. Move the TCB to the ready-to-run list, restore its context,
|
||||
* and start execution.
|
||||
*
|
||||
* Input Parameters:
|
||||
* tcb: Refers to the tcb to be unblocked. This tcb is in one of the
|
||||
* waiting tasks lists. It must be moved to the ready-to-run list and,
|
||||
* if it is the highest priority ready to run task, executed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_unblock_task(struct tcb_s *tcb)
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Verify that the context switch can be performed */
|
||||
|
||||
ASSERT((tcb->task_state >= FIRST_BLOCKED_STATE) &&
|
||||
(tcb->task_state <= LAST_BLOCKED_STATE));
|
||||
|
||||
/* Remove the task from the blocked task list */
|
||||
|
||||
sched_removeblocked(tcb);
|
||||
|
||||
/* Add the task in the correct location in the prioritized
|
||||
* ready-to-run task list
|
||||
*/
|
||||
|
||||
if (sched_addreadytorun(tcb))
|
||||
{
|
||||
/* The currently active task has changed! We need to do
|
||||
* a context switch to the new task.
|
||||
*/
|
||||
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_suspend_scheduler(rtcb);
|
||||
|
||||
/* Are we in an interrupt handler? */
|
||||
|
||||
if (g_current_regs)
|
||||
{
|
||||
/* Yes, then we have to do things differently.
|
||||
* Just copy the g_current_regs into the OLD rtcb.
|
||||
*/
|
||||
|
||||
up_savestate(rtcb->xcp.regs);
|
||||
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts. Any necessary address environment
|
||||
* changes will be made when the interrupt returns.
|
||||
*/
|
||||
|
||||
up_restorestate(rtcb->xcp.regs);
|
||||
}
|
||||
|
||||
/* We are not in an interrupt handler. Copy the user C context
|
||||
* into the TCB of the task that was previously active. if
|
||||
* up_saveusercontext returns a non-zero value, then this is really the
|
||||
* previously running task restarting!
|
||||
*/
|
||||
|
||||
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||
{
|
||||
/* Restore the exception context of the new task that is ready to
|
||||
* run (probably tcb). This is the new rtcb at the head of the
|
||||
* ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
up_restore_auxstate(rtcb);
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Make sure that the address environment for the previously
|
||||
* running task is closed down gracefully (data caches dump,
|
||||
* MMU flushed) and set up the address environment for the new
|
||||
* thread at the head of the ready-to-run list.
|
||||
*/
|
||||
|
||||
(void)group_addrenv(rtcb);
|
||||
#endif
|
||||
/* Update scheduler parameters */
|
||||
|
||||
sched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_fullcontextrestore(rtcb->xcp.regs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
if ARCH_INTEL64
|
||||
comment "intel64 Configuration Options"
|
||||
|
||||
config ARCH_INTEL64_HAVE_TSC_DEADLINE
|
||||
bool "TSC DEADLINE timer support"
|
||||
default y
|
||||
---help---
|
||||
Select to enable the use of TSC DEADLINE timer of x86_64
|
||||
|
||||
if ARCH_INTEL64_HAVE_TSC_DEADLINE
|
||||
|
||||
config ARCH_INTEL64_CORE_FREQ_KHZ
|
||||
int "CPU Core frequency in kHz"
|
||||
default 2000000
|
||||
---help---
|
||||
The CPU Core frequency (without Turbo boost). This is used
|
||||
to set the TSC deadline timer frequency.
|
||||
|
||||
endif
|
||||
|
||||
if !ARCH_INTEL64_HAVE_TSC_DEADLINE
|
||||
|
||||
config ARCH_INTEL64_APIC_FREQ_KHZ
|
||||
int "APIC timer frequency in kHz"
|
||||
default 2000000
|
||||
---help---
|
||||
The APIC timer frequency. This is used to set the APIC timer
|
||||
frequency in case of no TSC DEADLINE timer is available.
|
||||
|
||||
endif
|
||||
|
||||
config ARCH_INTEL64_HAVE_SSE3
|
||||
bool "SSE3 support"
|
||||
default y
|
||||
---help---
|
||||
Select to enable the use of SSE3 and FPU functions of x86_64
|
||||
|
||||
config ARCH_INTEL64_HAVE_PCID
|
||||
bool "PCID support"
|
||||
default y
|
||||
---help---
|
||||
Select to enable the use of PCID to reduce TLB flush
|
||||
|
||||
config ARCH_INTEL64_HAVE_RDRAND
|
||||
bool "RDRAND support"
|
||||
default y
|
||||
---help---
|
||||
Select to enable the use of RDRAND for /dev/random
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,49 @@
|
||||
############################################################################
|
||||
# arch/x86_64/src/intel64/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Common x86_64 and intel64 files
|
||||
|
||||
CMN_CSRCS += up_allocateheap.c up_assert.c up_blocktask.c up_copystate.c up_restore_auxstate.c
|
||||
CMN_CSRCS += up_createstack.c up_mdelay.c up_udelay.c up_exit.c
|
||||
CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c
|
||||
CMN_CSRCS += up_irq.c up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c
|
||||
CMN_CSRCS += up_regdump.c up_releasepending.c up_releasestack.c
|
||||
CMN_CSRCS += up_reprioritizertr.c up_savestate.c up_sigdeliver.c
|
||||
CMN_CSRCS += up_schedulesigaction.c up_stackframe.c up_unblocktask.c
|
||||
CMN_CSRCS += up_usestack.c
|
||||
CMN_CSRCS += up_rtc.c
|
||||
CMN_CSRCS += up_map_region.c
|
||||
|
||||
# Required Intel64 files
|
||||
|
||||
CHIP_ASRCS = intel64_saveusercontext.S intel64_fullcontextrestore.S intel64_vectors.S intel64_head.S
|
||||
CHIP_CSRCS = intel64_handlers.c intel64_idle.c intel64_lowsetup.c
|
||||
CHIP_CSRCS += intel64_serial.c intel64_rng.c intel64_check_capability.c
|
||||
|
||||
# Configuration-dependent intel64 files
|
||||
|
||||
ifneq ($(CONFIG_SCHED_TICKLESS),y)
|
||||
CHIP_CSRCS += intel64_timerisr.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SCHED_TICKLESS),y)
|
||||
CHIP_CSRCS += intel64_tickless.c
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/************************************************************************************
|
||||
* arch/x86_64/src/broadwell/chip.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_SRC_BROADWELL_BROADWELL_CHIP_H
|
||||
#define __ARCH_X86_64_SRC_BROADWELL_BROADWELL_CHIP_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************************************/
|
||||
|
||||
#endif /* __ARCH_X86_64_SRC_BROADWELL_BROADWELL_CHIP_H */
|
||||
@@ -0,0 +1,148 @@
|
||||
/************************************************************************************
|
||||
* arch/x86_64/src/intel64/intel64.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_SRC_INTEL64_INTEL64_H
|
||||
#define __ARCH_X86_64_SRC_INTEL64_INTEL64_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
#include "chip.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/* Configuration ********************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Inline Functions
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
************************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: intel64_lowsetup
|
||||
*
|
||||
* Description:
|
||||
* Called at the very beginning of _start. Performs low level initialization
|
||||
* including setup of the console UART. This UART done early so that the serial
|
||||
* console is available for debugging very early in the boot sequence.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
void intel64_lowsetup(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: vector_*
|
||||
*
|
||||
* Description:
|
||||
* These are the various ISR/IRQ vector address exported from
|
||||
* intel64_vectors.S. These addresses need to have global scope so that they
|
||||
* can be known to the interrupt initialization logic in intel64_irq.c.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
void vector_isr0(void);
|
||||
void vector_isr1(void);
|
||||
void vector_isr2(void);
|
||||
void vector_isr3(void);
|
||||
void vector_isr4(void);
|
||||
void vector_isr5(void);
|
||||
void vector_isr6(void);
|
||||
void vector_isr7(void);
|
||||
void vector_isr8(void);
|
||||
void vector_isr9(void);
|
||||
void vector_isr10(void);
|
||||
void vector_isr11(void);
|
||||
void vector_isr12(void);
|
||||
void vector_isr13(void);
|
||||
void vector_isr14(void);
|
||||
void vector_isr15(void);
|
||||
void vector_isr16(void);
|
||||
void vector_isr17(void);
|
||||
void vector_isr18(void);
|
||||
void vector_isr19(void);
|
||||
void vector_isr20(void);
|
||||
void vector_isr21(void);
|
||||
void vector_isr22(void);
|
||||
void vector_isr23(void);
|
||||
void vector_isr24(void);
|
||||
void vector_isr25(void);
|
||||
void vector_isr26(void);
|
||||
void vector_isr27(void);
|
||||
void vector_isr28(void);
|
||||
void vector_isr29(void);
|
||||
void vector_isr30(void);
|
||||
void vector_isr31(void);
|
||||
void vector_irq0(void);
|
||||
void vector_irq1(void);
|
||||
void vector_irq2(void);
|
||||
void vector_irq3(void);
|
||||
void vector_irq4(void);
|
||||
void vector_irq5(void);
|
||||
void vector_irq6(void);
|
||||
void vector_irq7(void);
|
||||
void vector_irq8(void);
|
||||
void vector_irq9(void);
|
||||
void vector_irq10(void);
|
||||
void vector_irq11(void);
|
||||
void vector_irq12(void);
|
||||
void vector_irq13(void);
|
||||
void vector_irq14(void);
|
||||
void vector_irq15(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_X86_64_SRC_INTEL64_INTEL64_H */
|
||||
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/intel64/intel64_capability.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: x86_64_check_capability
|
||||
*
|
||||
* Description:
|
||||
* Called from up_lowsetup to check various CPU capabilities, matching the
|
||||
* RTOS config
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void x86_64_check_and_enable_capability(void)
|
||||
{
|
||||
unsigned long ecx;
|
||||
unsigned long require;
|
||||
|
||||
require = X86_64_CPUID_01_X2APIC;
|
||||
|
||||
/* Check timer availability */
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64_HAVE_TSC_DEADLINE
|
||||
require |= X86_64_CPUID_01_TSCDEA;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64_HAVE_SSE3
|
||||
require |= X86_64_CPUID_01_SSE3;
|
||||
require |= X86_64_CPUID_01_XSAVE;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64_HAVE_RDRAND
|
||||
require |= X86_64_CPUID_01_RDRAND;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64_HAVE_PCID
|
||||
require |= X86_64_CPUID_01_PCID;
|
||||
#endif
|
||||
|
||||
asm volatile("cpuid" : "=c" (ecx) : "a" (X86_64_CPUID_CAP)
|
||||
: "rbx", "rdx", "memory");
|
||||
|
||||
/* Check x2APIC availability */
|
||||
|
||||
if ((ecx & require) != require)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64_HAVE_SSE3
|
||||
__enable_sse3();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_INTEL64_HAVE_PCID
|
||||
__enable_pcid();
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
err:
|
||||
asm volatile ("cli");
|
||||
asm volatile ("hlt");
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/**************************************************************************
|
||||
* arch/x86_64/src/intel64/intel64_fullcontextrestore.S
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <arch/irq.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
.file "intel64_fullcontextrestore.S"
|
||||
|
||||
/**************************************************************************
|
||||
* Pre-processor Definitions
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Data
|
||||
**************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Macros
|
||||
****************************************************************************/
|
||||
|
||||
/* Trace macros, use like trace 'i' to print char to serial port. */
|
||||
|
||||
.macro chout, addr, ch
|
||||
#ifdef CONFIG_DEBUG_FEATURES
|
||||
mov $\addr, %dx
|
||||
mov $\ch, %al
|
||||
out %al, %dx
|
||||
#endif
|
||||
.endm
|
||||
|
||||
.macro trace, ch
|
||||
#ifdef CONFIG_DEBUG_FEATURES
|
||||
push %eax
|
||||
push %edx
|
||||
chout 0x3f8, \ch
|
||||
pop %edx
|
||||
pop %eax
|
||||
#endif
|
||||
.endm
|
||||
|
||||
/**************************************************************************
|
||||
* Public Functions
|
||||
**************************************************************************/
|
||||
|
||||
.text
|
||||
|
||||
/**************************************************************************
|
||||
* Name: up_fullcontextrestore
|
||||
*
|
||||
* Full C prototype:
|
||||
* void up_fullcontextrestore(uint32_t *regs) noreturn_function;
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
.globl up_fullcontextrestore
|
||||
.type up_fullcontextrestore, @function
|
||||
up_fullcontextrestore:
|
||||
/* The pointer to the register save array in RDI. */
|
||||
|
||||
/* Disable interrupts now (the correct RFLAGS will be restored before we
|
||||
* return
|
||||
*/
|
||||
|
||||
cli
|
||||
|
||||
/* Create an interrupt stack frame for the final iret.
|
||||
*
|
||||
*
|
||||
* IRET STACK
|
||||
* ---------------
|
||||
* RSP Before ->
|
||||
* SS
|
||||
* RSP
|
||||
* RFLAGS
|
||||
* CS
|
||||
* RSP After -> RIP
|
||||
*
|
||||
*/
|
||||
|
||||
movq (8*REG_SS)(%rdi), %rbx
|
||||
push %rbx
|
||||
movq (8*REG_RSP)(%rdi), %rbx
|
||||
push %rbx
|
||||
|
||||
movq (8*REG_RFLAGS)(%rdi), %rbx
|
||||
push %rbx
|
||||
movq (8*REG_CS)(%rdi), %rbx
|
||||
push %rbx
|
||||
movq (8*REG_RIP)(%rdi), %rbx
|
||||
push %rbx
|
||||
|
||||
/* Save the value of RDI on the stack too */
|
||||
|
||||
movq (8*REG_RDI)(%rdi), %rbx
|
||||
push %rbx
|
||||
|
||||
/* Now restore the remaining registers */
|
||||
movq (8*REG_RSI)(%rdi), %rsi
|
||||
movq (8*REG_RDX)(%rdi), %rdx
|
||||
movq (8*REG_RCX)(%rdi), %rcx
|
||||
movq (8*REG_R8 )(%rdi), %r8
|
||||
movq (8*REG_R9 )(%rdi), %r9
|
||||
|
||||
movq (8*REG_R15)(%rdi), %r15
|
||||
movq (8*REG_R14)(%rdi), %r14
|
||||
movq (8*REG_R13)(%rdi), %r13
|
||||
movq (8*REG_R12)(%rdi), %r12
|
||||
movq (8*REG_R11)(%rdi), %r11
|
||||
movq (8*REG_R10)(%rdi), %r10
|
||||
movq (8*REG_RBP)(%rdi), %rbp
|
||||
movq (8*REG_RBX)(%rdi), %rbx
|
||||
movq (8*REG_RAX)(%rdi), %rax
|
||||
|
||||
/* Restore the data segment register. I think there is an issue that will
|
||||
* need to be address here at some time: If the register save area is in
|
||||
* one data segment and the stack is in another, then the above would not
|
||||
* work (and, conversely, if they are in the same data segment, the
|
||||
* following is unnecessary and redundant).
|
||||
*/
|
||||
|
||||
mov (8*REG_DS)(%rdi), %ds
|
||||
// mov (8*REG_ES)(%rdi), %es // Not used in 64 bit
|
||||
// mov (8*REG_GS)(%rdi), %gs // Disabled, otherwise we will destroy MSR_GS_BASE
|
||||
// mov (8*REG_FS)(%rdi), %fs // Disabled, otherwise we will destroy MSR_FS_BASE
|
||||
// XXX: Should use wrgsbase and wrfsbase to restore the gs and fs register
|
||||
|
||||
/* restore xmm registers */
|
||||
fxrstorq (%rdi)
|
||||
|
||||
/* Restore the correct value of EAX and then return */
|
||||
|
||||
popq %rdi
|
||||
iretq
|
||||
.size up_fullcontextrestore, . - up_fullcontextrestore
|
||||
.end
|
||||
@@ -0,0 +1,217 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/src/intel64/intel64_handlers.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/signal.h>
|
||||
#include <arch/io.h>
|
||||
#include <syscall.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
#include "sched/sched.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define X2APIC_EOI 0x80b
|
||||
|
||||
#define APIC_EOI_ACK 0
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: common_handler
|
||||
*
|
||||
* Description:
|
||||
* Common logic for the ISR/IRQ handlers
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SUPPRESS_INTERRUPTS
|
||||
static uint64_t *common_handler(int irq, uint64_t *regs)
|
||||
{
|
||||
board_autoled_on(LED_INIRQ);
|
||||
|
||||
/* Current regs non-zero indicates that we are processing an interrupt;
|
||||
* g_current_regs is also used to manage interrupt level context switches.
|
||||
*
|
||||
* Nested interrupts are not supported.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(g_current_regs == NULL);
|
||||
g_current_regs = regs;
|
||||
|
||||
/* Deliver the IRQ */
|
||||
|
||||
irq_dispatch(irq, regs);
|
||||
|
||||
#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
|
||||
/* Check for a context switch. If a context switch occurred, then
|
||||
* g_current_regs will have a different value than it did on entry. If an
|
||||
* interrupt level context switch has occurred, then restore the floating
|
||||
* point state and the establish the correct address environment before
|
||||
* returning from the interrupt.
|
||||
*/
|
||||
|
||||
if (regs != g_current_regs)
|
||||
{
|
||||
#ifdef CONFIG_ARCH_FPU
|
||||
/* Restore floating point registers */
|
||||
|
||||
up_restorefpu((uint64_t *)g_current_regs);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Make sure that the address environment for the previously
|
||||
* running task is closed down gracefully (data caches dump,
|
||||
* MMU flushed) and set up the address environment for the new
|
||||
* thread at the head of the ready-to-run list.
|
||||
*/
|
||||
|
||||
(void)group_addrenv(NULL);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If a context switch occurred while processing the interrupt then
|
||||
* g_current_regs may have change value. If we return any value different
|
||||
* from the input regs, then the lower level will know that a context
|
||||
* switch occurred during interrupt processing.
|
||||
*/
|
||||
|
||||
regs = (uint64_t *)g_current_regs;
|
||||
|
||||
/* Set g_current_regs to NULL to indicate that we are no longer in an
|
||||
* interrupt handler.
|
||||
*/
|
||||
|
||||
g_current_regs = NULL;
|
||||
return regs;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isr_handler
|
||||
*
|
||||
* Description:
|
||||
* This gets called from ISR vector handling logic in broadwell_vectors.S
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define SIGFPE 8
|
||||
|
||||
uint64_t *isr_handler(uint64_t *regs, uint64_t irq)
|
||||
{
|
||||
#ifdef CONFIG_SUPPRESS_INTERRUPTS
|
||||
board_autoled_on(LED_INIRQ);
|
||||
PANIC(); /* Doesn't return */
|
||||
return regs; /* To keep the compiler happy */
|
||||
#else
|
||||
uint64_t *ret;
|
||||
|
||||
DEBUGASSERT(g_current_regs == NULL);
|
||||
g_current_regs = regs;
|
||||
|
||||
switch (irq)
|
||||
{
|
||||
case 0:
|
||||
case 16:
|
||||
asm volatile("fnclex":::"memory");
|
||||
nxsig_kill(this_task()->pid, SIGFPE);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Let's say, all ISR are asserted when REALLY BAD things happened.
|
||||
* Don't even brother to recover, just dump the regs and PANIC.
|
||||
*/
|
||||
|
||||
_alert("PANIC:\n");
|
||||
_alert("Exception %lld occurred with error code %lld:\n",
|
||||
irq, regs[REG_ERRCODE]);
|
||||
|
||||
up_registerdump(regs);
|
||||
|
||||
up_trash_cpu();
|
||||
break;
|
||||
}
|
||||
|
||||
/* Maybe we need a context switch */
|
||||
|
||||
regs = (uint64_t *)g_current_regs;
|
||||
|
||||
/* Set g_current_regs to NULL to indicate that we are no longer in an
|
||||
* interrupt handler.
|
||||
*/
|
||||
|
||||
g_current_regs = NULL;
|
||||
return regs;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isr_handler
|
||||
*
|
||||
* Description:
|
||||
* This gets called from IRQ vector handling logic in intel64_vectors.S
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t *irq_handler(uint64_t *regs, uint64_t irq_no)
|
||||
{
|
||||
#ifdef CONFIG_SUPPRESS_INTERRUPTS
|
||||
board_autoled_on(LED_INIRQ);
|
||||
PANIC(); /* Doesn't return */
|
||||
return regs; /* To keep the compiler happy */
|
||||
#else
|
||||
uint64_t *ret;
|
||||
int irq;
|
||||
|
||||
board_autoled_on(LED_INIRQ);
|
||||
|
||||
/* Get the IRQ number */
|
||||
|
||||
irq = (int)irq_no;
|
||||
|
||||
/* Dispatch the interrupt */
|
||||
|
||||
ret = common_handler(irq, regs);
|
||||
|
||||
/* Send an EOI (end of interrupt) signal to the APIC */
|
||||
|
||||
write_msr(X2APIC_EOI, APIC_EOI_ACK);
|
||||
board_autoled_off(LED_INIRQ);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,458 @@
|
||||
/****************************************************************************
|
||||
* arch/x86/src/intel64/intel64_head.S
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <arch/arch.h>
|
||||
#include <arch/multiboot2.h>
|
||||
|
||||
.file "intel64_head.S"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Memory Map: _sbss is the start of the BSS region (see ld.script) _ebss is
|
||||
* the end of the BSS regsion (see ld.script). The idle task stack starts at
|
||||
* the end of BSS and is of size CONFIG_IDLETHREAD_STACKSIZE. The IDLE thread
|
||||
* is the thread that the system boots on and, eventually, becomes the idle,
|
||||
* do nothing task that runs only when there is nothing else to run. The
|
||||
* heap continues from there until the end of memory. See g_idle_topstack below.
|
||||
*/
|
||||
|
||||
#define STACKBASE ((_ebss + 0x1f) & 0xffffffe0)
|
||||
#define IDLE_STACK (STACKBASE+CONFIG_IDLETHREAD_STACKSIZE)
|
||||
#define HEAP_BASE (STACKBASE+CONFIG_IDLETHREAD_STACKSIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Macros
|
||||
****************************************************************************/
|
||||
|
||||
/* Trace macros, use like trace 'i' to print char to serial port. */
|
||||
|
||||
.macro trace, ch
|
||||
#ifdef CONFIG_DEBUG_FEATURES
|
||||
mov $0x3f8, %dx
|
||||
mov $\ch, %al
|
||||
out %al, %dx
|
||||
#endif
|
||||
.endm
|
||||
|
||||
/****************************************************************************
|
||||
* Public Symbols
|
||||
****************************************************************************/
|
||||
.global __pmode_entry /* The 32bit protected mode entry */
|
||||
.global __nxstart
|
||||
.global __enable_sse3
|
||||
.global __enable_pcid
|
||||
.global nx_start /* nx_start is defined elsewhere */
|
||||
.global up_lowsetup /* up_lowsetup is defined elsewhere */
|
||||
.global g_idle_topstack /* The end of the idle stack, the start of the heap */
|
||||
|
||||
/* These are the page tables */
|
||||
.global pdpt_low
|
||||
.global pd_low
|
||||
.global pt_low
|
||||
|
||||
/* These are the GDT */
|
||||
.global gdt64_low
|
||||
.global gdt64_ist_low
|
||||
.global gdt64_low_end
|
||||
|
||||
.global ist64_low
|
||||
|
||||
/****************************************************************************
|
||||
* The multiboot2 header
|
||||
****************************************************************************/
|
||||
|
||||
.set HEADER_LENGTH, header_end - header_start
|
||||
.set CHECKSUM, -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + HEADER_LENGTH)
|
||||
|
||||
#ifndef CONFIG_ARCH_EXCLUDE_MULTIBOOT
|
||||
.section ".multiboot", "a"
|
||||
.align 8
|
||||
|
||||
header_start:
|
||||
.long MULTIBOOT2_HEADER_MAGIC
|
||||
.long MULTIBOOT_ARCHITECTURE_I386
|
||||
.long HEADER_LENGTH
|
||||
.long CHECKSUM
|
||||
|
||||
// multiboot tags go here
|
||||
|
||||
.short MULTIBOOT_HEADER_TAG_END
|
||||
.short 0 // flags, none set
|
||||
.long 8 // size, including itself (short + short + long)
|
||||
header_end:
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* .text
|
||||
****************************************************************************/
|
||||
|
||||
.code32
|
||||
.section ".loader.text", "ax"
|
||||
|
||||
/****************************************************************************
|
||||
* Name: __pmode_entry
|
||||
*
|
||||
* Description:
|
||||
* Entry point for 32-bit protected mode
|
||||
* Function to transit protected mode to 64-bit long mode
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
.type __pmode_entry, @function
|
||||
__pmode_entry:
|
||||
start32:
|
||||
|
||||
// initialize rest of the page directory
|
||||
lea pd_low, %edi
|
||||
lea pt_low, %esi
|
||||
|
||||
// Popluate the lower 4GB as non-present
|
||||
// for ecx = 0...512 * 4 : Loop and setup the page directories
|
||||
mov $0x800, %ecx // 512 * 3
|
||||
epd_loop:
|
||||
mov %esi, %edx
|
||||
or $(X86_PAGE_WR | X86_PAGE_PRESENT), %edx
|
||||
mov %edx, 0(%edi)
|
||||
add $(X86_PAGE_ENTRY_SIZE), %edi
|
||||
|
||||
// for ebx = 0...1024: Loop and clear the page table of each page directory
|
||||
mov $1024, %ebx
|
||||
ept_loop:
|
||||
movl $0x0, 0(%esi)
|
||||
add $4, %esi
|
||||
|
||||
// end for ebx
|
||||
dec %ebx
|
||||
jnz ept_loop
|
||||
|
||||
// end for ecx
|
||||
dec %ecx
|
||||
jnz epd_loop
|
||||
|
||||
// Temporary populate the lower 128MB on 1:1 mapping
|
||||
lea pd_low, %edi
|
||||
mov $(X86_PAGE_GLOBAL | X86_PAGE_WR | X86_PAGE_PRESENT | X86_PAGE_HUGE), %eax
|
||||
|
||||
// for ecx = 0...64 : Loop and setup 64x 2MB page directories
|
||||
mov $64, %ecx
|
||||
pd_loop:
|
||||
mov %eax, 0(%edi)
|
||||
add $(HUGE_PAGE_SIZE), %eax
|
||||
add $(X86_PAGE_ENTRY_SIZE), %edi
|
||||
|
||||
// end for ecx
|
||||
dec %ecx
|
||||
jnz pd_loop
|
||||
|
||||
// Populate the 1GB after 4GB boundary with Global mapping to kernel code
|
||||
// This creates maps the lower 1GB to 4GB~5GB
|
||||
lea pdpt_low, %edi
|
||||
mov $(X86_PAGE_GLOBAL | X86_PAGE_WR | X86_PAGE_PRESENT | X86_PAGE_HUGE), %eax
|
||||
|
||||
mov $0x4, %ecx
|
||||
mov %eax, 0(%edi, %ecx, X86_PAGE_ENTRY_SIZE)
|
||||
|
||||
// Enable PAE
|
||||
mov %cr4, %eax
|
||||
or $(X86_CR4_PAE | X86_CR4_PGE), %eax
|
||||
mov %eax, %cr4
|
||||
|
||||
// Load the 4 level page table
|
||||
// Level 1 and 2 were preset at build time in assembly for this loading
|
||||
// process
|
||||
// 4KiB page table is used
|
||||
// Kernel mapped to 1GB HiMem
|
||||
lea pml4, %eax
|
||||
mov %eax, %cr3
|
||||
|
||||
movl $MSR_MTRR_DEF_TYPE, %ecx
|
||||
rdmsr
|
||||
or $MTRR_ENABLE, %eax
|
||||
wrmsr
|
||||
|
||||
movl $MSR_EFER, %ecx
|
||||
rdmsr
|
||||
or $EFER_LME, %eax
|
||||
wrmsr
|
||||
|
||||
// Enable paging related bits in CR0
|
||||
mov $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
|
||||
mov %eax, %cr0
|
||||
|
||||
// Enable FGSBASE
|
||||
mov %cr4, %eax
|
||||
or $X86_CR4_FGSBASE, %eax
|
||||
mov %eax, %cr4
|
||||
|
||||
|
||||
// Load a GDT with 64bits mode set
|
||||
lgdt gdt64_ptr
|
||||
|
||||
// Long jump into 64 bit mode, updating cs to new GDT
|
||||
ljmpl $(X86_GDT_CODE_SEL), $start64
|
||||
|
||||
.code64
|
||||
start64:
|
||||
|
||||
// Set Segement Registers for proper iret, etc. operation
|
||||
mov $(X86_GDT_DATA_SEL), %ax
|
||||
mov %ax, %ss
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
|
||||
// Finally, we can start the OS
|
||||
movabs $__nxstart, %rbx
|
||||
jmp *%rbx
|
||||
.size __pmode_entry, . - __pmode_entry
|
||||
|
||||
/****************************************************************************
|
||||
* Name: __nxstart
|
||||
*
|
||||
* Description:
|
||||
* Do low-level initialization and call nx_start
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
.section .text, "a"
|
||||
.type __nxstart, @function
|
||||
|
||||
__nxstart:
|
||||
/* We are now in high memory, revoke the lower 128MB memory mapping */
|
||||
lea pd_low, %edi
|
||||
mov $0, %eax
|
||||
|
||||
// for ecx = 0...64 : Loop and setup 64x 2MB page directories
|
||||
mov $64, %ecx
|
||||
npd_loop:
|
||||
mov %eax, 0(%edi)
|
||||
add $(HUGE_PAGE_SIZE), %eax
|
||||
add $(X86_PAGE_ENTRY_SIZE), %edi
|
||||
|
||||
// end for ecx
|
||||
dec %ecx
|
||||
jnz npd_loop
|
||||
|
||||
//clear out bss section
|
||||
movabs $_sbss, %rbx
|
||||
movabs $_ebss, %rdx
|
||||
clear_bss:
|
||||
movb $0, (%rbx)
|
||||
inc %rbx
|
||||
cmp %rbx, %rdx
|
||||
jne clear_bss
|
||||
|
||||
// Properly setup RSP to idle stack
|
||||
movabs $idle_stack, %rbx
|
||||
add $CONFIG_IDLETHREAD_STACKSIZE, %rbx
|
||||
mov %rbx, %rsp
|
||||
|
||||
|
||||
/* Initialize and start NuttX */
|
||||
call up_lowsetup /* Low-level, pre-OS initialization */
|
||||
|
||||
call nx_start /* Start NuttX */
|
||||
|
||||
/* NuttX will not return */
|
||||
/* We should never end up here */
|
||||
/* If we really do, then we are doomed, halting the processor for ever */
|
||||
|
||||
cli
|
||||
hang:
|
||||
hlt /* Halt machine should NuttX return */
|
||||
jmp hang
|
||||
.size __nxstart, . - __nxstart
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: __enable_sse3
|
||||
*
|
||||
* Description:
|
||||
* Do low-level initialization SSE related processor setting
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
.type __enable_sse3, @function
|
||||
|
||||
__enable_sse3:
|
||||
// Enable SSE
|
||||
mov %cr0, %rax
|
||||
mov $(X86_CR0_EM), %rbx
|
||||
not %rbx
|
||||
and %rbx, %rax
|
||||
or $(X86_CR0_MP), %rax
|
||||
mov %rax, %cr0
|
||||
|
||||
// Enable Saving XMM context
|
||||
mov %cr4, %rax
|
||||
or $(X86_CR4_OSXFSR | X86_CR4_XMMEXCPT), %rax
|
||||
mov %rax, %cr4
|
||||
|
||||
// Setup MXCSR, masking all SSE precision exception
|
||||
ldmxcsr mxcsr_mem
|
||||
|
||||
ret
|
||||
|
||||
.size __enable_sse3, . - __enable_sse3
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: __enable_pcid
|
||||
*
|
||||
* Description:
|
||||
* Enable PCID support
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
.type __enable_pcid, @function
|
||||
|
||||
__enable_pcid:
|
||||
// Enable PCID and FGSBASE
|
||||
mov %cr4, %rax
|
||||
or $X86_CR4_PCIDE, %rax
|
||||
mov %rax, %cr4
|
||||
|
||||
ret
|
||||
|
||||
.size __enable_pcid, . - __enable_pcid
|
||||
|
||||
/****************************************************************************
|
||||
* .data
|
||||
****************************************************************************/
|
||||
|
||||
.section ".loader.data", "ax"
|
||||
|
||||
// IST for 64 bit long mode
|
||||
// will be filled in up_irq
|
||||
.align(16)
|
||||
ist64_low:
|
||||
.long 0
|
||||
.quad 0xdeadbeefdeadbee0
|
||||
.quad 0xdeadbeefdeadbee1
|
||||
.quad 0xdeadbeefdeadbee2
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.quad 0
|
||||
.word 0
|
||||
|
||||
// GDT for 64 bit long mode
|
||||
.align(16)
|
||||
gdt64_low:
|
||||
.quad 0
|
||||
.quad X86_GDT_CODE64_ENTRY
|
||||
.quad X86_GDT_DATA_ENTRY
|
||||
.quad X86_GDT_CODE32_ENTRY
|
||||
.quad X86_GDT_DATA_ENTRY
|
||||
.quad X86_GDT_CODE64_ENTRY
|
||||
gdt64_ist_low:
|
||||
.quad 0x0 // TSS segment low
|
||||
.quad 0x0 // TSS segment high
|
||||
gdt64_low_end:
|
||||
|
||||
gdt64_ptr:
|
||||
.short gdt64_low_end - gdt64_low - 1
|
||||
.long gdt64_low
|
||||
|
||||
mxcsr_mem:
|
||||
.long 0x00001f80
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pml4:
|
||||
.quad pdpt_low + X86_PAGE_PRESENT + X86_PAGE_WR
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pdpt_low:
|
||||
.quad pd_low + X86_PAGE_PRESENT + X86_PAGE_WR
|
||||
.quad pd_2_low + X86_PAGE_PRESENT + X86_PAGE_WR
|
||||
.quad pd_3_low + X86_PAGE_PRESENT + X86_PAGE_WR
|
||||
.quad pd_4_low + X86_PAGE_PRESENT + X86_PAGE_WR
|
||||
|
||||
.fill X86_NUM_PAGE_ENTRY - 4, X86_PAGE_ENTRY_SIZE, 0
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pd_low:
|
||||
.fill X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pd_2_low:
|
||||
.fill X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pd_3_low:
|
||||
.fill X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pd_4_low:
|
||||
.fill X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
|
||||
.align(PAGE_SIZE)
|
||||
pt_low:
|
||||
.fill X86_NUM_PAGE_ENTRY * X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
.fill X86_NUM_PAGE_ENTRY * X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
.fill X86_NUM_PAGE_ENTRY * X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
.fill X86_NUM_PAGE_ENTRY * X86_NUM_PAGE_ENTRY, X86_PAGE_ENTRY_SIZE, 0
|
||||
|
||||
/****************************************************************************
|
||||
* .bss
|
||||
****************************************************************************/
|
||||
|
||||
/* The stack for the IDLE task thread is declared in .bss. NuttX boots and
|
||||
* initializes on the IDLE thread, then at the completion of OS startup, this
|
||||
* thread becomes the thread that executes when there is nothing else to
|
||||
* do in the system (see up_idle()).
|
||||
*/
|
||||
|
||||
.section .bss, "a"
|
||||
|
||||
.type idle_stack, @object
|
||||
.comm idle_stack, CONFIG_IDLETHREAD_STACKSIZE, 32
|
||||
.size idle_stack, CONFIG_IDLETHREAD_STACKSIZE
|
||||
|
||||
/****************************************************************************
|
||||
* .rodata
|
||||
****************************************************************************/
|
||||
|
||||
.section .rodata, "a"
|
||||
|
||||
/* HEAP BASE: _sbss is the start of the BSS region (see ld.script) _ebss is
|
||||
* the end of the BSS region (see liker script). The heap continues from there
|
||||
* until the end of memory.
|
||||
*/
|
||||
|
||||
.type g_idle_topstack, @object
|
||||
g_idle_topstack:
|
||||
.quad _ebss
|
||||
.size g_idle_topstack, . - g_idle_topstack
|
||||
.end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user