I recently started James Molly's Kernel Devolpment Tutorials and has come as far as implementing the GDT and IDT .
The problem arises when I link together the high level functions with their low level assembly counterparts .
You can Find the Code here
Source on Github
Here is the Directory Structure
.
|-- arch
|-- boot
| |-- boot.s
| |-- buildboot.sh
| |-- gdt.s
| |-- idt.s
| `-- interrupt.s
|-- build
| |-- boot.s.o
| |-- gdt.o
| |-- gdt.s.o
| |-- idt.o
| |-- idt.s.o
| |-- interrupt.s.o
| |-- io.o
| |-- isr.o
| |-- main.o
| |-- memory.o
| |-- monitor.o
| `-- stdlib.o
|-- doc
| `-- Bug_Log.md
|-- include
| |-- gdt.cc
| |-- gdt.h
| |-- gdt.o
| |-- idt.cc
| |-- idt.h
| |-- idt.o
| |-- io.cc
| |-- io.h
| |-- io.o
| |-- isr.cc
| |-- isr.h
| |-- isr.o
| |-- memory.cc
| |-- memory.h
| |-- memory.o
| |-- monitor.cc
| |-- monitor.h
| |-- monitor.o
| |-- SConstruct
| |-- stdlib.cc
| |-- stdlib.h
| |-- stdlib.o
| `-- system.h
|-- JOSMake.sh
|-- link.ld
|-- main.cc
`-- ReadMe.md
Here is the Bash Scripts
JOSmake.sh
#
# Build File for JOS
#
# To Build
# bash build.sh
# To Run
# bash run.sh
# ----------------------------------------------------------------------------------------------
# JOS uses assembly to build the bootsector
# Compile the boot Sectors in boot
echo "==============================================="
echo "-------- Building Boot Sectors ----------------"
cd boot
# Run the Make Script inside the boot directory
bash buildboot.sh
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# Compile the C++ Sources into Respective Objects
# Compile main.cc
echo "==============================================="
echo "--------- Compiling C++ Sources --------------"
g++ -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 -o main.o main.cc
mv main.o build
# Run scons to build the Entire Lbrary of C++ Files
cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
## When Everything is Finished Link together the Objects into a Kernel File
echo "==============================================="
echo "--------- Linking ----------------"
cd build
# require ld , link.ld
ld -T '../link.ld' -m elf_i386 -o kernel.jos *.o
# Clean Up After Build
#rm *.o
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
## When Everything is Finished Run the Kernel
qemu-system-i386 -kernel kernel.jos
# -----------------------------------------------------------------------------------------
Here is the buildboot.sh
# Builds the Boot files for JOS
# require 'nasm'
# Add all the Assembly Files Here
nasm -f elf -o boot.s.o boot.s
nasm -f elf -o gdt.s.o gdt.s
nasm -f elf -o idt.s.o idt.s
nasm -f elf -o interrupt.s.o interrupt.s
# Move the Entire Object Files into the Build Directory
mv *.o ../build
And here is the Terminal Output when I run the Script
===============================================
-------- Building Boot Sectors ----------------
===============================================
===============================================
--------- Compiling C++ Sources --------------
In file included from include/system.h:22:0,
from main.cc:6:
include/idt.h:34:13: warning: ‘void init_idt()’ used but never defined
static void init_idt();
^
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o gdt.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 gdt.cc
g++ -o idt.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 idt.cc
g++ -o io.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 io.cc
g++ -o isr.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 isr.cc
g++ -o memory.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 memory.cc
g++ -o monitor.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 monitor.cc
g++ -o stdlib.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 stdlib.cc
scons: done building targets.
===============================================
===============================================
--------- Linking ----------------
gdt.o: In function `init_gdt()':
gdt.cc:(.text+0xb0): undefined reference to `gdt_flush(unsigned int)'
idt.o: In function `init_idt()':
idt.cc:(.text+0x3a): undefined reference to `isr0()'
idt.cc:(.text+0x51): undefined reference to `isr1()'
idt.cc:(.text+0x68): undefined reference to `isr2()'
idt.cc:(.text+0x7f): undefined reference to `isr3()'
idt.cc:(.text+0x96): undefined reference to `isr4()'
idt.cc:(.text+0xad): undefined reference to `isr5()'
idt.cc:(.text+0xc4): undefined reference to `isr6()'
idt.cc:(.text+0xdb): undefined reference to `isr7()'
idt.cc:(.text+0xf2): undefined reference to `isr8()'
idt.cc:(.text+0x109): undefined reference to `isr9()'
idt.cc:(.text+0x120): undefined reference to `isr10()'
idt.cc:(.text+0x137): undefined reference to `isr11()'
idt.cc:(.text+0x14e): undefined reference to `isr12()'
idt.cc:(.text+0x165): undefined reference to `isr13()'
idt.cc:(.text+0x17c): undefined reference to `isr14()'
idt.cc:(.text+0x193): undefined reference to `isr15()'
idt.cc:(.text+0x1aa): undefined reference to `isr16()'
idt.cc:(.text+0x1c1): undefined reference to `isr17()'
idt.cc:(.text+0x1d8): undefined reference to `isr18()'
idt.cc:(.text+0x1ef): undefined reference to `isr19()'
idt.cc:(.text+0x206): undefined reference to `isr20()'
idt.cc:(.text+0x21d): undefined reference to `isr21()'
idt.cc:(.text+0x234): undefined reference to `isr22()'
idt.cc:(.text+0x24b): undefined reference to `isr23()'
idt.cc:(.text+0x262): undefined reference to `isr24()'
idt.cc:(.text+0x279): undefined reference to `isr25()'
idt.cc:(.text+0x290): undefined reference to `isr26()'
idt.cc:(.text+0x2a7): undefined reference to `isr27()'
idt.cc:(.text+0x2be): undefined reference to `isr28()'
idt.cc:(.text+0x2d5): undefined reference to `isr29()'
idt.cc:(.text+0x2ec): undefined reference to `isr30()'
idt.cc:(.text+0x303): undefined reference to `isr31()'
idt.cc:(.text+0x323): undefined reference to `idt_flush(unsigned int)'
interrupt.s.o: In function `isr_common_stub':
interrupt.s:(.text+0x10d): undefined reference to `isr_handler'
main.o: In function `main':
main.cc:(.text+0x17): undefined reference to `init_idt()'
===============================================
qemu: could not load kernel 'kernel.jos': No such file or directory
Could anyone Point out what Iam Doing Wrong
This looks like a name mangling issue.
The guide you're following is written in C, and your IDT code would probably work if it were compiled using GCC instead of G++. However if you choose to use C++ you need to make some changes to allow referring to assembler functions from C++ and vice versa.
Function names in C and assembler map directly to symbol names, but C++ by default adds some extra text to the symbol name to include information about classes, namespaces, overloading etc.
To make sure that your C++ code can refer to the assembler functions using the correct symbol name, you must tell the compiler to use C linkage for those functions.
Look for places in your C++ header files where you declare functions that are implemented in assembler, for example: the isrN() functions in idt.hh
.
Wrap those declarations in a C linkage block like so:
extern "C" {
extern int isr0();
extern int isr1();
// ... and so on for all your ASM functions.
}
And do the same for C++ functions that should be callable from assembler.
Related
I'm using C-preprocessor to get conditional-code, code-include and real constants in Lua. Unfortunately VS-Code / Lua gets confused about the #-directives in the lua code.
Is there a way to somehow exclude these lines from the parsing of the lua-extension?
As you are using external tooling already I'd just replace the # with --# and preprocess it once more:
test.lua:
--# if defined(TEST)
print("test defined:", TEST)
--# else
print("test not defined")
--# endif
❯ cat test.lua | sed -r 's:--#:#:g' | gcc -E -P -xc - | luajit
test not defined
❯ cat test.lua | sed -r 's:--#:#:g' | gcc -E -P -DTEST=42 -xc - | luajit
test defined: 42
It might be helpful to use the Better Comments extension and define the '#' to be highlighted.
I am running this from my terminal:
cp build/*.js /Users/amin/servers/tomcat/work/static/vaadin/
But the command just shows me usage instructions, and does not copy the files:
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
Does anyone know what I did wrong?
This happened to me once, and my problem was that the directory I was copying to, didn't exist. Does yours?
I am trying to (cross-)compile Bazel 0.4.5 in the Yocto system. The target is an ARMv7 and the Linux distro is Poky.
I am getting this compilation error:
| � Building Bazel with Bazel.
| ................................
| ____Loading package: src
| ____Loading package: #bazel_tools//tools/cpp
| ____Loading package: #local_config_xcode//
| ERROR: in target '//external:cc_toolchain': no such package '#local_config_cc//': Traceback (most recent call last):
| File "/home/giuseppe/.cache/bazel/_bazel_giuseppe/32d64188b76850bf1edfd4141b911134/external/bazel_tools/tools/cpp/cc_configure.bzl", line 584
| _find_cc(repository_ctx)
| File "/home/giuseppe/.cache/bazel/_bazel_giuseppe/32d64188b76850bf1edfd4141b911134/external/bazel_tools/tools/cpp/cc_configure.bzl", line 383, in _find_cc
| repository_ctx.which(cc_name)
| Program argument of which() may not contains a / or a \ ('arm-poky-linux-gnueabi-gcc -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/home/giuseppe/research/projects/zynq/yocto/build/tmp/sysroots/zc702-zynq7' given).
| ____Elapsed time: 3.851s
Do you have any suggestions?
Thank you
Maybe you can take a look at the meta-tensorflow layer. Link:
http://layers.openembedded.org/layerindex/branch/master/layer/meta-tensorflow/
I need to edit files with specific pattern in their names. These files are spread across multiple hierarchical directories.
I am using find followed by sed with the help of xargs to achieve the same as follows:
find . -type f -name "file*" | sed -i.bak 's/word1/replace_word1/g'
My problem is that now I want to revert back the changes from backup files (*.bak). Sample directory tree will look like as shown below. I am looking for linux command (may be a chain) to achieve the same.
$ tree
.
|-- pdir1
| |-- dir1
| | |-- dir2
| | | |-- file2
| | | `-- file2.bak
| | |-- file1
| | `-- file1.bak
| `-- dir3
| |-- file3
| `-- file3.bak
`-- pdir2
|-- file1
`-- file1.bak
I can find all backup files using following find command. But can't figure out what to do next. It would be appreciable if your could help me solve this.
find . -type f -name "file*.bak"
Note
I observe this problem as general scenario. I had faced this many times but got away with writing a small wrapper script for it. Here I am hoping for a generic and concise solution.
One option could be use rename with find:
find . -type f -name "*.bak" -exec rename 's/\.bak$//' {} \;
This would not rename foo.bak if foo exists. In order to force overwriting, use the -f option for rename:
find . -type f -name "*.bak" -exec rename -f 's/\.bak$//' {} \;
EDIT: If you can't use rename, try:
find . -name "*.bak" -exec sh -c 'mv -f $0 ${0%.bak}' {} \;
Explanation of the above (last) command: For each result returned by find, a shell command is invoked that takes the result as a parameter (denoted by {}) for mv -f $0 ${0%.bak}. $0 is a positional parameter and ${0%.bak} denotes shell parameter expansion for removing .bak from the end of the parameter. In effect, for a result foo.bak, the shell would issue a command mv -f foo.bak foo.
You can restore simply with a for loop that traverse directories. It doesn't check if the file without the bak extension exists.
for f in **/*.bak; do mv -- "$f" "${f%.bak}"; done
here is the output from the console in Eclipse:
**** Build of configuration Debug for project FatFstest ****
make all
make: *** No rule to make target `main.o', needed by `FatFstest.elf'. Stop.
I am trying to build a project using the AVR plugin for Eclipse to test the FatFs library. I first imported the FatFs code then created main.c file to implement it. After I tried building it the first time, I added the src folder of my project to my the directories list in Properties > AVR Compiler > Directories, and I still get the build error. Any help?
Here is my makefile:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include src/subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_DEPS)),)
-include $(S_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
LSS += \
FatFstest.lss \
SIZEDUMMY += \
sizedummy \
AVRDUDEDUMMY += \
avrdudedummy \
# All Target
all: FatFstest.elf secondary-outputs
# Tool invocations
FatFstest.elf: $(OBJS) $(USER_OBJS)
#echo 'Building target: $#'
#echo 'Invoking: AVR C Linker'
avr-gcc -Wl,-Map,FatFstest.map -mmcu=atmega328p -o"FatFstest.elf" $(OBJS) $(USER_OBJS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
FatFstest.lss: FatFstest.elf
#echo 'Invoking: AVR Create Extended Listing'
-avr-objdump -h -S FatFstest.elf >"FatFstest.lss"
#echo 'Finished building: $#'
#echo ' '
sizedummy: FatFstest.elf
#echo 'Invoking: Print Size'
-avr-size --format=avr --mcu=atmega328p FatFstest.elf
#echo 'Finished building: $#'
#echo ' '
avrdudedummy: FatFstest.elf
#echo 'Invoking: AVRDude'
/usr/local/CrossPack-AVR-20100115/bin/avrdude -pm328p -Uflash:w:FatFstest.hex:a
#echo 'Finished building: $#'
#echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(ASM_DEPS)$(ELFS)$(LSS)$(AVRDUDEDUMMY)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS) FatFstest.elf
-#echo ' '
secondary-outputs: $(LSS) $(SIZEDUMMY) $(AVRDUDEDUMMY)
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
main.c
#include <diskio.h>
#include <ff.h>
#include <stdio.h>
int main(void)
{
printf("hello world\n");
return 0;
}
subdir.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../src/diskio.c \
../src/ff.c \
../src/main.c
OBJS += \
./src/diskio.o \
./src/ff.o \
./src/main.o
C_DEPS += \
./src/diskio.d \
./src/ff.d \
./src/main.d
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c
#echo 'Building file: $<'
#echo 'Invoking: AVR Compiler'
avr-gcc -I"/Users/nathannewcomb/Documents/Puzzles/FatFstest/src" -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -c -o"$#" "$<"
#echo 'Finished building: $<'
#echo ' '
objects.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS :=
sources.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
O_SRCS :=
C_SRCS :=
S_UPPER_SRCS :=
S_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
OBJS :=
C_DEPS :=
ASM_DEPS :=
ELFS :=
LSS :=
AVRDUDEDUMMY :=
S_DEPS :=
SIZEDUMMY :=
S_UPPER_DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
src \
It happened to me too, simply moving main.cpp in an another folder.
I try to clean out the project, but the problem persist, so I have deleted Debug folder, re-compile and it works!
Don't put the main.c in a directory, put it at the top of its project
I added the src folder of my project to my the directories list in
Properties > AVR Compiler > Directories
Remove this /Users/nathannewcomb/Documents/Puzzles/FatFstest/src folder and try to compile again.
In the subdir.mk file, the line :
avr-gcc -I"/Users/nathannewcomb/Documents/Puzzles/FatFstest/src" -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -c -o"$#" "$<"
should be become :
avr-gcc -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -c -o"$#" "$<"
This src folder is already added in source.mk file :
# Every subdirectory with source files must be described here
SUBDIRS := \
src \
quoting eclipse - http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Fconcepts%2Fcdt_c_makefile.htm
Q2. My Console view says No rule to make target 'X'.
make -k clean all
make: * No rule to make target 'clean'.
make: * No rule to make target 'all'.
By default, the make program looks for a file most commonly called "Makefile" or "makefile". If it cannot find such a file in the working directory, or if that file is empty or the file does not contain rules for the command line goals ("clean" and "all" in this case), it will normally fail with an error message similar to those shown.
If you already have a valid Makefile, you may need to change the working directory of your build. The default working directory for the build command is the project's root directory. You can change this by specifying an alternate Build Directory in the Make Project properties. Or, if your Makefile is named something else (eg. buildFile.mk), you can specify the name by setting the default Build command to make -f buildFile.mk.
If you do not have a valid Makefile, create a new file named Makefile in the root directory. You can then add the contents of the sample Makefile (above), and modify it as appropriate.