Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
138 changes: 138 additions & 0 deletions AMD_XEN_V2000_GCC/Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Makefile.common
#
# Copyright (C) 2025 Advanced Micro Devices, Inc. or its affiliates. All Rights Reserved.
#
# SPDX-License-Identifier: MIT
#
# 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 THE AUTHORS OR
# COPYRIGHT HOLDERS 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.
#

VERSION_HEADER := $(PROJECT_ROOT)/../include/freertos_version.h
KERNEL_DIR := ${FREERTOS_DIR}/Source
XEN_SRC := ${PROJECT_ROOT}/../xen/

$(shell rm -f $(VERSION_HEADER))
BRANCH_NAME := $(shell git describe --tags --exact-match 2>/dev/null || echo "dev")
FREERTOS_BRANCH_NAME := $(shell cd $(KERNEL_DIR) && git describe --tags --abbrev=0 2>/dev/null || echo "dev")
FREERTOS_PLUS_BRANCH_NAME := $(shell cd $(FREERTOS_DIR)/../FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/ && git describe --tags --abbrev=0 2>/dev/null || echo "dev")

INCLUDE_DIRS += -I${PROJECT_ROOT}/include
INCLUDE_DIRS += -I${FREERTOS_DIR}/Demo/Common/include
INCLUDE_DIRS += -I${PROJECT_ROOT}/../include
INCLUDE_DIRS += -I${KERNEL_DIR}/include
INCLUDE_DIRS += -I${PROJECT_ROOT}/../acpica/source/include
INCLUDE_DIRS += -I${XEN_SRC}
INCLUDE_DIRS += -I${XEN_SRC}/include
INCLUDE_DIRS += -I${XEN_SRC}/include/x86
INCLUDE_DIRS += -I${FREERTOS_DIR}/../FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/

SOURCE_FILES = ${PROJECT_ROOT}/../src/main.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/utils.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/serial.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/IRQ.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/ctype_b_loc.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/ctype_loc.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/io.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/ioapic.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/memory.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/print_vga.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/freertos_acpica.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/freertos_xenbus.c
SOURCE_FILES += ${PROJECT_ROOT}/../src/xenbus-watch.c

SOURCE_FILES += ${PROJECT_ROOT}/../cli/cli.c

SOURCE_FILES += ${PROJECT_ROOT}/../Support_Files/galileo-support.c
SOURCE_FILES += ${PROJECT_ROOT}/../Support_Files/printf.c

# application source files
SOURCE_FILES += ${PROJECT_ROOT}/../application/blinky_app.c
SOURCE_FILES += ${PROJECT_ROOT}/../application/app_hooks.c

# Demo Test Files related to Queues, Timers and Tasks
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-timer-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-tasknotify-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-tasknotifyarray-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-blockq-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-genqtest-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-qoverwrite-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-qpeek-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-pollq-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-dynamic-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-blocktim-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-countsem-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-semtest-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-eventgroups-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-msgbuffer-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-streambuffer-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-mutex-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-xenbus-read-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-xenbus-ls-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-gnt-test.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-argo-test.c

SOURCE_FILES += ${PROJECT_ROOT}/../tests/test-cmd.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/register_tests.c
SOURCE_FILES += ${PROJECT_ROOT}/../tests/run-performance-test.c

# Queues Tasks and Timers
SOURCE_FILES += ${FREERTOS_DIR}/Source/list.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/queue.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/tasks.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/timers.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/event_groups.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/croutine.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/stream_buffer.c

# Additional Demo Tests for Queues, Tasks and Timers
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/BlockQ.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/blocktim.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/dynamic.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/GenQTest.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/PollQ.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QPeek.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueOverwrite.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TaskNotify.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TaskNotifyArray.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/countsem.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSet.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferDemo.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/semtest.c


# XEN PVN
SOURCE_FILES += ${XEN_SRC}/console.c
SOURCE_FILES += ${XEN_SRC}/events.c
SOURCE_FILES += ${XEN_SRC}/hypervisor.c
SOURCE_FILES += ${XEN_SRC}/time.c
SOURCE_FILES += ${XEN_SRC}/mm.c
SOURCE_FILES += ${XEN_SRC}/e820.c
SOURCE_FILES += ${XEN_SRC}/lib/printf.c
SOURCE_FILES += ${XEN_SRC}/lib/string.c
SOURCE_FILES += ${XEN_SRC}/gnttab.c
SOURCE_FILES += ${XEN_SRC}/gntmap.c
SOURCE_FILES += ${XEN_SRC}/argo.c

