Skip to content

Commit 159bcc2

Browse files
authored
Merge branch 'master' into make/clean
2 parents fce6242 + cfe0528 commit 159bcc2

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

loader.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
6969
callbacks_arg = arg;
7070

7171
/* setjmp error anchor */
72-
if (setjmp(jb))
72+
if (setjmp(jb)) {
73+
CALLBACK(exit, errno);
7374
return;
75+
}
7476

7577
if (parse_args(&loader_args))
7678
goto error;

tests/data/multiboot/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CCFLAGS=-m32 -Wall -Wextra -Werror -fno-stack-protector -nostdinc -fno-builtin
22
ASFLAGS=-m32
3+
OUTPUT=COM1
34

45
UNAME_S!=uname -s
56
LIBGCC!=$(CC) ${CCFLAGS} -print-libgcc-file-name
@@ -27,7 +28,7 @@ modules.elf: start.o modules.o libc.o
2728
$(LD) $(LDFLAGS) -o $@ $> $(LIBGCC)
2829

2930
.c.o:
30-
$(CC) $(CCFLAGS) -c -o $@ $<
31+
$(CC) -DOUTPUT=$(OUTPUT) $(CCFLAGS) -c -o $@ $<
3132

3233
.S.o:
3334
$(CC) $(ASFLAGS) -c -o $@ $<

tests/data/multiboot/libc.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "libc.h"
2424

25+
static char serial_set_up = 0;
26+
2527
void* memcpy(void *dest, const void *src, int n)
2628
{
2729
char *d = dest;
@@ -46,7 +48,25 @@ void* memset(void *b, int c, unsigned len)
4648

4749
static void print_char(char c)
4850
{
49-
outb(0xe9, c);
51+
#if (OUTPUT != DEBUGCON)
52+
/* Check if serial is set up */
53+
if (!serial_set_up) {
54+
outb(OUTPUT + 1, 0x00); // Disable all interrupts
55+
outb(OUTPUT + 3, 0x80); // Enable DLAB (set baud rate divisor)
56+
outb(OUTPUT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
57+
outb(OUTPUT + 1, 0x00); // (hi byte)
58+
outb(OUTPUT + 3, 0x03); // 8 bits, no parity, one stop bit
59+
outb(OUTPUT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
60+
outb(OUTPUT + 4, 0x0B); // IRQs enabled, RTS/DSR set
61+
serial_set_up = 1;
62+
}
63+
/* Check if transmit is empty */
64+
while ( (inb(OUTPUT + 5) & 0x20) == 0 );
65+
if ( c == '\n' )
66+
print_char('\r');
67+
#endif
68+
69+
outb(OUTPUT, c);
5070
}
5171

5272
static void print_str(char *s)

tests/data/multiboot/libc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
#ifndef LIBC_H
2424
#define LIBC_H
2525

26+
/* Serial Ports */
27+
#define DEBUGCON 0xe9
28+
#define COM1 0x3f8
29+
#define COM2 0x2F8
30+
#define COM3 0x3E8
31+
#define COM4 0x2E8
32+
33+
#ifndef OUTPUT
34+
#define OUTPUT DEBUGCON
35+
#endif
36+
2637
/* Integer types */
2738

2839
typedef unsigned long long uint64_t;
@@ -53,6 +64,13 @@ static inline void outb(uint16_t port, uint8_t data)
5364
asm volatile ("outb %0, %1" : : "a" (data), "Nd" (port));
5465
}
5566

67+
static inline uint8_t inb(uint16_t port)
68+
{
69+
uint8_t ret;
70+
asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
71+
return ret;
72+
}
73+
5674

5775
/* Misc functions */
5876

0 commit comments

Comments
 (0)