Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard circular buffer #26

Merged
merged 12 commits into from
May 8, 2024
Merged

Keyboard circular buffer #26

merged 12 commits into from
May 8, 2024

Conversation

karlek
Copy link
Owner

@karlek karlek commented May 8, 2024

No description provided.

karlek added 6 commits May 5, 2024 14:21
Things to consider going forward:
- naming conventions between userland and kernel syscall functions.
- type-safety problems with the syscall array; this might bite us down
  the road if registers gets unknowingly trashed.
- random userland registers leak into syscall implementations since they
  aren't nulled out. (See the linux link)
- this skeleton is probably terribly slow
// The way linux does it is to use `struct pt_regs`.
// https://lwn.net/Articles/750536/
//
// NOTE: arbitrary func ptr for minimum type safety.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

killer feature : )

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

literally. there is probably some nifty way to do this, but my C-type-signature-fu is lacking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

har alla syscalls samma function signature? annars är det (void *) som gäller

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, de har olika. så (void *) it is

void debug_interrupt() {
// NOTE: This will actually throw a general protection fault, since it's a
// privileged instruction. So we just hook this empty void stub instead and
// pretend that it works!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta save those 0xcc bytes.

Vad händer om compiler:n inline'ar den här tomma funktionen och vi break'ar på den? 😊

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bra fråga. Min gissning är att symbolen läggs där funktionen inline:as, men är inte säker!

Säkraste är säkert att slänga på en __attribute__ ((noinline)). Jobbigt btw att det är compilerspecifika syntaxer för olika attributes T.T Hade ju varit soft om det bara var noinline void debug_interrupt typ

Copy link
Collaborator

@mewmew mewmew May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bra fråga. Min gissning är att symbolen läggs där funktionen inline:as, men är inte säker!

Vad händer om den inline'as på mer än ett ställe? :P

Säkraste är säkert att slänga på en attribute ((noinline)). Jobbigt btw att det är compilerspecifika syntaxer för olika attributes T.T Hade ju varit soft om det bara var noinline void debug_interrupt typ

Håller med! Låt oss fixa en ny standard som unifyar usage, ... , 17 competing standards xD

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vad händer om den inline'as på mer än ett ställe? :P

Symboler är unika (tror jag?) så den kan nog inte vara på flera ställen. Så undefined behavior antagligen :D

Håller med! Låt oss fixa en ny standard som unifyar usage, ... , 17 competing standards xD

Det är ju tempting! IBM jobbar på det: https://www.ibm.com/docs/en/i/7.5?topic=attributes-noinline-function-attribute

/* asm volatile("int3"); */
}

#define EVER \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAHAHA! den fick leva kvar. for EVER

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format verkar gilla göra den utdragen också :p


void strip(uint8_t* s) {
bool stop = true;
uint32_t i = strlen(s) - 1;
Copy link
Collaborator

@mewmew mewmew May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

om s = "" så får vi en integer underflow. men då i är unsigned så får vi UINT32_MAX. således är i större än 0 i loopen och random stuff happens.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riktig sunkkod 😂

bool stop = true;
uint32_t i = strlen(s) - 1;
for (; i > 0; i--) {
if (i == ' ') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-if (i == ' ')
+if (s[i] == ' ')

och likaledes för de andra if-blocken

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godnatt yxskaft på den här 🙃

}

void memset(uint8_t* p, uint8_t c, uint32_t len) {
for (uint32_t i = 0; i < len; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invoke med memset(p, c, UINT32_MAX) kommer ge en inf_loop.

generellt sätt är det rekommenderat att inte använda unsigned för loop index, då wrap-around buggar annars inte träffas.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Den fotpistolen gick jag på 🦶

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotta love C

for (EVER) {
uint8_t printl[128];
uint8_t readl[128];
memset(printl, 0, sizeof printl);
Copy link
Collaborator

@mewmew mewmew May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-sizeof printl
+sizeof(printl)

mer portable C, och känns snyggare, som ett funktions-anrop snarare än något magiskt i språket

strip(readl);

if (strcmp(readl, "pwd")) {
sprintf(&printl[0], "> %s\n", "/");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always root dir : )

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exakt, det är ju oftast inte fel iaf ^^
Snart får vi slänga på ett VFS lager

@karlek
Copy link
Owner Author

karlek commented May 8, 2024

I'll merge since the review hopefully identified most of the improvement points.

@karlek karlek merged commit 9071aef into main May 8, 2024
1 check passed
@karlek karlek deleted the keyboard-circular-buffer branch May 8, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants