From 3ee8369ec6c94dc374843f52d21d2a1f2b881fe8 Mon Sep 17 00:00:00 2001 From: turbocat Date: Sun, 11 Jul 2021 11:17:39 +0000 Subject: [PATCH] Kolibri-F: - Added sprintf to the kernel. - Added a notification from @notify when there are exceptions in the application. - Added debug files to bochs git-svn-id: svn://kolibrios.org@9051 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/Kolibri-F/Makefile | 47 --------------- kernel/branches/Kolibri-F/Tupfile.lua | 7 --- kernel/branches/Kolibri-F/build.bat | 39 ------------- kernel/branches/Kolibri-F/build.sh | 22 ------- kernel/branches/Kolibri-F/build_test.sh | 21 +++++++ kernel/branches/Kolibri-F/core/sys32.inc | 11 +++- kernel/branches/Kolibri-F/data32.inc | 5 +- .../branches/Kolibri-F/debug_bochs/bochs.bxrc | 54 ++++++++++++++++++ .../Kolibri-F/debug_bochs/fastxt2bochs_map.py | 20 +++++++ .../Kolibri-F/debug_bochs/symbols.exe | Bin 0 -> 4096 bytes kernel/branches/Kolibri-F/kernel32.inc | 2 + kernel/branches/Kolibri-F/libc/bin.x | 19 ++++++ kernel/branches/Kolibri-F/libc/libc.c | 8 +++ kernel/branches/Kolibri-F/libc/libc.inc | 6 ++ 14 files changed, 143 insertions(+), 118 deletions(-) delete mode 100644 kernel/branches/Kolibri-F/Makefile delete mode 100644 kernel/branches/Kolibri-F/Tupfile.lua delete mode 100644 kernel/branches/Kolibri-F/build.bat delete mode 100755 kernel/branches/Kolibri-F/build.sh create mode 100755 kernel/branches/Kolibri-F/build_test.sh create mode 100644 kernel/branches/Kolibri-F/debug_bochs/bochs.bxrc create mode 100644 kernel/branches/Kolibri-F/debug_bochs/fastxt2bochs_map.py create mode 100755 kernel/branches/Kolibri-F/debug_bochs/symbols.exe create mode 100644 kernel/branches/Kolibri-F/libc/bin.x create mode 100644 kernel/branches/Kolibri-F/libc/libc.c create mode 100644 kernel/branches/Kolibri-F/libc/libc.inc diff --git a/kernel/branches/Kolibri-F/Makefile b/kernel/branches/Kolibri-F/Makefile deleted file mode 100644 index 8f924bca16..0000000000 --- a/kernel/branches/Kolibri-F/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -FASM=fasm -FLAGS=-m 65536 -languages=en|ru|ge|et|sp - -.PHONY: all kernel bootloader clean - -all: kernel bootloader bootbios - -kernel: check_lang bootbios - @echo "*** building kernel with language '$(lang)' ..." - @mkdir -p bin - @echo "lang fix $(lang)" > lang.inc - @echo "--- building 'bin/kernel.mnt' ..." - @$(FASM) $(FLAGS) kernel.asm bin/kernel.mnt - @$(FASM) $(FLAGS) -dUEFI=1 kernel.asm bin/kernel.bin - @rm -f lang.inc - -bootbios: check_lang - @echo "*** building bootbios.bin with language '$(lang)' ..." - @mkdir -p bin - @echo "lang fix $(lang)" > lang.inc - @echo "--- building 'bootbios.bin' ..." - @$(FASM) $(FLAGS) bootbios.asm bootbios.bin - @rm -f lang.inc - -bootloader: check_lang - @echo "*** building bootloader with language '$(lang)' ..." - @mkdir -p bin - @echo "lang fix $(lang)" > lang.inc - @echo "--- building 'bin/boot_fat12.bin' ..." - @$(FASM) $(FLAGS) bootloader/boot_fat12.asm bin/boot_fat12.bin - @rm -f lang.inc - - -check_lang: - @case "$(lang)" in \ - $(languages)) \ - ;; \ - *) \ - echo "*** error: language is incorrect or not specified"; \ - exit 1; \ - ;; \ - esac - -clean: - rm -rf bin - rm -f lang.inc diff --git a/kernel/branches/Kolibri-F/Tupfile.lua b/kernel/branches/Kolibri-F/Tupfile.lua deleted file mode 100644 index cbed9e8c80..0000000000 --- a/kernel/branches/Kolibri-F/Tupfile.lua +++ /dev/null @@ -1,7 +0,0 @@ -if tup.getconfig("NO_FASM") ~= "" then return end -tup.rule("echo lang fix " .. ((tup.getconfig("LANG") == "") and "en" or tup.getconfig("LANG")) .. " > %o", {"lang.inc"}) -tup.rule({"bootbios.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o ", "bootbios.bin") -tup.rule({"bootbios.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o -dextended_primary_loader=1", "bootbios.bin.ext_loader") -tup.rule({"kernel.asm", extra_inputs = {"bootbios.bin", "lang.inc"}}, "fasm -m 65536 %f %o " .. tup.getconfig("KERPACK_CMD"), "kernel.mnt") -tup.rule({"kernel.asm", extra_inputs = {"bootbios.bin.ext_loader", "lang.inc"}}, "fasm -m 65536 %f %o -dextended_primary_loader=1" .. tup.getconfig("KERPACK_CMD"), "kernel.mnt.ext_loader") -tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 65536 %f %o -dUEFI=1 -dextended_primary_loader=1", "kolibri.krn") diff --git a/kernel/branches/Kolibri-F/build.bat b/kernel/branches/Kolibri-F/build.bat deleted file mode 100644 index 1e8981838e..0000000000 --- a/kernel/branches/Kolibri-F/build.bat +++ /dev/null @@ -1,39 +0,0 @@ -@echo off -cls - -call :Target_kernel - -if ERRORLEVEL 0 goto Exit_OK - -echo There was an error executing script. -echo For any help, please send a report. -pause -goto :eof - -:Target_kernel - rem valid languages: en ru ge et sp - set lang=en - - echo *** building kernel with language '%lang%' ... - - echo lang fix %lang% > lang.inc - fasm -m 65536 bootbios.asm bootbios.bin - fasm -m 65536 kernel.asm kernel.mnt - fasm -m 65536 kernel.asm kernel.bin -dUEFI=1 - if not %errorlevel%==0 goto :Error_FasmFailed - erase lang.inc -goto :eof - - -:Error_FasmFailed -echo error: fasm execution failed -erase lang.inc >nul 2>&1 -echo. -pause -exit 1 - -:Exit_OK -echo. -echo all operations have been done -pause -exit 0 diff --git a/kernel/branches/Kolibri-F/build.sh b/kernel/branches/Kolibri-F/build.sh deleted file mode 100755 index bdd23245b1..0000000000 --- a/kernel/branches/Kolibri-F/build.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# Compile the KolibriOS kernel on Linux -# 2017, The KolibriOS team - -KERPACK=$HOME/kolibrios/programs/other/kpack/kerpack_linux/kerpack -KOLIBRI_IMG=$HOME/nightly/kolibri.img - -replace=0; # Replace kernel in the image file? -echo 'lang fix en' > lang.inc -fasm -m 65536 bootbios.asm bootbios.bin -fasm -m 65536 kernel.asm kernel.mnt -$KERPACK kernel.mnt kernel.mnt - -[[ $replace -eq 1 ]] && { - mntpt=$(mktemp -d) - - sudo mount -o loop $KOLIBRI_IMG $mntpt - sudo mount -o remount,rw $mntpt - sudo cp kernel.mnt ${mntpt}/KERNEL.MNT - sudo umount $mntpt - rmdir $mntpt -} diff --git a/kernel/branches/Kolibri-F/build_test.sh b/kernel/branches/Kolibri-F/build_test.sh new file mode 100755 index 0000000000..3b7aae431e --- /dev/null +++ b/kernel/branches/Kolibri-F/build_test.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -e +KERPACK=kerpack +KOLIBRI_IMG=kolibri.img + +gcc -m32 -c -nostdinc -I../../../programs/develop/ktcc/trunk/libc.obj/source/ -I../../../programs/develop/ktcc/trunk/libc.obj/include -DGNUC -D_BUILD_LIBC -fno-common -Os -fno-builtin -fno-leading-underscore -fno-stack-protector -fno-pie libc/libc.c -o libc/libc.o +ld -m elf_i386 -nostdlib -s -Map libc/libc.map -T libc/bin.x libc/libc.o -o libc/libc.bin + +echo 'lang fix en' > lang.inc +fasm -m 65536 bootbios.asm bootbios.bin +fasm -m 65536 -s debug_bochs/kernel.fas kernel.asm kernel.mnt +wine debug_bochs/symbols.exe debug_bochs/kernel.fas debug_bochs/kernel.txt +python3 debug_bochs/fastxt2bochs_map.py debug_bochs/kernel.txt + +$KERPACK kernel.mnt kernel.mnt +wget http://builds.kolibrios.org/eng/latest-img.7z +7z x -y latest-img.7z +rm -f latest-img.7z +mcopy -D o -i $KOLIBRI_IMG kernel.mnt ::kernel.mnt +qemu-system-i386 -m 256 -fda kolibri.img -boot a -enable-kvm + diff --git a/kernel/branches/Kolibri-F/core/sys32.inc b/kernel/branches/Kolibri-F/core/sys32.inc index 1309e9eca8..3f565820d6 100644 --- a/kernel/branches/Kolibri-F/core/sys32.inc +++ b/kernel/branches/Kolibri-F/core/sys32.inc @@ -75,7 +75,6 @@ iglobal msg_sel_ker db "kernel", 0 msg_sel_app db "application", 0 end if - endg macro save_ring3_context { @@ -228,6 +227,15 @@ show_error_parameters: mov bl, 0x09 .l1: mov eax, [msg_fault_sel+ebx*4 - 0x08*4] + + ; Notify show exeption message + pushad + ccall LIBC_SPRINTF, except_notify_msg, except_notify_fstr, [current_slot], [edx+TASKDATA.pid], eax + mov ebx, except_notify_msg ; exception message for @notify + mov ebp, notifyapp ; @notify bin file path + call fs_execute_from_sysdir_param ; Execute a @notify to display an exception + popad + DEBUGF 1, "K : %s\n", eax mov eax, [reg_cs3+4] mov edi, msg_sel_app @@ -335,7 +343,6 @@ show_error_parameters: restore reg_esi restore reg_edi - align 4 lock_application_table: push eax ecx edx diff --git a/kernel/branches/Kolibri-F/data32.inc b/kernel/branches/Kolibri-F/data32.inc index fa3c514e1e..cc1f3ed11a 100644 --- a/kernel/branches/Kolibri-F/data32.inc +++ b/kernel/branches/Kolibri-F/data32.inc @@ -168,6 +168,9 @@ ud_user_message db 'Error: unsupported processor instruction',0 mtrr_user_message db '"There is a problem with MTRR configuration.\nPerformance can be low" -dW',0 end if +except_notify_fstr db "'%s (pid %d): %s!' -E", 0 ; String format to write to notify exception message +except_notify_msg rb 64 ; The message displayed by notify when an application exception occurs + kernel_file_load: ; load kernel.mnt to _CLEAN_ZONE dd 0 ; subfunction @@ -556,4 +559,4 @@ BUTTON_INFO rb 64*1024 RESERVED_PORTS: rb 64*1024 sys_pgmap: - rb 1024*1024/8 + rb 1024*1024/8 \ No newline at end of file diff --git a/kernel/branches/Kolibri-F/debug_bochs/bochs.bxrc b/kernel/branches/Kolibri-F/debug_bochs/bochs.bxrc new file mode 100644 index 0000000000..cdd2d2a144 --- /dev/null +++ b/kernel/branches/Kolibri-F/debug_bochs/bochs.bxrc @@ -0,0 +1,54 @@ +plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true +config_interface: textconfig +display_library: x, options = "gui_debug" +memory: host=128, guest=128 +romimage: file="/usr/share/bochs/BIOS-bochs-latest", address=0x00000000, options=none +vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest" +boot: floppy +floppy_bootsig_check: disabled=0 +floppya: type=1_44, 1_44="kolibri.img", status=inserted, write_protected=0 +# no floppyb +ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 +ata0-master: type=none +ata0-slave: type=none +ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15 +ata1-master: type=cdrom +ata1-slave: type=none +ata2: enabled=false +ata3: enabled=false +optromimage1: file=none +optromimage2: file=none +optromimage3: file=none +optromimage4: file=none +optramimage1: file=none +optramimage2: file=none +optramimage3: file=none +optramimage4: file=none +pci: enabled=1, chipset=i440fx +vga: extension=vbe, update_freq=60, realtime=1 +cpu: count=1:2:1, ips=4000000, quantum=16, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 +cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor" +cpuid: mmx=true, apic=xapic, simd=sse2, sse4a=false, misaligned_sse=false, sep=true +cpuid: movbe=false, adx=false, aes=false, sha=false, xsave=false, xsaveopt=false, avx_f16c=false +cpuid: avx_fma=false, bmi=0, xop=false, fma4=false, tbm=false, x86_64=true, 1g_pages=false +cpuid: pcid=false, fsgsbase=false, smep=false, smap=false, mwait=true +print_timestamps: enabled=0 +port_e9_hack: enabled=0 +private_colormap: enabled=0 +clock: sync=none, time0=local, rtc_sync=1 +# no cmosimage +log: - +logprefix: %t%e%d +debug: action=ignore +info: action=report +error: action=report +panic: action=ask +keyboard: type=mf, serial_delay=200, paste_delay=100000, user_shortcut=none +mouse: type=ps2, enabled=false, toggle=ctrl+f10 +speaker: enabled=true, mode=sound +parport1: enabled=true, file=none +parport2: enabled=false +com1: enabled=true, mode=null +com2: enabled=false +com3: enabled=false +com4: enabled=false diff --git a/kernel/branches/Kolibri-F/debug_bochs/fastxt2bochs_map.py b/kernel/branches/Kolibri-F/debug_bochs/fastxt2bochs_map.py new file mode 100644 index 0000000000..3feda5cd7f --- /dev/null +++ b/kernel/branches/Kolibri-F/debug_bochs/fastxt2bochs_map.py @@ -0,0 +1,20 @@ +import re +import sys +if len(sys.argv) < 2 or sys.argv[1].strip() == '': + print('error: no input file\nusage: {:s} '.format(sys.argv[0])) + exit(-1) +inp_path = sys.argv[1].strip() +out_path = inp_path + '.map' +inp = open(inp_path,'r') +inp_text = inp.read() +inp.close() +regex1 = re.compile(r"[\S]+\:\s0x[\da-fA-F]*") +res = re.findall(regex1, inp_text) +#print(res) +out = open(out_path, 'w') +for ln in res: + splt = ln.split() + sym_addr = int(splt[1],16) + sym_name = splt[0][:-1] + out.write('{:016x} {:s}\n'.format(sym_addr, sym_name)) +out.close() diff --git a/kernel/branches/Kolibri-F/debug_bochs/symbols.exe b/kernel/branches/Kolibri-F/debug_bochs/symbols.exe new file mode 100755 index 0000000000000000000000000000000000000000..3543ada725884842b8dc61e4ef9b972c1bb05352 GIT binary patch literal 4096 zcmeHJVQgDh6~6X!x+HDlP$gQ1+Vyq>+Ko0i?OM_{1vhEhj=8Oyl+Yz=wHLqV(F%N5CrbLIddn=JdFjRzgHp|ci0 zjFhV$eNpox-y+q4=16oH98nkjk?-|DG#Yz`8=~ji^UV- zGrU7j2m*DrOf?MM*vc6;_Mh{AsDH34aJfot@UwTz<+8mOGc}jz8Fc%1z(?KXridTP zIs8A4vWimS{~7#zHxYjd;t_isGQXGfXDQHC;g*}?2+v&lWfY!?4leF?JRp`5_(*j@ zgiG&EKwknlK#<&ZA_z5*-hKcPEK!|tK*^il{&~mnP{siWYsgZ>3Pdy`qOo+Fa@9kv zfm)R<-M&-Y=PP7OKbXrU-k!@L-kdF#H_@WYO@gNPLS`m?rR*#G@y9ba(r>wsvSAI* z1ART^rc>}2k9vmb0tr$DQZUpMgnPDlr#Q?~RF+`5Y0RMkAC=Hu!ze)t(ZevOXUoEq zDH0zpl$0b9{EG;$6JdVbp5Ds180Mwf;(^8HBog++er{V6O))V(TLf95(Y@yjm>|U- zpBwc|(Q2Y9+9B+f_rx2x40Grk9xpAg{N^V2p6Q#ZyDqUO zb+=0FPu*Q2`ldVYO(oXluMpuT2xo1C_Q`{Ld4P7x-J-vAGqm zeHgal#8^Q{+0tw=Q@r4O#R}f%u6sIaS7@KgPQC8A^>(qh=K}lHcek}&^WB_zrzd^K zC2Fg0Cg^6Un*OcFm(9G`cI^UvT4vtKOdYDZlDN@7P)wDX2psq1K3Q_-)@S?jrOmix zFjPbPb+K~m{o+0xhl1-;sdVak!LI69BGz`?BY1}-nk(nzNUH1-OLGrpz2`66qd4lt z+-PY@ZUpI)+3;jE8XiA&J^k7$`v`oct213V`7D)KV{LTGf%8`-#d%4x;??$jpyUR! zR+q>25j>nN=Dw88AEX+-k8<={1Jw&f{23SnR#)}5u4Q6Heuy|XDx75toHNA9eK}jS zt@p}hdPb=+Jux)QqiR$)M!3*c1AVzgb`AmNR!!b+$onGuk#e( zdMK2j866v@;e|1x#fE6khKf1Ul<-mc&mxW)ny8Gz>=Z&4tqM;~T9k~eA$=&OjbgyL zC5>S9c*;a&q3JPt)Bv%Mxd)RUcMrxt;Wo83ZbkD;s+`;*si9=2q$6?3%o0Pv2d|oRS*p7S`2>zvh-<&NXU^L5&WAL U>AMV-0=_^u&wMbs|1aC$09)h5E&u=k literal 0 HcmV?d00001 diff --git a/kernel/branches/Kolibri-F/kernel32.inc b/kernel/branches/Kolibri-F/kernel32.inc index 5b920094c4..29799e4b4d 100644 --- a/kernel/branches/Kolibri-F/kernel32.inc +++ b/kernel/branches/Kolibri-F/kernel32.inc @@ -7,6 +7,8 @@ $Revision$ +include "libc/libc.inc" + include "core/sync.inc" ; macros for synhronization objects include "core/sys32.inc" ; process management include "core/sched.inc" ; process scheduling diff --git a/kernel/branches/Kolibri-F/libc/bin.x b/kernel/branches/Kolibri-F/libc/bin.x new file mode 100644 index 0000000000..a110a95f53 --- /dev/null +++ b/kernel/branches/Kolibri-F/libc/bin.x @@ -0,0 +1,19 @@ +OUTPUT_FORMAT(binary) + +LIBC_BASE = 0x800145ef; + +SECTIONS +{ + . = LIBC_BASE; + .text : + { + *(.text); + } + .data : + { + *(.data); + *(.bss); + *(.rodata); + } + _heap = ALIGN(4); +} diff --git a/kernel/branches/Kolibri-F/libc/libc.c b/kernel/branches/Kolibri-F/libc/libc.c new file mode 100644 index 0000000000..dc619bdda3 --- /dev/null +++ b/kernel/branches/Kolibri-F/libc/libc.c @@ -0,0 +1,8 @@ +#include "libtcc/libtcc1.c" +#include "stdio/format_print.c" +#include "stdio/sprintf.c" +#include "stdlib/___chkstk_ms.c" + +__asm__( + ".include \"math/pow10.s\"\n\t" +); diff --git a/kernel/branches/Kolibri-F/libc/libc.inc b/kernel/branches/Kolibri-F/libc/libc.inc new file mode 100644 index 0000000000..229ee8dddb --- /dev/null +++ b/kernel/branches/Kolibri-F/libc/libc.inc @@ -0,0 +1,6 @@ +LIBC_BASE = 0x800145ef +LIBC_SPRINTF = LIBC_BASE+0x1568 + +assert libc_ptr = LIBC_BASE + +libc_ptr: file 'libc.bin' \ No newline at end of file