ゼロからのOS自作入門
https://www.youtube.com/playlist?list=PLbBGNsln3DxTLHB9GFM6_drAJ1JQXIOud
code: zsh
OS_DIR=/workspaces/mikanos-devcontainer/mikanos
code: zsh
xhost + 127.0.0.1
code: zsh
cd $OS_DIR
code: zsh
git checkout osbook_day04b
code: zsh
source ~/osbook/devenv/buildenv.sh
code: zsh
APPS_DIR=apps RESOURCE_DIR=resource ./build.sh run
code: zsh
./build.sh run
code: zsh
cd kernel
code: zsh
make
code: zsh
cd ~/edk2
code: zsh
source edksetup.sh
code: zsh
build
code: zsh
~/osbook/devenv/run_qemu.sh ~/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/Loader.efi $OS_DIR/kernel/kernel.elf
code: frame_buffer_config.cpp
enum PixelFormat {
kPixelRGBResv8BitPerColor,
kPixelBGRResv8BitPerColor,
};
struct FrameBufferConfig {
unsigned char* frame_buffer;
unsigned int pixels_per_scan_line;
unsigned int horizontal_resolution;
unsigned int vertical_resolution;
enum PixelFormat pixel_format;
};
code: elf.hpp
typedef unsigned long Elf64_Addr;
typedef unsigned long Elf64_Off;
typedef unsigned char Elf64_Half;
typedef unsigned int Elf64_Word;
typedef int Elf64_Sword;
typedef unsigned long Elf64_Xword;
typedef long Elf64_Sxword;
code: graphics.hpp
struct PixelColor {
unsigned char r, g, b;
};
class FrameBufferWriter : public PixelWriter {
public:
FrameBufferWriter(const FrameBufferConfig& config) : config_{config} {
}
virtual ~FrameBufferWriter() = default;
virtual int Width() const override { return config_.horizontal_resolution; }
virtual int Height() const override { return config_.vertical_resolution; }
protected:
unsigned char* PixelAt(int x, int y) {
return config_.frame_buffer + 4 * (config_.pixels_per_scan_line * y + x);
}
private:
const FrameBufferConfig& config_;
};
code:font.cpp
extern const unsigned char _binary_hankaku_bin_start;
extern const unsigned char _binary_hankaku_bin_end;
extern const unsigned char _binary_hankaku_bin_size;
const unsigned char* GetFont(char c) {
auto index = 16 * static_cast<unsigned int>(c);
if (index >= reinterpret_cast<uintptr_t>(&_binary_hankaku_bin_size)) {
return nullptr;
}
return &_binary_hankaku_bin_start + index;
}
void WriteAscii(PixelWriter& writer, Vector2D<int> pos, char c, const PixelColor& color) {
const unsigned char* font = GetFont(c);
if (font == nullptr) {
return;
}
for (int dy = 0; dy < 16; ++dy) {
for (int dx = 0; dx < 8; ++dx) {
if ((fontdy << dx) & 0x80u) { writer.Write(pos + Vector2D<int>{dx, dy}, color);
}
}
}
}
code: memory_map.hpp
struct MemoryMap {
unsigned long long buffer_size;
void* buffer;
unsigned long long map_size;
unsigned long long map_key;
unsigned long long descriptor_size;
unsigned int descriptor_version;
};
struct MemoryDescriptor {
unsigned int type;
unsigned long physical_start;
unsigned long virtual_start;
unsigned long number_of_pages;
unsigned long attribute;
};
enum class MemoryType {
kEfiReservedMemoryType,
kEfiLoaderCode,
kEfiLoaderData,
kEfiBootServicesCode,
kEfiBootServicesData,
kEfiRuntimeServicesCode,
kEfiRuntimeServicesData,
kEfiConventionalMemory,
kEfiUnusableMemory,
kEfiACPIReclaimMemory,
kEfiACPIMemoryNVS,
kEfiMemoryMappedIO,
kEfiMemoryMappedIOPortSpace,
kEfiPalCode,
kEfiPersistentMemory,
kEfiMaxMemoryType
};
inline bool operator==(unsigned int lhs, MemoryType rhs) {
return lhs == static_cast<unsigned int>(rhs);
}
inline bool operator==(MemoryType lhs, unsigned int rhs) {
return rhs == lhs;
}
day1
https://scrapbox.io/files/6353938541ae45001d954cd1.JPG
code: zsh
$ sudo apt install ansible
E: いくつかのアーカイブを取得できません。apt-get update を実行するか --fix-missing オプションを付けて試してみてください。
code: zsh
$ sudo apt install ansible --fix-missing
$ ansible --version
config file = /etc/ansible/ansible.cfg
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 22 2022, 20:18:18) GCC 9.4.0 jinja version = 2.10.1
libyaml = True
code:zsh
$ ansible-playbook -K -i ansible_inventory ansible_provision.yml
BECOME password:
PLAY all ************************************************************************************************************************************************************** TASK Gathering Facts ************************************************************************************************************************************************** code: zsh
vscode ➜ ~/osbook/day01/c (master ✗) $ make
clang -target x86_64-pc-win32-coff -o hello.o -c hello.c
lld-link /subsystem:efi_application /entry:EfiMain /out:hello.efi hello.o
rm hello.o
https://scrapbox.io/files/6354b89d166a09001da5e5ce.png
day2
code: zsh
vscode ➜ ~/edk2 (tags/edk2-stable202105~127 ✗) $ build
Build environment: Linux-5.10.124-linuxkit-aarch64-with-glibc2.29
Build start time: 01:55:58, Oct.25 2022
WORKSPACE = /home/vscode/edk2
EDK_TOOLS_PATH = /home/vscode/edk2/BaseTools
CONF_PATH = /home/vscode/edk2/Conf
PYTHON_COMMAND = /usr/bin/python3.8
build.py...
: error 000E: File/directory not found in workspace
/home/vscode/edk2/MikanLoaderPkg/MikanLoaderPkg.dsc (Please give file in absolute path or relative to WORKSPACE)
- Failed -
Build end time: 01:55:58, Oct.25 2022
Build total time: 00:00:00
code: zsh
vscode ➜ ~/edk2 $ ln -s $OS_DIR/MikanLoaderPkg ./
https://scrapbox.io/files/63574427fe226f0023686155.png
https://scrapbox.io/files/63574ab3bf3780001d94d2fc.png
code: zsh
vscode ➜ ~/edk2 (tags/edk2-stable202105~127 ✗) $ cat mnt/memmap
Index, Type, Type(name), PhysicalStart, NumberOfPages, Attribute
0, 3, EfiBootServicesCode, 00000000, 1, F
1, 7, EfiConventionalMemory, 00001000, 9F, F
2, 7, EfiConventionalMemory, 00100000, 700, F
3, A, EfiACPIMemoryNVS, 00800000, 8, F
4, 7, EfiConventionalMemory, 00808000, 8, F
5, A, EfiACPIMemoryNVS, 00810000, F0, F
6, 4, EfiBootServicesData, 00900000, B00, F
7, 7, EfiConventionalMemory, 01400000, 3AB36, F
8, 4, EfiBootServicesData, 3BF36000, 20, F
9, 7, EfiConventionalMemory, 3BF56000, 270C, F
10, 1, EfiLoaderCode, 3E662000, 2, F
11, 4, EfiBootServicesData, 3E664000, 219, F
12, 3, EfiBootServicesCode, 3E87D000, B7, F
13, A, EfiACPIMemoryNVS, 3E934000, 12, F
14, 0, EfiReservedMemoryType, 3E946000, 1C, F
15, 3, EfiBootServicesCode, 3E962000, 10A, F
16, 6, EfiRuntimeServicesData, 3EA6C000, 5, F
17, 5, EfiRuntimeServicesCode, 3EA71000, 5, F
18, 6, EfiRuntimeServicesData, 3EA76000, 5, F
19, 5, EfiRuntimeServicesCode, 3EA7B000, 5, F
20, 6, EfiRuntimeServicesData, 3EA80000, 5, F
21, 5, EfiRuntimeServicesCode, 3EA85000, 7, F
22, 6, EfiRuntimeServicesData, 3EA8C000, 8F, F
23, 4, EfiBootServicesData, 3EB1B000, 4DA, F
24, 7, EfiConventionalMemory, 3EFF5000, 4, F
25, 4, EfiBootServicesData, 3EFF9000, 6, F
26, 7, EfiConventionalMemory, 3EFFF000, 1, F
27, 4, EfiBootServicesData, 3F000000, A1B, F
28, 7, EfiConventionalMemory, 3FA1B000, 1, F
29, 3, EfiBootServicesCode, 3FA1C000, 17F, F
30, 5, EfiRuntimeServicesCode, 3FB9B000, 30, F
31, 6, EfiRuntimeServicesData, 3FBCB000, 24, F
32, 0, EfiReservedMemoryType, 3FBEF000, 4, F
33, 9, EfiACPIReclaimMemory, 3FBF3000, 8, F
34, A, EfiACPIMemoryNVS, 3FBFB000, 4, F
35, 4, EfiBootServicesData, 3FBFF000, 201, F
36, 7, EfiConventionalMemory, 3FE00000, 8D, F
37, 4, EfiBootServicesData, 3FE8D000, 20, F
38, 3, EfiBootServicesCode, 3FEAD000, 20, F
39, 4, EfiBootServicesData, 3FECD000, 9, F
40, 3, EfiBootServicesCode, 3FED6000, 1E, F
41, 6, EfiRuntimeServicesData, 3FEF4000, 84, F
42, A, EfiACPIMemoryNVS, 3FF78000, 88, F
43, 6, EfiRuntimeServicesData, FFC00000, 400, 1
day3
code: zsh
vscode ➜ ~/edk2 (tags/edk2-stable202105~127 ✗) $ build
Build environment: Linux-5.10.124-linuxkit-aarch64-with-glibc2.29
Build start time: 01:46:27, Oct.29 2022
WORKSPACE = /home/vscode/edk2
EDK_TOOLS_PATH = /home/vscode/edk2/BaseTools
CONF_PATH = /home/vscode/edk2/Conf
PYTHON_COMMAND = /usr/bin/python3.8
Processing meta-data .
Architecture(s) = X64
Build target = DEBUG
Toolchain = CLANG38
Active Platform = /home/vscode/edk2/MikanLoaderPkg/MikanLoaderPkg.dsc
done!
Building ... /home/vscode/edk2/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiLib/UefiLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BasePrintLib/BasePrintLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BaseLib/BaseLib.inf X64 Building ... /home/vscode/edk2/MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf X64 make: Nothing to be done for 'tbuild'.
make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MikanLoaderPkg/Loader.inf X64 "clang" -MMD -MF /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Main.obj.deps -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=LoaderStrings -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -Oz -flto -target x86_64-pc-linux-gnu -g -c -o /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/./Main.obj -I/home/vscode/edk2/MikanLoaderPkg -I/home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG -I/home/vscode/edk2/MdePkg -I/home/vscode/edk2/MdePkg/Include -I/home/vscode/edk2/MdePkg/Test/UnitTest/Include -I/home/vscode/edk2/MdePkg/Include/X64 /home/vscode/edk2/MikanLoaderPkg/Main.c
rm -f /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Loader.lib
"llvm-ar" cr /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Loader.lib @/home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/object_files.lst
"clang" -o /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.dll -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40 -Wl,--entry,_ModuleEntryPoint -u _ModuleEntryPoint -Wl,-Map,/home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.map,--whole-archive -flto -Wl,-Oz -Wl,-melf_x86_64 -Wl,--oformat=elf64-x86-64 -Wl,-pie -mcmodel=small -Wl,--start-group,@/home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/static_library_files.lst,--end-group -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=LoaderStrings -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -Oz -flto -target x86_64-pc-linux-gnu -g -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 -Wl,--script=/home/vscode/edk2/BaseTools/Scripts/GccBase.lds -Wno-error -O3
"objcopy" /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.dll
cp -f /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.dll /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.debug
objcopy --strip-unneeded -R .eh_frame /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.dll
objcopy --add-gnu-debuglink=/home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.debug /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.dll
cp -f /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.debug /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/Loader.debug
"GenFw" -e UEFI_APPLICATION -o /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Loader.efi /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/Loader.dll
cp -f /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Loader.efi /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG
cp -f /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Loader.efi /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/Loader.efi
cp -f /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG/*.map /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT
- Done -
Build end time: 01:46:28, Oct.29 2022
Build total time: 00:00:01
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ ~/osbook/devenv/run_qemu.sh ~/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/Loader.efi
(qemu) x /4xb 0x067ae4c4
00000000067ae4c4: 0x00 0x00 0x00 0x00
(qemu) x /2i 0x067ae4c4
0x067ae4c4: 00 00 addb %al, (%rax)
0x067ae4c6: 00 00 addb %al, (%rax)
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer/mikanos/kernel (tags/osbook_day03a ✗) $ readelf -h kernel.elf
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x101000
https://scrapbox.io/files/635b3498fbf1730022a9f5f0.png
code: zsh
(qemu) x /2i 0x101011
0x00101011: eb fd jmp 0x101010
0x00101013: cc int3
(qemu) x /2i 0x101010
0x00101010: f4 hlt
0x00101011: eb fd jmp 0x101010
https://scrapbox.io/files/635b36e2e613790023a54f73.png
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer/mikanos (tags/osbook_day03c ✗) $ echo $CPPFLAGS
-I/home/vscode/osbook/devenv/x86_64-elf/include/c++/v1 -I/home/vscode/osbook/devenv/x86_64-elf/include -I/home/vscode/osbook/devenv/x86_64-elf/include/freetype2 -I/home/vscode/edk2/MdePkg/Include -I/home/vscode/edk2/MdePkg/Include/X64 -nostdlibinc -D__ELF__ -D_LDBL_EQ_DBL -D_GNU_SOURCE -D_POSIX_TIMERS -DEFIAPI='__attribute__((ms_abi))'
https://scrapbox.io/files/635b383d757dc1001dfa0fe9.png
day4
code: zsh
vscode ➜ ~/edk2 (tags/edk2-stable202105~127 ✗) $ build
Build environment: Linux-5.10.124-linuxkit-aarch64-with-glibc2.29
Build start time: 02:04:14, Oct.29 2022
WORKSPACE = /home/vscode/edk2
EDK_TOOLS_PATH = /home/vscode/edk2/BaseTools
CONF_PATH = /home/vscode/edk2/Conf
PYTHON_COMMAND = /usr/bin/python3.8
Processing meta-data .
Architecture(s) = X64
Build target = DEBUG
Toolchain = CLANG38
Active Platform = /home/vscode/edk2/MikanLoaderPkg/MikanLoaderPkg.dsc
done!
Building ... /home/vscode/edk2/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiLib/UefiLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BasePrintLib/BasePrintLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BaseLib/BaseLib.inf X64 Building ... /home/vscode/edk2/MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf X64 make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf X64 make: Nothing to be done for 'tbuild'.
make: Nothing to be done for 'tbuild'.
Building ... /home/vscode/edk2/MikanLoaderPkg/Loader.inf X64 "clang" -MMD -MF /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/Main.obj.deps -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=LoaderStrings -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -Oz -flto -target x86_64-pc-linux-gnu -g -c -o /home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/OUTPUT/./Main.obj -I/home/vscode/edk2/MikanLoaderPkg -I/home/vscode/edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/MikanLoaderPkg/Loader/DEBUG -I/home/vscode/edk2/MdePkg -I/home/vscode/edk2/MdePkg/Include -I/home/vscode/edk2/MdePkg/Test/UnitTest/Include -I/home/vscode/edk2/MdePkg/Include/X64 /home/vscode/edk2/MikanLoaderPkg/Main.c
In file included from /home/vscode/edk2/MikanLoaderPkg/Main.c:11:
In file included from /home/vscode/edk2/MikanLoaderPkg/frame_buffer_config.hpp:3:
In file included from /usr/lib/llvm-7/lib/clang/7.0.1/include/stdint.h:61:
/usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
build.py...
: error 7000: Failed to execute command
build.py...
: error F002: Failed to build module
- Failed -
Build end time: 02:04:15, Oct.29 2022
Build total time: 00:00:01
code: frame_buffer_config.hpp
enum PixelFormat {
kPixelRGBResv8BitPerColor,
kPixelBGRResv8BitPerColor,
};
struct FrameBufferConfig {
int* frame_buffer;
int pixels_per_scan_line;
int horizontal_resolution;
int vertical_resolution;
enum PixelFormat pixel_format;
};
code: main.cpp
int* PixelAt(int x, int y) {
code: main.c
(int *)gop->Mode->FrameBufferBase,
https://scrapbox.io/files/635c8fab54a3f80021ef289d.png
code: zsh
vscode ➜ ~/edk2 (tags/edk2-stable202105~127 ✗) $ find /usr -name libc-header-start.h
/usr/include/aarch64-linux-gnu/bits/libc-header-start.h
/usr/x86_64-linux-gnu/include/bits/libc-header-start.h
code: frame_buffer_config.cpp
enum PixelFormat {
kPixelRGBResv8BitPerColor,
kPixelBGRResv8BitPerColor,
};
struct FrameBufferConfig {
unsigned char* frame_buffer;
unsigned int pixels_per_scan_line;
unsigned int horizontal_resolution;
unsigned int vertical_resolution;
enum PixelFormat pixel_format;
};
code: Main.c
(unsigned char*)gop->Mode->FrameBufferBase,
https://scrapbox.io/files/635ca6455d35240022fff61e.png
https://scrapbox.io/files/635dd43cfc4fe00023b8a539.png
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer/mikanos/kernel (tags/osbook_day04d ✗) $ readelf -l kernel.elf
Elf file type is EXEC (Executable file)
Entry point 0x101020
There are 5 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000100040 0x0000000000100040
0x0000000000000118 0x0000000000000118 R 0x8
LOAD 0x0000000000000000 0x0000000000100000 0x0000000000100000
0x00000000000001a8 0x00000000000001a8 R 0x1000
LOAD 0x0000000000001000 0x0000000000101000 0x0000000000101000
0x00000000000001b9 0x00000000000001b9 R E 0x1000
LOAD 0x0000000000002000 0x0000000000102000 0x0000000000102000
0x0000000000000000 0x0000000000000018 RW 0x1000
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x0
Section to Segment mapping:
Segment Sections...
00
01 .rodata
02 .text
03 .bss
04
code: elf.hpp
typedef unsigned long Elf64_Addr;
typedef unsigned int Elf64_Off;
typedef unsigned char Elf64_Half;
typedef unsigned int Elf64_Word;
typedef int Elf64_Sword;
typedef unsigned long Elf64_Xword;
typedef long Elf64_Sxword;
https://scrapbox.io/files/635ddc5592198d001d41dfec.png
code: elf.hpp
typedef unsigned long Elf64_Addr;
typedef unsigned long Elf64_Off;
typedef unsigned char Elf64_Half;
typedef unsigned int Elf64_Word;
typedef int Elf64_Sword;
typedef unsigned long Elf64_Xword;
typedef long Elf64_Sxword;
https://scrapbox.io/files/635ddcaf24867e0023992b2f.png
day5
https://scrapbox.io/files/635de0c3705ba9001f3c8bc2.png
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer/mikanos/kernel (tags/osbook_day05c ✗) $ ../tools/makefont.py -o hankaku.bin hankaku.txt
vscode ➜ /workspaces/mikanos-devcontainer/mikanos/kernel (t
ags/osbook_day05c ✗) $ objcopy -I binary -O elf64-x86-64 -B i386:x86-64 hankaku.bin hankaku.o
https://scrapbox.io/files/635dec36551f73001d5750e6.png
code: main.cpp
int i = 0;
for (char c = '!'; c <= '~'; ++c, ++i) {
WriteAscii(*pixel_writer, 8 * i, 50, c, {0, 0, 0});
}
WriteString(*pixel_writer, 0, 66, "Hello, world!", {0, 0, 255});
// sprintf(buf, "1 + 2 = %d", 1 + 2);
// WriteString(*pixel_writer, 0, 82, buf, {0, 0, 0});
https://scrapbox.io/files/635df304fa0c1100202710bb.png
https://scrapbox.io/files/635df369d972c2002358ef77.png
code: main.cpp
Console console{*pixel_writer, {0, 0, 0}, {255, 255, 255}};
console.PutString("line 1\n");
console.PutString("line 2\n");
console.PutString("line 3\n");
console.PutString("line 4\n");
console.PutString("line 5\n");
// for (int i = 0; i < 27; ++i) {
// sprintf(buf, "line %d\n", i);
// console.PutString(buf);
// }
https://scrapbox.io/files/635df5ec113adc001ff27a85.png
https://scrapbox.io/files/635df64d628ffb001d1e686b.png
day6
https://scrapbox.io/files/6365babbb6e7c60023e1addb.png
https://scrapbox.io/files/6365c03b6cfe92001d96adc9.png
https://scrapbox.io/files/6365c5d803ccbd0022873a3b.png
day7
https://scrapbox.io/files/63670f8383847a002356134f.png
day8
https://scrapbox.io/files/6369b02f6da6dd0023504938.png
day9
https://scrapbox.io/files/636dacd8dd0890001d3b0225.png
https://scrapbox.io/files/636daf68640f52001d59bd53.png
https://scrapbox.io/files/636dbd522888db001f389adb.png
https://scrapbox.io/files/636dbeabf45b06001d0f22de.png
https://scrapbox.io/files/636dc1bd9d85f6001dfda026.png
day10
https://scrapbox.io/files/6370457024cecd00221d6fbe.png
https://scrapbox.io/files/63704778a7980900235c9d44.png
https://scrapbox.io/files/637048f25a156500212ff8a5.png
https://scrapbox.io/files/63704be1672a08001dac2941.png
https://scrapbox.io/files/63704dd65a1565002130198c.png
https://scrapbox.io/files/637051d010f4b6001d767b11.png
https://scrapbox.io/files/6370540c24cecd00221dd9be.png
day11
https://scrapbox.io/files/6372e72a7851a9001ddf73f1.png
https://scrapbox.io/files/6372e8d83cbbf7001d6d5d33.png
https://scrapbox.io/files/6372ead13cbbf7001d6d7af9.png
https://scrapbox.io/files/6372ecec0d3ec0001d7183fc.png
https://scrapbox.io/files/6372ef883afcef001da943ec.png
day12
https://scrapbox.io/files/637835b86d3bd7001d943f93.png
https://scrapbox.io/files/63783a0530c149001d82f3e6.png
https://scrapbox.io/files/63783bc4f171b300237c0a28.png
https://scrapbox.io/files/63783d8b96508a001fbbeb12.png
https://scrapbox.io/files/63783fe6c1649d001fd8d77c.png
day13
https://scrapbox.io/files/6379836fa174e500236e4baa.png
https://scrapbox.io/files/6379857331d59d002024537e.png
https://scrapbox.io/files/63798a381e8fa4001f6ddcdf.png
day14
https://scrapbox.io/files/637c241c7f95a6001d5a5709.png
https://scrapbox.io/files/637c2a684e14e1001e5c3d04.png
https://scrapbox.io/files/637c2cf5b357c400231567b5.png
day15
https://scrapbox.io/files/637d74c86eeb42001dbc3aeb.png
https://scrapbox.io/files/637d78e7ee89fc0020fc9689.png
https://scrapbox.io/files/637d7c2a795dfc002193ef64.png
https://scrapbox.io/files/63801fbddadc95002202b891.png
$ git diff --diff-filter=AMCRD osbook_day15c osbook_day15d
https://scrapbox.io/files/6380269a72da47002324d0be.png
code: layer.cpp
void LayerManager::Draw(unsigned int id) const {
bool draw = false;
Rectangle<int> window_area;
for (auto layer : layer_stack_) {
if (layer->ID() == id) {
window_area.size = layer->GetWindow()->Size();
window_area.pos = layer->GetPosition();
draw = true;
}
if (draw) {
layer->DrawTo(back_buffer_, window_area);
}
}
screen_->Copy(window_area.pos, back_buffer_, window_area);
}
// void LayerManager::Draw(unsigned int id, Rectangle<int> area) const {
// bool draw = false;
// Rectangle<int> window_area;
// for (auto layer : layer_stack_) {
// if (layer->ID() == id) {
// window_area.size = layer->GetWindow()->Size();
// window_area.pos = layer->GetPosition();
// if (area.size.x >= 0 || area.size.y >= 0) {
// area.pos = area.pos + window_area.pos;
// window_area = window_area & area;
// }
// draw = true;
// }
// if (draw) {
// layer->DrawTo(back_buffer_, window_area);
// }
// }
// screen_->Copy(window_area.pos, back_buffer_, window_area);
// }
code: layer.cpp
// case LayerOperation::DrawArea:
// layer_manager->Draw(arg.layer_id, {{arg.x, arg.y}, {arg.w, arg.h}});
// break;
code: layer.hpp
// /** @brief 指定したレイヤーに設定されているウィンドウ内の指定された範囲を再描画する。 */
// void Draw(unsigned int id, Rectangle<int> area) const;
// constexpr Message MakeLayerMessage(
// unsigned long task_id, unsigned int layer_id,
// LayerOperation op, const Rectangle<int>& area) {
// Message msg{Message::kLayer, task_id};
// msg.arg.layer.layer_id = layer_id;
// msg.arg.layer.op = op;
// msg.arg.layer.x = area.pos.x;
// msg.arg.layer.y = area.pos.y;
// msg.arg.layer.w = area.size.x;
// msg.arg.layer.h = area.size.y;
// return msg;
// }
code: message.hpp
enum class LayerOperation {
Move, MoveRelative, Draw //, DrawArea
};
struct {
LayerOperation op;
unsigned int layer_id;
int x, y;
// int w, h;
} layer;
code: terminal.cpp
case Message::kTimerTimeout:
terminal->BlinkCursor();
{
Message msg{Message::kLayer, task_id};
msg.arg.layer.layer_id = terminal->LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// const auto area = terminal->BlinkCursor();
// Message msg = MakeLayerMessage(
// task_id, terminal->LayerID(), LayerOperation::DrawArea, area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
break;
code: terminal.hpp
void BlinkCursor();
https://scrapbox.io/files/63803527964c68002256a9c9.png
day16
code: terminal.cpp
case Message::kKeyPush:
terminal->InputKey(msg->arg.keyboard.modifier,
msg->arg.keyboard.keycode,
msg->arg.keyboard.ascii);
{
Message msg{Message::kLayer, task_id};
msg.arg.layer.layer_id = terminal->LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// const auto area = terminal->InputKey(msg->arg.keyboard.modifier,
// msg->arg.keyboard.keycode,
// msg->arg.keyboard.ascii);
// Message msg = MakeLayerMessage(
// task_id, terminal->LayerID(), LayerOperation::DrawArea, area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
break;
https://scrapbox.io/files/638037a5b0d861001d673652.png
https://scrapbox.io/files/63803a3c72da470023267c94.png
https://scrapbox.io/files/63803bcadadc950022046dfd.png
https://scrapbox.io/files/63803c5303aab6001df47cba.png
https://scrapbox.io/files/63803e02b33c38001ddc474b.png
https://scrapbox.io/files/63803e918ddb42001dcec5ea.png
day17
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ ls
mikanos mnt README.md target.txt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ dd if=/dev/zero of=fat_disk bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB, 128 MiB) copied, 1.89435 s, 70.9 MB/s
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ ls
fat_disk mikanos mnt README.md target.txt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ mkfs.fat -n 'MIKAN OS' -s 2 -f 2 -R 32 -F 32 fat_disk
mkfs.fat 4.1 (2017-01-24)
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ ls
fat_disk mikanos mnt README.md target.txt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ hexdump -C -s 16k fat_disk
00004000 f8 ff ff 0f ff ff ff 0f f8 ff ff 0f 00 00 00 00 |................|
00004010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00083000 f8 ff ff 0f ff ff ff 0f f8 ff ff 0f 00 00 00 00 |................|
00083010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00102000 4d 49 4b 41 4e 20 4f 53 20 20 20 08 00 00 2a 09 |MIKAN OS ...*.|
00102010 7a 55 7a 55 00 00 2a 09 7a 55 00 00 00 00 00 00 |zUzU..*.zU......|
00102020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
08000000
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ mkdir mnt
mkdir: cannot create directory ‘mnt’: File exists
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ rm -r -f mnt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ mkdir mnt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo mount -o loop fat_disk mnt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ ls -a mnt
. ..
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ echo deadbeef > cafe.txt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo cp cafe.txt mnt/cafe.txt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ ls -a mnt
. .. cafe.txt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo unmount mnt
sudo: unmount: command not found
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo umount mnt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ hexdump -C -s 16k fat_disk
00004000 f8 ff ff 0f ff ff ff 0f f8 ff ff 0f ff ff ff 0f |................|
00004010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00083000 f8 ff ff 0f ff ff ff 0f f8 ff ff 0f ff ff ff 0f |................|
00083010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00102000 4d 49 4b 41 4e 20 4f 53 20 20 20 08 00 00 2a 09 |MIKAN OS ...*.|
00102010 7a 55 7a 55 00 00 2a 09 7a 55 00 00 00 00 00 00 |zUzU..*.zU......|
00102020 41 63 00 61 00 66 00 65 00 2e 00 0f 00 dc 74 00 |Ac.a.f.e......t.|
00102030 78 00 74 00 00 00 ff ff ff ff 00 00 ff ff ff ff |x.t.............|
00102040 43 41 46 45 20 20 20 20 54 58 54 20 00 70 4b 0a |CAFE TXT .pK.|
00102050 7a 55 7a 55 00 00 4b 0a 7a 55 03 00 09 00 00 00 |zUzU..K.zU......|
00102060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00102400 64 65 61 64 62 65 65 66 0a 00 00 00 00 00 00 00 |deadbeef........|
00102410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
08000000
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo mount -o loop fat_disk mnt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ echo CafeBabe > HelloWorld.data
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo cp HelloWorld.data mnt/HelloWorld.data
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ sudo umount mnt
vscode ➜ /workspaces/mikanos-devcontainer (master ✗) $ hexdump -C -s 16k fat_disk
00004000 f8 ff ff 0f ff ff ff 0f f8 ff ff 0f ff ff ff 0f |................|
00004010 ff ff ff 0f 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00004020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00083000 f8 ff ff 0f ff ff ff 0f f8 ff ff 0f ff ff ff 0f |................|
00083010 ff ff ff 0f 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00083020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00102000 4d 49 4b 41 4e 20 4f 53 20 20 20 08 00 00 2a 09 |MIKAN OS ...*.|
00102010 7a 55 7a 55 00 00 2a 09 7a 55 00 00 00 00 00 00 |zUzU..*.zU......|
00102020 41 63 00 61 00 66 00 65 00 2e 00 0f 00 dc 74 00 |Ac.a.f.e......t.|
00102030 78 00 74 00 00 00 ff ff ff ff 00 00 ff ff ff ff |x.t.............|
00102040 43 41 46 45 20 20 20 20 54 58 54 20 00 70 4b 0a |CAFE TXT .pK.|
00102050 7a 55 7a 55 00 00 4b 0a 7a 55 03 00 09 00 00 00 |zUzU..K.zU......|
00102060 42 74 00 61 00 00 00 ff ff ff ff 0f 00 8c ff ff |Bt.a............|
00102070 ff ff ff ff ff ff ff ff ff ff 00 00 ff ff ff ff |................|
00102080 01 48 00 65 00 6c 00 6c 00 6f 00 0f 00 8c 57 00 |.H.e.l.l.o....W.|
00102090 6f 00 72 00 6c 00 64 00 2e 00 00 00 64 00 61 00 |o.r.l.d.....d.a.|
001020a0 48 45 4c 4c 4f 57 7e 31 44 41 54 20 00 77 94 0a |HELLOW~1DAT .w..|
001020b0 7a 55 7a 55 00 00 94 0a 7a 55 04 00 09 00 00 00 |zUzU....zU......|
001020c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00102400 64 65 61 64 62 65 65 66 0a 00 00 00 00 00 00 00 |deadbeef........|
00102410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00102800 43 61 66 65 42 61 62 65 0a 00 00 00 00 00 00 00 |CafeBabe........|
00102810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
08000000
https://scrapbox.io/files/63816fc5ba1516001def3055.png
code: zsh
vscode ➜ ~/edk2 (tags/edk2-stable202105~127 ✗) $ hexdump -n 256 -C disk.img
00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 02 20 00 |.X.mkfs.fat... .|
00000010 02 00 00 00 00 f8 00 00 20 00 40 00 00 00 00 00 |........ .@.....|
00000020 00 40 06 00 34 06 00 00 00 00 00 00 02 00 00 00 |.@..4...........|
00000030 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000040 80 00 29 7c 5a 4c f7 4d 49 4b 41 4e 20 4f 53 20 |..)|ZL.MIKAN OS |
00000050 20 20 46 41 54 33 32 20 20 20 0e 1f be 77 7c ac | FAT32 ...w|.|
00000060 22 c0 74 0b 56 b4 0e bb 07 00 cd 10 5e eb f0 32 |".t.V.......^..2|
00000070 e4 cd 16 cd 19 eb fe 54 68 69 73 20 69 73 20 6e |.......This is n|
00000080 6f 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 64 69 |ot a bootable di|
00000090 73 6b 2e 20 20 50 6c 65 61 73 65 20 69 6e 73 65 |sk. Please inse|
000000a0 72 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 66 6c |rt a bootable fl|
000000b0 6f 70 70 79 20 61 6e 64 0d 0a 70 72 65 73 73 20 |oppy and..press |
000000c0 61 6e 79 20 6b 65 79 20 74 6f 20 74 72 79 20 61 |any key to try a|
000000d0 67 61 69 6e 20 2e 2e 2e 20 0d 0a 00 00 00 00 00 |gain ... .......|
000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000100
https://scrapbox.io/files/638173527e418800230b6a98.png
day18
https://scrapbox.io/files/6382ba4426e11e001dc901db.png
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer/mikanos/apps/onlyhlt (tags/osbook_day18b ✗) $ hexdump -C onlyhlt
00000000 f4 eb fd |...|
00000003
vscode ➜ /workspaces/mikanos-devcontainer/mikanos/apps/onlyhlt (tags/osbook_day18b ✗) $ objdump -D -m i386:x86-64 -b binary onlyhlt
onlyhlt: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: f4 hlt
1: eb fd jmp 0x0
https://scrapbox.io/files/6382be9edff4b4001f1a3272.png
https://scrapbox.io/files/6382c18d967bb30022955e5a.png
https://scrapbox.io/files/6382c346ac27a8001d030d19.png
day19
https://scrapbox.io/files/638562dfc6b5de00220ac899.png
day20
code: zsh
vscode ➜ /workspaces/mikanos-devcontainer/mikanos (tags/osbook_day20a ✗) $ nm -C kernel/kernel.elf | grep printk
000000000010b000 T printk(char const*, ...)
https://scrapbox.io/files/63895a466567b3001d23ecf1.png
https://scrapbox.io/files/63895e8456b905001ee0f10a.png
https://scrapbox.io/files/6389653ae6d3ff001e781b6e.png
https://scrapbox.io/files/63896929d9f53b001df04414.png
day21
code: terminal.cpp
Message msg{Message::kLayer, task_id_};
msg.arg.layer.layer_id = LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// const auto cursor_after = CalcCursorPos();
// Vector2D<int> draw_pos{ToplevelWindow::kTopLeftMargin.x, cursor_before.y};
// Vector2D<int> draw_size{window_->InnerSize().x,
// cursor_after.y - cursor_before.y + 16};
// Rectangle<int> draw_area{draw_pos, draw_size};
// Message msg = MakeLayerMessage(
// task_id_, LayerID(), LayerOperation::DrawArea, draw_area);
https://scrapbox.io/files/6397d9c76a1ce0001e19bc12.png
https://scrapbox.io/files/6397dd74a26ecd001de0dbc2.png
https://scrapbox.io/files/6397e081510b5d001e0c41b1.png
https://scrapbox.io/files/6397e126832a4a001e210d26.png
day22
https://scrapbox.io/files/639a772ac4ec06001ebbf9dc.png
https://scrapbox.io/files/639a77cb1df96b001ec47eb1.png
https://scrapbox.io/files/639a79a9159723001e25c25e.png
https://scrapbox.io/files/639a7b8923d2d2001e702c12.png
https://scrapbox.io/files/639d2839cd4c4d001d3c2e2b.png
code: syscall.cpp
auto msg = task.ReceiveMessage();
if (!msg && i == 0) {
// break;
code: winhello.cpp
// printf("ReadEvent failed: %s\n", strerror(err));
// printf("unknown event: type = %d\n", events0.type); day23
https://scrapbox.io/files/639d234f8ecd0e001e613338.png
https://scrapbox.io/files/639d25c7db243f001ebe8053.png
https://scrapbox.io/files/639d27f6164cc7001d73f363.png
https://scrapbox.io/files/639d2a0a1912da001e3625c5.png
code: terminal.cpp
case Message::kKeyPush:
if (msg->arg.keyboard.press) {
terminal->InputKey(msg->arg.keyboard.modifier,
msg->arg.keyboard.keycode,
msg->arg.keyboard.ascii);
Message msg{Message::kLayer, task_id};
msg.arg.layer.layer_id = terminal->LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// const auto area = terminal->InputKey(msg->arg.keyboard.modifier,
// msg->arg.keyboard.keycode,
// msg->arg.keyboard.ascii);
// Message msg = MakeLayerMessage(
// task_id, terminal->LayerID(), LayerOperation::DrawArea, area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
break;
https://scrapbox.io/files/639d2ce62558fd001ec38c3f.png
day24
code: main.cpp
msg->arg.keyboard.keycode == 29 /* Z */
https://scrapbox.io/files/639e76ab4f10e5001db955ba.png
https://scrapbox.io/files/639e7c39596584001e1262d6.png
https://scrapbox.io/files/639e7d4224c8da001eb7b140.png
code: terminal.cpp
case Message::kTimerTimeout:
add_blink_timer(msg->arg.timer.timeout);
if (show_window && window_isactive) {
terminal->BlinkCursor();
Message msg{Message::kLayer, task_id};
msg.arg.layer.layer_id = terminal->LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// Message msg = MakeLayerMessage(
// task_id, terminal->LayerID(), LayerOperation::DrawArea, area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
break;
case Message::kKeyPush:
if (msg->arg.keyboard.press) {
const auto area = terminal->InputKey(msg->arg.keyboard.modifier,
msg->arg.keyboard.keycode,
msg->arg.keyboard.ascii);
if (show_window) {
Message msg{Message::kLayer, task_id};
msg.arg.layer.layer_id = terminal->LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// Message msg = MakeLayerMessage(
// task_id, terminal->LayerID(), LayerOperation::DrawArea, area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
}
break;
https://scrapbox.io/files/639e804086947f001d298fbd.png
https://scrapbox.io/files/639e81a2240663001d203460.png
https://scrapbox.io/files/639e827b3a9f06001db4887b.png
day25
https://scrapbox.io/files/63a3b34a7feae3001e7201d0.png
https://scrapbox.io/files/63a3b6d9337cbf001db8e4ca.png
https://scrapbox.io/files/63a3b871dfcf32001e2a0e1b.png
day26
https://scrapbox.io/files/63a508d9df7ad1001edd41dd.png
https://scrapbox.io/files/63a50b04668356001d070682.png
https://scrapbox.io/files/63a50cb0ff7498001ee21edc.png
https://scrapbox.io/files/63a50fba29e45f001d216b7d.png
day27
https://scrapbox.io/files/63a6546ae25465001e0fe2e3.png
https://scrapbox.io/files/63a657a940f39f001ee9218f.png
https://scrapbox.io/files/63a659f0c2689b001d60b7b1.png
https://scrapbox.io/files/63a65d3f00d736001d6b815b.png
day28
https://scrapbox.io/files/63a7a6cd73ee3b001d0203d2.png
https://scrapbox.io/files/63a7a92c05073e001e7a817f.png
https://scrapbox.io/files/63a7ac8980a257001ee17cce.png
day29
https://scrapbox.io/files/63aa487179a4ea001d8d935d.png
https://scrapbox.io/files/63aa4cc53ac5eb001e8d8685.png
https://scrapbox.io/files/63aa4f082806a6001d847272.png
code: terminal.cpp
DrawCursor(true);
Message msg{Message::kLayer, task_.ID()};
msg.arg.layer.layer_id = LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// const auto cursor_after = CalcCursorPos();
// Vector2D<int> draw_pos{ToplevelWindow::kTopLeftMargin.x, cursor_before.y};
// Vector2D<int> draw_size{window_->InnerSize().x,
// cursor_after.y - cursor_before.y + 16};
// Rectangle<int> draw_area{draw_pos, draw_size};
// Message msg = MakeLayerMessage(
// task_.ID(), LayerID(), LayerOperation::DrawArea, draw_area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
void Terminal::Redraw() {
Message msg{Message::kLayer, task_.ID()};
msg.arg.layer.layer_id = LayerID();
msg.arg.layer.op = LayerOperation::Draw;
// Rectangle<int> draw_area{ToplevelWindow::kTopLeftMargin,
// window_->InnerSize()};
// Message msg = MakeLayerMessage(
// task_.ID(), LayerID(), LayerOperation::DrawArea, draw_area);
__asm__("cli");
task_manager->SendMessage(1, msg);
__asm__("sti");
}
https://scrapbox.io/files/63aa5059e2f586001e0c6181.png
day30
https://scrapbox.io/files/63ace8a359275e001d4eeecd.png
https://scrapbox.io/files/63acea4f59275e001d4ef67c.png
https://scrapbox.io/files/63aceb9da22955001e026409.png
https://scrapbox.io/files/63acee9842afc9001d8d010e.png
https://scrapbox.io/files/63acf144706915001d5ecd78.png
https://scrapbox.io/files/63acf281dcf509001ed149ce.png
https://scrapbox.io/files/63acfca5462cd2001e2f631e.png