Omit the question why it is needed. This is one of the few compact open source operating systems with support for the Russian language, which have stepped further than the conceptual version.
What you need to start developing for Hummingbird OS (CBS)?
Sources of information for you will be (start
here ):
- A forum to know which direction to go;
- Wiki, although unfortunately quite fragmented, but will give the necessary minimum of overview information;
- Sources for programs in the Subversion repository (SVN);
- Handbook of system functions in Russian and English SVN: /kernel/trunk/docs/sysfunc*.txt , or on the wiki ;
What to use for development and what is needed for this:
- Prepare a working environment or machine to run the system. You can work on a live gland (possibly with hardware support problems). Personally, I run the OS in a free for non-commercial use of VMware Player, but the Hummingbird works in QEMU and in VirtualBox, and in the Bochs emulator.
')
Install the SVN client by choice - for example, for the command line there is SlikSVN , visual RapidSVN , SubTile (you need Firefox runtime), but there is in the form of the Windows Exporer TortoiseSVN extension.
We are looking for a complete tutorial on working with SVN on the net, here are examples of typical commands for SlikSVN, being in the right directory:
> svn co svn://kolibrios.org/contrib/sdk sdk
- get yourself an up-to-date copy;
> svn status --show-updates
- show svn status --show-updates
— view files that have been changed compared to the server;
> svn up
- update your copy from the server;
> svn add *.c
- add all new c-files under control;
> svn commit --username XXXX --password YYYY -m " "
- upload your changes to the server (first, do not forget to analyze the status);
No password is required to download source files from SVN. You can use the SVN server's web capabilities to view the Hummingbird code and applications, but you cannot see the Russian-language comments in CP1251 encoding (CP866 is supported).
- The FASM assembler and Tinypad editor come with the installed system, which is natural for a system written in Assembler. Directly from the editor, you can open the system functions guide, Board debug message board, broadcast the program and run it independently or in the Mtdbg system debugger. An example of the program is also in the ISO image, you can still watch programs on SVN on the SVN path: / programs / demos.
- C--. The second native language for this system, in which many system utilities are written. It is similar to C, but instead of the standard C-library it uses direct system calls and allows you to work with processor registers directly, due to which the program is more compact. Lying here , examples of programs, very nicely written by the way - SVN: / programs / cmm. SVN Library: / programs / cmm / lib. There is a Hummingbird working and cross compiler for Windows. About him there is a more detailed article on Habré from Punk_Joker
- Cross compiler C / C ++ GCC. Host can be Linux or Windows. It lies here , you need to download msys-kos32 or linux-kos32 and SDK with ready C-libraries for CBS. Some required to run GCC dll under Windows may have to be downloaded separately from the mingw page , if you don’t have it on the machine yet. It uses the newlib library modified for CBS, which needs to be downloaded from SVN: / contrib / sdk / sources / newlib (libstdc ++ - v3 is also nearby). In the SDK there is a pre-assembled libc.dll for dynamic loading, and for a static link, the library will have to be built by yourself.
The only inconvenience of cross-compilation is that every time you need to copy the resulting program to the system. The options are either via FTP if the server works with your network card, or via a USB flash drive, or by modifying the ISO image of the system (for example, using Magic ISO Maker) and restarting it. On this compiler there is an article on Habré from pascualle , from which you can take a makefile. In the near future (already in the test) release of the gcc 5.4 port from ion2
- A simple TinyC compiler in the form of a native and cross-compiler for Windows (you can build for Linux). Take the complete set with examples here , the easiest way to copy it with the program in the Hummingbird and use it there. It supports only pure C, with the support of some language extensions from GCC, for example, attributes and assembly inserts.
What to use as an editor for cross-compilation? Your personal matter, I registered a separate toolchain in CodeBlocks.
Compile and debug
For C, there is no source code debugger, so you have to use the system Mtdbg.
For some convenience, you can compile with a .map file for gcc and a debugging file for tcc - this will give a hint in the debugger in the form of function names and partially source lines for tcc.
For GCC, static and dynamic linking is supported - because of two makefiles. Do not forget to add libc.dll and stdlibc ++. Dll into the system image in / lib (in the ISO version of the system are immediately present)
Examples of compilation lines for debugging:
- gcc (static libc) - lines are complex, therefore it is better to use ready-made makefiles
> kos32-gcc -c -g -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I $(SDK_DIR)/sources/newlib/libc/include -o hello hello.cpp
- normal compilation
> kos32-ld -static -nostdlib -T $(SDK_DIR)/sources/newlib/static.lds -Map=hello.map -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib -o hello hello.o -lstdc++ -lsupc++ -lgcc_eh -lc -lapp -lgcc -lc
- link with the proper format for the Hummingbird and the creation of a .map file for the debugger
> kos32-objdump -d -M intel -S hello.o > hello.asm
- create an assembly file with the lines of the source cpp file for convenience
> kos32-objcopy hello -O binary
- cutting off the excess and generating the Hummingbird executable file
It is a bit difficult, but as a result of the map file, we can look at the physical addresses of the data and functions and see the correspondence between the assembler and C-code.
- GCC (libc in the form of .dll) - the difference from the static assembly only in the link line:
> kos32-ld -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds --image-base 0 -Map=hello.map -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib -o hello hello.o -lstdc++ -lsupc++ -lgcc_eh -lc.dll -lapp -lgcc -lc.dll
- Tinyc
> tcc hello.c -o hello -lck -g
Everything is easier here, since the compiler is modified specifically for Hummingbirds.
More exotic options, but which may seem comfortable to you:
- Use other C compilers or languages according to this article .
When reviewing examples of C programs, please pay special attention to the fact that the system uses different libc programs in different programs, developed in different historical eras, characterized by system API calls:
- The old menuetlibc, inherited from the menuetOS ancestor, <menuet / os.h>, is prefixed with functions __menuet, is a DJGPP port. It is often used with GCC, although I would consider it obsolete and advised to use the new newlibc <kos32sys.h>.
- Tcc has its own simplified libck, but API calls <kos32sys1.h> are unified with GCC. Although there is still an old tcc version of <kolibrisys.h>, I personally did not test it.
- minimum feature set for MSVC. It is determined by the files "kosSyst.h", "KosFile.h". Outdated
- minimum set of functions for for BCC “menuet.h”
- pretty complete library for WatcomC “kolibri.h”
- Use Oberon. It's like standard Pascal, only better, and syntax simpler than Object Pascal (Delphi). Language description takes only 13 pages. The compiler and documentation here , an example of use is fbreader . By the way, while this article was being prepared, the author of the compiler has already done an article about using Oberon. Expect soon.
- There are also ports PascalPro , the ability to use FreePascal, TinyPy , Lua , Forth , Basic of varying degrees of readiness. Perhaps these topics will be disclosed in separate articles.
More on creating application programs
Development of console applications:
The system does not support console applications through the system API, it is oddly enough a system with a graphical interface, if you notice. Creating such applications is possible using the system library console.obj, with the SVN documentation: / programs / develop / libraries / console. An example of using assembly language is ibid examples.
A small digression — in Hummingbird, the .obj format is not a regular object file for a linker, but a dynamically loaded COFF format library, with an export table formed in a special way. In each program, you must load it through the system API and linking explicitly. GCC also supports loading. PE format dll.
For GCC, using the console for standard functions is built into the C libc library.
For TinyC, libck can also be used, but there are also tiny_printf functions reduced by the size of the code and a direct wrapper over console.obj in the form of conio.h
The nuance for KolibriOS is the lack of I / O streams and their redirection, because to write something like
cat a.txt > aaa.txt | more
cat a.txt > aaa.txt | more
will not work.
There are 4 ways to interact with console programs:
- use shell.c functions
- use API for IPC (interprocess communication), SysFn 60
- use API for Shared Memory, SysFn 68.22
- use Clipboard API, Clipboard, SysFn 54.1
Also, when using console.obj, your application will consist of two processes of the same name, do not be intimidated.
Graphic Application Development:
I’ll say right away that this is a very broad topic, and in this article there will be only a little more difficult review than Helloworrd and some blues, where else to look.
Currently, for the development of graphical applications, you can use the system calls, the widget library box_lib and gui.h for C--. For C, box_lib was also bundled, partly as part of GSoC 2016, GUI library expansion is scheduled for autumn 2016.
Since the window GUI is built into the kernel, the standard window window procurement is very simple.
SVN: /programs/develop/examples/example/trunk/rus/example.asm; KolibriOS
;
;
; FASM'
; example.asm FASM (
; )
; F9 Tinypad'.
; ( BOARD)
;
; :
; eax.
; "int 0x40".
; , ,
; eflags, .
;
; :
; mov eax, 1 ; 1 -
; ; . DOCPACK - sysfuncr.txt
; mov ebx, 10 ; x=10
; mov ecx, 20 ; y=10
; mov edx, 0xFFFfff ;
; int 0x40 ;
;
; :
; mcall 1, 10, 20, 0xFFFfff
;---------------------------------------------------------------------
use32 ; 32-
org 0x0 ;
db 'MENUET01' ; 8- MenuetOS
dd 0x01 ; ( 1)
dd START ;
dd I_END ;
dd 0x1000 ;
dd 0x1000 ;
dd 0x0 ;
dd 0x0 ;
include "macros.inc" ; !
;---------------------------------------------------------------------
;--- ----------------------------------------------
;---------------------------------------------------------------------
START:
red: ;
call draw_window ;
;---------------------------------------------------------------------
;--- ----------------------------------------
;---------------------------------------------------------------------
still:
mcall 10 ; 10 -
cmp eax,1 ; ?
je red ; - red
cmp eax,2 ; ?
je key ; - key
cmp eax,3 ; ?
je button ; - button
jmp still ; -
;---------------------------------------------------------------------
key: ;
mcall 2 ; 2 - ( ah)
mov [Music+1], ah ;
; 55-55: ("PlayNote")
; esi -
; mov eax,55
; mov ebx,eax
; mov esi,Music
; int 0x40
; :
mcall 55, eax, , , Music
jmp still ;
;---------------------------------------------------------------------
button:
mcall 17 ; 17 -
cmp ah, 1 ; 1,
jne still ;
.exit:
mcall -1 ;
;---------------------------------------------------------------------
;--- ----------------------------------
;---------------------------------------------------------------------
draw_window:
mcall 12, 1 ; 12:
mcall 48, 3, sc,sizeof.system_colors
; : ()
;
; mov eax,0 ; 0:
; mov ebx,200*65536+300 ; [x ] *65536 + [x ]
; mov ecx,200*65536+150 ; [y ] *65536 + [y ]
; mov edx, [sc.work] ;
; or edx, 0x33000000 ; 3
; mov edi,header ;
; int 0x40
mov edx, [sc.work] ;
or edx, 0x33000000 ; 3
mcall 0, <200,300>, <200,150>, , ,title
;
mov ecx, [sc.work_text] ;
or ecx, 0x90000000 ;
mcall 4, <10, 20>, 0x90000000, message
mcall 12, 2 ; 12.2,
ret ;
;---------------------------------------------------------------------
;--- ----------------------------------------------
;---------------------------------------------------------------------
; "".
;
Music:
db 0x90, 0x30, 0
sc system_colors
message db ' ...',0
title db ' ',0
;---------------------------------------------------------------------
I_END: ;
Examples for Assembler use box_lib.
SVN: /programs/develop/libraries/box_lib/asm/trunk/ctrldemo.asm and
editbox_ex.asmExample for C--. SVN: /programs/cmm/examples/window.c #define MEMSIZE 4096*10 #include "../lib/io.h" #include "../lib/gui.h" void main() { word id; dword file; io.dir.load(0,DIR_ONLYREAL); loop() switch(WaitEvent()) { case evButton: id=GetButtonID(); if (id==1) ExitProcess(); break; case evKey: GetKeys(); if (key_scancode == SCAN_CODE_ESC ) ExitProcess(); break; case evReDraw: draw_window(); break; } } void draw_window() { proc_info Form; int i; DefineAndDrawWindow(215,100,350,300,0x34,0xFFFFFF,"Window header"); GetProcessInfo(#Form, SelfInfo); for (i=0; i<io.dir.count; i++) { WriteText(5,i*8+3,0x80,0xFF00FF,io.dir.position(i)); } DrawCaptButton(100, 10, 100, 22, 22, 0xCCCccc, 0x000000, "Button"); WriteText(100,50,0x80,0,"Textline small"); WriteText(100,70,0x90,0,"Textline big"); DrawBar(100, 110, 100, 100, 0x66AF86); }
Examples for gcc / tcc:
»
Svn: / programs / develop / libraries / newlib_example /»
Svn: / programs / develop / ktcc / trunk / samples /»Examples of using box_lib from C:
SVN: / contrib / C_Layer / EXAMPLE /Compiling as indicated above, for GCC you need to link the application with the
--subsystem windows
(or
--subsystem native
) key, if you do not use the console window.
The list of libraries can be viewed on the Wiki. This and work with images, and with fonts, OpenGL implementation, system-wide libraries.