# FreeRTOS CLI Common Wrapper
SOURCE_FILES += ${FREERTOS_DIR}/../FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c

$(VERSION_HEADER):
@echo "#ifndef FREERTOS_VERSION_H" > $(VERSION_HEADER)
@echo "#define FREERTOS_VERSION_H" >> $(VERSION_HEADER)
@echo "#define FREERTOS_VERSION \"$(BRANCH_NAME), FreeRTOS:${FREERTOS_BRANCH_NAME}, FreeRTOS-Plus-CLI:${FREERTOS_PLUS_BRANCH_NAME}\"" >> $(VERSION_HEADER)
@echo "#endif // FREERTOS_VERSION_H" >> $(VERSION_HEADER)
119 changes: 119 additions & 0 deletions AMD_XEN_V2000_GCC/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# FreeRTOS port for Xen
This repository contains source for FreeRTOS port for xen.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source for port or source for demo?


# FreeRTOS port to Xen HVM

## Setup Build Environement

1. Build Host Operating System - Ubuntu 22.04
2. Install Dependencies

`apt install -y build-essential grub-common mtools nasm xorriso gcc-multilib`


## Build FreeRTOS
1. Clone FreeRTOS repository

`cd $HOME`

`git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules`

`cd FreeRTOS/FreeRTOS/Source/`

`git checkout V11.2.0`

The above common will clone FreeRTOS resposity in the current working directoy, FreeRTOS kernel source will be cloned under FreeRTOS/FreeRTOS/Source.

2. Build 32-bit FreeRTOS port

export FREERTOS_DIR=<path containing Source folder from cloned FreeRTOS repository>

for example export FREERTOS_DIR=$HOME/FreeRTOS/FreeRTOS if git clone for FreeRTOS was done under home directory

`export FREERTOS_DIR=$HOME/FreeRTOS/FreeRTOS`

`cd $HOME`

`git clone https://github.com/AMD-EMBAUTO/FreeRTOS/ FreeRTOS-X86`

`cd FreeRTOS-X86`

`git checkout v4.0`

`cd port_32`

`make clean`

`make`

Make will generate an image file in output/freertos-v4.0-x86_32.iso
3. Build 64-bit FreeRTOS port

export FREERTOS_DIR=<path containing Source folder from cloned FreeRTOS repository>

for example export FREERTOS_DIR=$HOME/FreeRTOS/FreeRTOS if git clone for FreeRTOS was done under home directory

`export FREERTOS_DIR=$HOME/FreeRTOS/FreeRTOS`

`cd $HOME`

`git clone https://github.com/AMD-EMBAUTO/FreeRTOS/ FreeRTOS-X86`

`cd FreeRTOS-X86`

`git checkout v4.0`

`cd port_64`

`make clean`

`make`

Make will generate an image file in output/freertos-v4.0-x86_64.iso

## Create FreeRTOS xen HVM on Celadon board with Yocto

1. Copy HVM and ISO files to board

use scp command to copy following files
- freertos-v4.0-x86_32.iso
- freertos32_v4.0.bin
- freertos_x86_32.hvm
- freertos_x86_32.pvh
- freertos-v4.0-x86_64.iso
- freertos64_v4.0.bin
- freertos_x86_64.pvh
- freertos_x86_64.hvm

2. Launch FreeRTOS xen HVM

*32-bit*

`xl create freertos_x86_32.hvm`

*64-bit*

`xl create freertos_x86_64.hvm`

3. Launch FreeRTOS xen PVH

*32-bit*

`xl create freertos_x86_32.pvh`

*64-bit*

`xl create freertos_x86_64.pvh`

4. Check DomU created

`xl list`

5. Connect to console using minicom debug port
- find domain id using xl list
- xenstore-read /local/domain/{domain_id}/console/tty
- minicom -D <output_of_above_command>

6. Connect to xl console
- xl console <domain_id|domain_name>

140 changes: 140 additions & 0 deletions AMD_XEN_V2000_GCC/Support_Files/galileo-support.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*--------------------------------------------------------------------
Copyright(c) 2015 Intel Corporation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------*/

