make kappl app1

This commit is contained in:
2026-03-01 15:45:48 +01:00
parent 704fdb301a
commit 92ceb1f5e2
4 changed files with 0 additions and 0 deletions

View File

@@ -1,145 +0,0 @@
#include "../libsys/stub.h"
#include "../libsys/string.h"
char sbuf[8194], rbuf[8194]; // (2 * 4KiB) + 2
void main() {
fork();
fork();
int ppid = sys_getpid();
int other = fork();
//write(1, "app", 3, 0, ppid);
if (ppid == other) { // child
sbuf[0] = 3;
sbuf[8192] = sys_getpid();
sbuf[8193] = 1;
send(other, sbuf, 8193, rbuf, 8193);
char msg[] = "REPLY: AA\n";
msg[7] += rbuf[0] + sbuf[8193];
msg[8] += 4 + ppid;
write(0, msg, 10);
} else { // parent
// int X = recv(rbuf, 8193);
receive(rbuf, 8193);
rbuf[0] = rbuf[0] + rbuf[8192];
rbuf[8193] = 7;
// reply(X,rbuf, 8193);
reply(rbuf,8193);
}
sys_exit();
}
//// vim: set noet ts=4 sw=4:
//
//#include "../libsys/stub.h"
//#include "../libsys/string.h"
//
//char* itoh(unsigned int value, char* buffer) {
// char* ptr = &buffer[11];
// *ptr = '\0'; // Nullterminator am Ende setzen
//
// if (value == 0) {
// *--ptr = '0';
// return ptr;
// }
//
// do {
// ptr--;
// *ptr = '0' + (value % 16);
// if(*ptr >= 0x3A)
// *ptr+=7;
// value /= 16;
// } while (value != 0);
//
// return ptr;
//}
//char* itoa(unsigned int value, char* buffer) {
// char* ptr = &buffer[11];
// *ptr = '\0'; // Nullterminator am Ende setzen
//
// if (value == 0) {
// *--ptr = '0';
// return ptr;
// }
//
// do {
// ptr--;
// *ptr = '0' + (value % 10);
// value /= 10;
// } while (value != 0);
//
// return ptr;
//}
//
//extern "C" void main() {
// // Thread 1 may be an auxiliary thread
//
// //sys_test(1,2,3,4,5);
//
// uint8_t ret = fork();
// ret = fork();
//
// unsigned id = sys_getpid();
//
// char text[] = "appX";
// text[3] = 0x30+id;
// write(1, text, strlen(text), 0, (int)id);
//
// char msg[] = "forked pid: ";
// msg[12] = 0x30+ret;
// write(1, msg, strlen(msg), 6, (int)id);
//
// uint8_t cnt = 0;
//
// while(1){
// cnt = (cnt+1)%100;
// char msg[12];
// char* num = itoa(cnt, msg);
// write(1, num, strlen(num), 25, (int)id);
// sleep(100);
// }
//
//
// for (uint8_t i = 1;; ++i) {
// //counter to see app running
// cnt=(cnt+1)%100;
// char buf[32];
// char* msg = itoa(cnt,buf);
// write(1, msg, strlen(msg), 6, (int)id);
//
// //test ipc
// if((i+50)%100 == 0){
// if(id == 2){
// char txt[] = "toastbrot ";
// itoa(cnt, &txt[1]);
// write(2, "send\n", 5);
// send(4, txt, strlen(txt), txt, 15);
// write(1, txt, strlen(txt), 25, (int)id);
// }
// }
// if(i%100 == 0){
// if(id == 4){
// char blubb[20];
// if(receive(blubb, sizeof(blubb))){
// write(1, blubb, strlen(blubb), 25, (int)id);
// write(2, "reply\n", 6);
// memset(&blubb[10], ' ', 3);
// itoa(cnt, &blubb[1]);
// reply(blubb, sizeof(blubb));
// }
// }
// }
//
// // test map/unmap and print ptr
// void* ptr= map(4096);
// uint16_t* val = ((uint16_t*)ptr);
// *val = 0x1337;
//
// msg = itoh((uintptr_t)ptr,buf);
// write(1, msg, strlen(msg), 12, (int)id);
// unmap(ptr, 4096);
//
// sleep(100);
// }
//}

View File

@@ -1,32 +0,0 @@
// vim: set noet ts=4 sw=4:
/*! \file
* \brief Enthält die Klasse Application
*/
#pragma once
#include "../libsys/types.h"
#include "../libsys/thread.h"
//! \brief Test application
//!
//! \note Any class derived from Thread defines an application for StuBS.
//!
class Application : public Thread {
// Prevent copies and assignments
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
public:
Application(Application&&) = delete;
/*! \brief Constructor
*
*/
Application() {}
/*! \brief Contains the application code.
*
*/
void action() override;
};

48
user/app1/kappl.cc Normal file
View File

@@ -0,0 +1,48 @@
// vim: set noet ts=4 sw=4:
#include "../libsys/stub.h"
#include "../libsys/string.h"
//#include "../libsys/string.h"
extern "C" void main() {
char cmd_buff[100];
uint8_t bufferpos = 0;
uint8_t id = sys_getpid();
uint8_t x = 0;
char text[] = "kappl";
write(1, text, sizeof(text), 0, (int)id);
while(1){
char msg[11];
int len;
len = read(0, msg, 1);
if(len){
write(0, msg, len, 6+x, id);
memcpy(&cmd_buff[bufferpos], msg, len);
bufferpos+=len;
for(uint8_t i=0; i<len; i++)
if(msg[i] == '\n'){
x=0;
write(0, " ", 52, 6+x, id);
bufferpos = 0;
if(strncmp(cmd_buff, "kill ", 5) == 0){
int pid = cmd_buff[5]-0x30;
char r[] = "killing X\n";
r[8] = pid+0x30;
write(0, r, 9);
sys_kill(pid);
}
if(strncmp(cmd_buff, "killall", 7) == 0){
for(uint8_t i = 0; i<10; i++){
sys_kill(i);
}
}
}
else
x++;
}
}
}

26
user/app1/kappl.h Normal file
View File

@@ -0,0 +1,26 @@
// vim: set noet ts=4 sw=4:
/*! \file
* \brief Enthält die Klasse KeyboardApplication
*/
#pragma once
#include "../../thread/thread.h"
#include "../../types.h"
/*! \brief Keyboard Application
*
*/
class KeyboardApplication : public Thread {
// Prevent copies and assignments
KeyboardApplication(const KeyboardApplication&) = delete;
KeyboardApplication& operator=(const KeyboardApplication&) = delete;
public:
KeyboardApplication() {}
/*! \brief Contains the application code.
*
*/
void action() override;
};