{"action":"created","issue":{"url":"https://api.github.com/repos/shkolnick-kun/bugurtos/issues/13","repository_url":"https://api.github.com/repos/shkolnick-kun/bugurtos","labels_url":"https://api.github.com/repos/shkolnick-kun/bugurtos/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/shkolnick-kun/bugurtos/issues/13/comments","events_url":"https://api.github.com/repos/shkolnick-kun/bugurtos/issues/13/events","html_url":"https://github.com/shkolnick-kun/bugurtos/issues/13","id":123951941,"number":13,"title":"SDCC STM8 port","user":{"login":"spth","id":10352947,"avatar_url":"https://avatars.githubusercontent.com/u/10352947?v=3","gravatar_id":"","url":"https://api.github.com/users/spth","html_url":"https://github.com/spth","followers_url":"https://api.github.com/users/spth/followers","following_url":"https://api.github.com/users/spth/following{/other_user}","gists_url":"https://api.github.com/users/spth/gists{/gist_id}","starred_url":"https://api.github.com/users/spth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spth/subscriptions","organizations_url":"https://api.github.com/users/spth/orgs","repos_url":"https://api.github.com/users/spth/repos","events_url":"https://api.github.com/users/spth/events{/privacy}","received_events_url":"https://api.github.com/users/spth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":18,"created_at":"2015-12-26T22:36:49Z","updated_at":"2016-08-02T08:14:16Z","closed_at":null,"body":"It seems, currently the STM8 is supported via the non-free IAR and Raisonance compilers only.\r\nThe free C compiler SDCC supports STM8 since the 3.4.0 release in 2014.\r\n\r\nPhilipp\r\n"},"comment":{"url":"https://api.github.com/repos/shkolnick-kun/bugurtos/issues/comments/236834963","html_url":"https://github.com/shkolnick-kun/bugurtos/issues/13#issuecomment-236834963","issue_url":"https://api.github.com/repos/shkolnick-kun/bugurtos/issues/13","id":236834963,"user":{"login":"shkolnick-kun","id":12095582,"avatar_url":"https://avatars.githubusercontent.com/u/12095582?v=3","gravatar_id":"","url":"https://api.github.com/users/shkolnick-kun","html_url":"https://github.com/shkolnick-kun","followers_url":"https://api.github.com/users/shkolnick-kun/followers","following_url":"https://api.github.com/users/shkolnick-kun/following{/other_user}","gists_url":"https://api.github.com/users/shkolnick-kun/gists{/gist_id}","starred_url":"https://api.github.com/users/shkolnick-kun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shkolnick-kun/subscriptions","organizations_url":"https://api.github.com/users/shkolnick-kun/orgs","repos_url":"https://api.github.com/users/shkolnick-kun/repos","events_url":"https://api.github.com/users/shkolnick-kun/events{/privacy}","received_events_url":"https://api.github.com/users/shkolnick-kun/received_events","type":"User","site_admin":false},"created_at":"2016-08-02T08:14:16Z","updated_at":"2016-08-02T08:14:16Z","body":"OK, I've got a working prototype:\r\n```C\r\n/**************************************************************************\r\n    BuguRTOS-2.0.x (Bugurt real time operating system)\r\n    Copyright (C) 2016 anonimous\r\n\r\n    This program is free software: you can redistribute it and/or modify\r\n    it under the terms of the GNU General Public License as published by\r\n    the Free Software Foundation, either version 3 of the License, or\r\n    (at your option) any later version.\r\n\r\n    This program is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n    GNU General Public License for more details.\r\n\r\n    You should have received a copy of the GNU General Public License\r\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r\n\r\n    Please contact with me by E-mail: shkolnick.kun@gmail.com\r\n\r\n    A special exception to the GPL can be applied should you wish to distribute\r\n    a combined work that includes BuguRTOS, without being obliged to provide\r\n    the source code for any proprietary components. See the file exception.txt\r\n    for full details of how and when the exception can be applied.\r\n**************************************************************************/\r\n\r\n/*****************************************************************************************\r\n```````````````````````````````..:+oyhdmNNMMMMMMNmmdhyo+:..```````````````````````````````\r\n``````````````````````````.:oydNMMMMMMMMMNNNNNNNNMMMMMMMMMNdy+:.``````````````````````````\r\n```````````````````````:sdNMMMMMNdys+/::----------::/osydNMMMMMNds:```````````````````````\r\n```````````````````.+hNMMMMmho/-..........................-/shmMMMMNh/.```````````````````\r\n````````````````./hNMMMNho:...................................-:ohNMMMNh/`````````````````\r\n``````````````.smMMMNy/-.......:////ss++/+-.......................-+yNMMMmo.``````````````\r\n````````````-sNMMMd+-.....:////:-...-/s::..............+o/-..........-odMMMNs.````````````\r\n``````````.sNMMNh/....................................-o:--............./hMMMNo.``````````\r\n`````````+mMMMh:-........................................-...............-/dMMMm/`````````\r\n```````.yMMMm/...................-::--..................:-........--........+mMMMy.```````\r\n``````:mMMMy-.......................-::-...............-:.........-::........-yMMMd:``````\r\n`````/NMMN+-..................::-.....-:-............../--.........-:/-.......-+NMMN:`````\r\n````+NMMm::o/-..--/+o+o+++++o+osys+//::-::.............:/....-:-::-..-++-.......:NMMN/````\r\n```/NMMm:.-++-+yhs/-``       `dMMMMMmho+:-..............:-/+yho/:/+oyo//o-......./mMMN:```\r\n``-NMMm/....-/--::/o+o+oo+oo++oosyss+smyo/.............:yyho-`     smMMddh-......./NMMN.``\r\n`.hMMM/......-++:-.-:oooooooooosyyhhys/...............-+osyyyyysssssooo+ohhs-......+MMMh.`\r\n`+MMMy.......-::/++:-.....-:/++++o+o/--................--/oooo+o++o+++////-y/.......hMMM/`\r\n.mMMN:.........--:---...-::/+//::--.......................--//+//-...-.....+/......./NMMd`\r\n/MMMy............-::----------....----/+-.....................-++/:---....-o-........hMMN:\r\nyMMM/.............--:://///oo+++/+++oo+-.......................-://+/:--::::.........+MMMs\r\nmMMN:................----:/h:::/:/::---.........................--/osss+++:..........:NMMd\r\nMMMd-....................:mNs:-....................................--:odo:-..........:mMMN\r\nMMMd-....................yoshyoso:--................................../mm/...........:mMMM\r\nMMMm:..................../-o/h.y-:+dooo+/:--....................-/osydddmh...........:mMMN\r\nmMMN:........................+mNs `h.  -d/:/+h++ooooy+++s++y+++mo+y` yh.do...........:NMMh\r\nsMMM+........................-hmMo/ds  oMo`.-o     :h   s:`h` `Nysd.-Ny-h:...........+MMMo\r\n/MMMh........................./smMMMMd+NMMNNMh`    sN: .mNNMddNMMMMNmN+..............hMMN:\r\n.dMMN/........................./+hMMMMMMMMMMMMmhyyyNMNNMMMMMMMMMMMNsoo-............./NMMd`\r\n`+MMMh.........................-/+omMMMMMMMMMMMMMMMMMMMMMMMMMMMMms-/+...............hMMM/`\r\n`.hMMM+..........................:/-omMMMMMMMMMMMMMMMdmMdhMMMds/-..-...............oMMMy``\r\n``.NMMN/............................--/hNN/h.`ys:dmsd:-syos+--+.................../NMMN.``\r\n```/NMMm:...........................:+/--:+s++oo+osoo+/:-..-/+::-................/mMMN:```\r\n````/NMMN:............................-/++/:-..........-//+/-..:+.--............/NMMN/````\r\n`````:NMMN+-.............../+-.............-://////////:-.......+s+::.........-oNMMN:`````\r\n``````:mMMMy-..............:/o-.................................:yo//........-hMMMd-``````\r\n```````.yMMMm+.............:o:++-...............................+y+o-......-+mMMMs.```````\r\n`````````/mMMMd/-...........-++:+/-.---........................-ho+/.....-/dMMMm/`````````\r\n``````````.oNMMMh/............-++:++/////:....................-yo:o-...-+hMMMNo.``````````\r\n````````````.sNMMMdo-...........-++::++:-:/+//:..............:o:/o-..-omMMMNo.````````````\r\n``````````````.omMMMNy+-..........-/+-.:/+/:--:+++/++//:/::/+/-+/.-+hMMMMmo```````````````\r\n`````````````````/hNMMMNho:-...............-:/:-....--::::--..-/ohNMMMNy:`````````````````\r\n```````````````````./hNMMMMmhs/-..........................-/shNMMMMNy/.```````````````````\r\n```````````````````````:sdNMMMMMNdhso+/:----------:/+oshdNMMMMMNho:```````````````````````\r\n``````````````````````````.:+ydNMMMMMMMMMMNNNNNNMMMMMMMMMMmds+:```````````````````````````\r\n````````````````````````````````.:/osyhdmNNMMMMNNmdhyso/:.````````````````````````````````\r\n******************************************************************************************\r\n*                                                                                        *\r\n*                   This logo was graciously delivered by 10003-kun ITT:                 *\r\n*                                                                                        *\r\n*                           http://www.0chan.ru/r/res/9996.html                          *\r\n*                                                                                        *\r\n*****************************************************************************************/\r\n#include \"stm8l.h\"\r\n#include <stdint.h>\r\n\r\n#define BGRT_INT_PTR unsigned short\r\ntypedef uint8_t bgrt_stack_t;\r\ntypedef void (*bgrt_code_t)(void*);\r\n\r\nbgrt_stack_t * bgrt_proc_stack_init(\r\n                            bgrt_stack_t * bgrt_stack_top,\r\n                            bgrt_code_t pmain,\r\n                            void * arg,\r\n                            void (*return_address)(void)\r\n                        )\r\n{\r\n    //main arg\r\n    *bgrt_stack_top-- = (bgrt_stack_t)((unsigned short)arg & 0xFF);\r\n    *bgrt_stack_top-- = (bgrt_stack_t)(((unsigned short)arg>>8)& 0xFF);\r\n    // return address (func)\r\n    *bgrt_stack_top-- = (bgrt_stack_t)(((BGRT_INT_PTR)return_address) & 0xFF);\r\n    *bgrt_stack_top-- = (bgrt_stack_t)(((BGRT_INT_PTR)return_address>>8)& 0xFF);\r\n    // process main\r\n    *bgrt_stack_top-- = (bgrt_stack_t)(((BGRT_INT_PTR)pmain) & 0xFF);\r\n    *bgrt_stack_top-- = (bgrt_stack_t)(((BGRT_INT_PTR)pmain>>8)& 0xFF);\r\n    *bgrt_stack_top-- = 0x00;\r\n    // Y\r\n    *bgrt_stack_top-- = 0xAD;\r\n    *bgrt_stack_top-- = 0xDE;\r\n    /** WARNING: LARGE RAM MODEL IS NOT SUPPORTED IN THIS CODE!!! */\r\n    // X - 1st argument is placed in X\r\n    *bgrt_stack_top-- = 0xBE;\r\n    *bgrt_stack_top-- = 0xAF;\r\n    // A\r\n    *bgrt_stack_top-- = 0xAA;\r\n    // CCR\r\n    *bgrt_stack_top-- = 0x20; //Interrupts are enabled\r\n    //Dummy bytes, as after bgrt_isr_epilogue [addw\tsp, #2] is done\r\n    *bgrt_stack_top-- = 0xFF;\r\n    *bgrt_stack_top-- = 0xFF;\r\n    return bgrt_stack_top;\r\n}\r\nstatic bgrt_stack_t * bgrt_isr_prologue(void) __naked\r\n{\r\n    __asm\r\n        ldw X, SP\r\n        ret\r\n    __endasm;\r\n}\r\n\r\nstatic void bgrt_isr_epilogue(bgrt_stack_t * val) __naked\r\n{\r\n    (void)val;\r\n    __asm\r\n        ldw   X, (0x03, SP) /*Get new SP value   */\r\n        popw  Y             /*pop return address */\r\n        ldw   SP, X         /*Set SP             */\r\n        pushw Y             /*push return address*/\r\n        ret                 /*return             */\r\n    __endasm;\r\n}\r\n\r\nstatic bgrt_stack_t * save_sp = (void *)0;\r\n\r\nstatic bgrt_stack_t * main_sp = (void *)0;\r\nstatic bgrt_stack_t * thread_sp = (void *)0;\r\n\r\nstatic bgrt_stack_t ** restore_sp = &main_sp;\r\n\r\nstatic void my_sched(void)\r\n{\r\n    *restore_sp = save_sp;\r\n    if (&main_sp == restore_sp){\r\n        restore_sp = &thread_sp;\r\n    }else{\r\n        restore_sp = &main_sp;\r\n    }\r\n    save_sp = *restore_sp;\r\n}\r\n\r\nstatic void my_trap(void) __trap __naked\r\n{\r\n    save_sp = bgrt_isr_prologue();\r\n    my_sched();\r\n    bgrt_isr_epilogue(save_sp);\r\n    __asm__(\"iret\");\r\n}\r\n\r\nbgrt_stack_t thread_stack[128];\r\n\r\nuint16_t d_thr = 0;\r\n\r\nstatic void thread(void * arg)\r\n{\r\n    d_thr = (int)(arg);\r\n}\r\n\r\nstatic void thread_end(void)\r\n{\r\n    int d;\r\n    while(1)\r\n    {\r\n        PE_ODR &= ~0x80;\r\n        for(d = 0; d < d_thr; d++) { }\r\n        __asm__(\"trap\");\r\n    }\r\n}\r\n\r\nint main() {\r\n\tint d;\r\n\t// Configure pins\r\n\tPE_DDR = 0x80;\r\n\tPE_CR1 = 0x80;\r\n\tPE_ODR &= ~0x80;\r\n\r\n    thread_sp = bgrt_proc_stack_init(&thread_stack[127], thread, (void *)30000, thread_end);\r\n\t// Loop\r\n\tdo {\r\n\t\tPE_ODR |= 0x80;\r\n\t\tfor(d = 0; d < 15000; d++) { }\r\n\t\t__asm__(\"trap\");\r\n\t} while(1);\r\n}\r\n```"}}
{"actor":{"display_login":"shkolnick-kun"}}