/*-----------------------------------------------------------------------
* Any required includes
*------------------------------------------------------------------------
*/
#include "multiboot.h"
#include "galileo_support.h"
#include "serial.h"
#include "stdlib.h"
#include "string.h"
#include "desc.h"

/*-----------------------------------------------------------------------
* Any required local definitions
*------------------------------------------------------------------------
*/


#if defined(__i386__)
uint32_t bootinfo = 1UL;
uint32_t bootsign = 1UL;


#define INTR_STACK_SIZE PAGE_SIZE
static uint8_t intr_stack[INTR_STACK_SIZE] __attribute__((aligned(16)));

hw_tss tss __attribute__((aligned(16))) =
{
#if defined(__i386__)
.esp0 = (unsigned long)&intr_stack[INTR_STACK_SIZE],
.ss0 = __KERN_DS,
#elif defined(__x86_64__)
.rsp0 = (unsigned long)&intr_stack[INTR_STACK_SIZE],
#endif
.iopb = X86_TSS_INVALID_IO_BITMAP,
};


/*------------------------------------------------------------------------
* GDT default entries (used in GDT setup code)
*------------------------------------------------------------------------
*/
static struct sd gdt_default[NGDE] =
{
/* sd_lolimit sd_lobase sd_midbase sd_access sd_hilim_fl sd_hibase */
/* 0th entry NULL */
{ 0, 0, 0, 0, 0, 0, },
/* 1st, Kernel Code Segment */
{ 0xffff, 0, 0, 0x9a, 0xcf, 0, },
/* 2nd, Kernel Data Segment */
{ 0xffff, 0, 0, 0x92, 0xcf, 0, },
/* 3rd, Kernel Stack Segment */
{ 0xffff, 0, 0, 0x92, 0xcf, 0, },
/* 4st, Boot Code Segment */
{ 0xffff, 0, 0, 0x9a, 0xcf, 0, },
/* 5th, Code Segment for BIOS32 request */
{ 0xffff, 0, 0, 0x9a, 0xcf, 0, },
/* 6th, Data Segment for BIOS32 request */
{ 0xffff, 0, 0, 0x92, 0xcf, 0, },
};

extern struct sd gdt[]; /* Global segment table (defined in startup.S) */

/*------------------------------------------------------------------------
* Set segment registers (used in GDT setup code)
*------------------------------------------------------------------------
*/
void setsegs()
{
extern int __text_end;
struct sd *psd;
uint32_t np, ds_end;

ds_end = 0xffffffff/PAGE_SIZE; /* End page number */

psd = &gdt_default[1]; /* Kernel code segment */
np = ((int)&__text_end - 0 + PAGE_SIZE-1) / PAGE_SIZE; /* Number of code pages */
psd->sd_lolimit = np;
psd->sd_hilim_fl = FLAGS_SETTINGS | ((np >> 16) & 0xff);

psd = &gdt_default[2]; /* Kernel data segment */
psd->sd_lolimit = ds_end;
psd->sd_hilim_fl = FLAGS_SETTINGS | ((ds_end >> 16) & 0xff);

psd = &gdt_default[3]; /* Kernel stack segment */
psd->sd_lolimit = ds_end;
psd->sd_hilim_fl = FLAGS_SETTINGS | ((ds_end >> 16) & 0xff);

psd = &gdt_default[4]; /* Boot code segment */
psd->sd_lolimit = ds_end;
psd->sd_hilim_fl = FLAGS_SETTINGS | ((ds_end >> 16) & 0xff);

#if 0
extern hw_tss tss;
psd = &gdt_default[7]; /* Boot code segment */
uint32_t base=&tss;
uint32_t limit=0x67;
uint32_t attr=0x89;
psd->sd_lolimit = limit&0xffff;
psd->sd_lobase = base&0xffff;
psd->sd_midbase = (base&0x00ff0000)>>16;
psd->sd_access = attr;
psd->sd_hilim_fl = 0;
psd->sd_hibase = (base&0xff000000)>>24;
printf("base: %x\n",base);
printf("%x %x %x %x %x %x\n",psd->sd_lolimit,psd->sd_lobase,psd->sd_midbase,psd->sd_access,psd->sd_hilim_fl,psd->sd_hibase);
#endif
memcpy(gdt, gdt_default, sizeof(gdt_default));

}
#endif
Loading